summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--loader/ground-cell.cpp18
-rw-r--r--loader/ground-cell.hpp7
-rw-r--r--loader/ground-traits.cpp15
-rw-r--r--serialize/ground-atlas.cpp32
-rw-r--r--serialize/ground-atlas.hpp9
-rw-r--r--src/ground-atlas.hpp1
6 files changed, 61 insertions, 21 deletions
diff --git a/loader/ground-cell.cpp b/loader/ground-cell.cpp
new file mode 100644
index 00000000..8cc1e31d
--- /dev/null
+++ b/loader/ground-cell.cpp
@@ -0,0 +1,18 @@
+#include "ground-cell.hpp"
+#include "compat/vector-wrapper.hpp"
+#include "loader/loader.hpp"
+#include "serialize/json-helper.hpp"
+//#include "serialize/corrade-string.hpp"
+#include "serialize/ground-atlas.hpp"
+
+namespace floormat {
+
+vector_wrapper<const ground_cell> ground_cell::load_atlases_from_json()
+{
+ char buf[fm_FILENAME_MAX];
+ auto s = loader.make_atlas_path(buf, loader.GROUND_TILESET_PATH, "ground.json"_s);
+ auto cells = json_helper::from_json<std::vector<ground_cell>>(s);
+ return {cells};
+}
+
+} // namespace floormat
diff --git a/loader/ground-cell.hpp b/loader/ground-cell.hpp
index 260301c2..0e1e51be 100644
--- a/loader/ground-cell.hpp
+++ b/loader/ground-cell.hpp
@@ -1,6 +1,9 @@
#pragma once
-#include "src/ground-def.hpp"
+#include "compat/vector-wrapper-fwd.hpp"
+#include "src/pass-mode.hpp"
#include <memory>
+#include <Corrade/Containers/String.h>
+#include <Magnum/Math/Vector2.h>
namespace floormat {
@@ -12,6 +15,8 @@ struct ground_cell
String name;
Vector2ub size;
pass_mode pass = pass_mode::pass;
+
+ static vector_wrapper<const ground_cell> load_atlases_from_json();
};
} // namespace floormat
diff --git a/loader/ground-traits.cpp b/loader/ground-traits.cpp
index e1fd5e70..5cb8d29e 100644
--- a/loader/ground-traits.cpp
+++ b/loader/ground-traits.cpp
@@ -1,16 +1,14 @@
#include "ground-traits.hpp"
#include "compat/assert.hpp"
#include "compat/exception.hpp"
-#include "atlas-loader.hpp"
+#include "compat/vector-wrapper.hpp"
#include "atlas-loader-storage.hpp"
#include "ground-cell.hpp"
#include "loader.hpp"
#include "src/tile-defs.hpp"
-#include "serialize/json-helper.hpp"
-#include "serialize/ground-atlas.hpp"
+#include "src/ground-atlas.hpp"
#include <Corrade/Containers/StringView.h>
#include <Corrade/Containers/Pointer.h>
-#include <Corrade/Utility/Path.h>
#include <Magnum/ImageView.h>
#include <Magnum/Trade/ImageData.h>
@@ -32,14 +30,7 @@ void traits::ensure_atlases_loaded(Storage& st)
fm_assert(st.cell_array.empty());
fm_assert(st.name_map.empty());
- auto defs = json_helper::from_json<std::vector<ground_def>>(Path::join(loader_::GROUND_TILESET_PATH, "ground.json"_s));
- std::vector<ground_cell> infos;
- infos.reserve(defs.size());
-
- for (auto& x : defs)
- infos.push_back(ground_cell{{}, std::move(x.name), x.size, x.pass});
-
- st.cell_array = Utility::move(infos);
+ st.cell_array = ground_cell::load_atlases_from_json().vec;
fm_assert(!st.cell_array.empty());
fm_assert(st.name_map.empty());
diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp
index d5c04332..11ef40ef 100644
--- a/serialize/ground-atlas.cpp
+++ b/serialize/ground-atlas.cpp
@@ -1,21 +1,22 @@
#include "ground-atlas.hpp"
+#include "compat/exception.hpp"
+#include "src/ground-atlas.hpp"
+#include "src/ground-def.hpp"
+#include "loader/loader.hpp"
+#include "loader/ground-cell.hpp"
#include "serialize/corrade-string.hpp"
#include "serialize/magnum-vector.hpp"
#include "serialize/pass-mode.hpp"
-#include "loader/loader.hpp"
+#include <tuple>
+#include <Corrade/Utility/Move.h>
#include <Magnum/Trade/ImageData.h>
#include <Magnum/ImageView.h>
-#include <tuple>
#include <nlohmann/json.hpp>
-namespace floormat {
-
-} // namespace floormat
+namespace nlohmann {
using namespace floormat;
-namespace nlohmann {
-
void adl_serializer<ground_def>::to_json(json& j, const ground_def& x)
{
using nlohmann::to_json;
@@ -31,6 +32,23 @@ void adl_serializer<ground_def>::from_json(const json& j, ground_def& val)
val.pass = j["pass-mode"];
}
+void adl_serializer<ground_cell>::to_json(json& j, const ground_cell& x)
+{
+ j = std::tuple<StringView, Vector2ub, pass_mode>{x.name, x.size, x.pass};
+}
+
+void adl_serializer<ground_cell>::from_json(const json& j, ground_cell& val)
+{
+ using nlohmann::from_json;
+ val = {};
+ val.name = j["name"];
+ fm_soft_assert(loader.check_atlas_name(val.name));
+ val.size = j["size"];
+ if (j.contains("pass-mode"))
+ val.pass = j["pass-mode"];
+}
+
+
void adl_serializer<std::shared_ptr<ground_atlas>>::to_json(json& j, const std::shared_ptr<const ground_atlas>& x)
{
j = std::tuple<StringView, Vector2ub, pass_mode>{x->name(), x->num_tiles2(), x->pass_mode()};
diff --git a/serialize/ground-atlas.hpp b/serialize/ground-atlas.hpp
index a423ebbe..20b50537 100644
--- a/serialize/ground-atlas.hpp
+++ b/serialize/ground-atlas.hpp
@@ -1,10 +1,11 @@
#pragma once
-#include "src/ground-atlas.hpp"
#include <nlohmann/json_fwd.hpp>
namespace floormat {
+struct ground_def;
struct ground_cell;
+class ground_atlas;
} // namespace floormat
@@ -22,4 +23,10 @@ struct adl_serializer<std::shared_ptr<floormat::ground_atlas>> final {
static void from_json(const json& j, std::shared_ptr<floormat::ground_atlas>& x);
};
+template<>
+struct adl_serializer<floormat::ground_cell> final {
+ static void to_json(json& j, const floormat::ground_cell& x);
+ static void from_json(const json& j, floormat::ground_cell& x);
+};
+
} // namespace nlohmann
diff --git a/src/ground-atlas.hpp b/src/ground-atlas.hpp
index e13c0012..3fc3a177 100644
--- a/src/ground-atlas.hpp
+++ b/src/ground-atlas.hpp
@@ -1,6 +1,7 @@
#pragma once
#include "src/pass-mode.hpp"
#include "src/quads.hpp"
+#include "src/ground-def.hpp"
#include "loader/ground-cell.hpp"
#include <array>
#include <memory>