summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-02-08 23:08:42 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-02-08 23:08:42 +0100
commit55a76536bbcc0ab662c3b56e4af7370d5932f063 (patch)
tree112a3641dee78e660b11d1190ed448dee8107efb /serialize
parentaceb0a84b4abaa4e631d317c6cd0d02b0aa0bdbd (diff)
loader: more refactoring
Diffstat (limited to 'serialize')
-rw-r--r--serialize/ground-atlas.cpp32
-rw-r--r--serialize/ground-atlas.hpp9
2 files changed, 33 insertions, 8 deletions
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