summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-21 21:42:38 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-21 21:43:21 +0200
commit087f5021200e6c80bfdc1f039a47a1d6240d0a87 (patch)
treefa3cb5961e2e2e303e929f1213f76a9c3ffebb06 /serialize
parent0f6de650e81d196d32c143c05e33cf538673b401 (diff)
serialize world
Diffstat (limited to 'serialize')
-rw-r--r--serialize/tile.cpp15
-rw-r--r--serialize/tile.hpp2
-rw-r--r--serialize/world.cpp29
-rw-r--r--serialize/world.hpp25
4 files changed, 56 insertions, 15 deletions
diff --git a/serialize/tile.cpp b/serialize/tile.cpp
index 2eb3a81a..2e94bfb8 100644
--- a/serialize/tile.cpp
+++ b/serialize/tile.cpp
@@ -2,7 +2,6 @@
#include "src/chunk.hpp"
#include "serialize/tile.hpp"
#include "serialize/tile-atlas.hpp"
-#include "global-coords.hpp"
#include <nlohmann/json.hpp>
namespace floormat {
@@ -10,14 +9,6 @@ namespace floormat {
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(tile_image, atlas, variant)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(tile, ground_image, wall_north, wall_west, passability)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords, x, y)
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y)
-
-struct global_coords_ final {
- chunk_coords chunk;
- local_coords local;
-};
-
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(global_coords_, chunk, local)
} // namespace floormat
@@ -37,10 +28,4 @@ void adl_serializer<chunk>::from_json(const json& j, chunk& val) { using nlohman
void adl_serializer<local_coords>::to_json(json& j, const local_coords& val) { using nlohmann::to_json; to_json(j, val); }
void adl_serializer<local_coords>::from_json(const json& j, local_coords& val) { using nlohmann::from_json; from_json(j, val); }
-void adl_serializer<chunk_coords>::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); }
-void adl_serializer<chunk_coords>::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); }
-
-void adl_serializer<global_coords>::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); }
-void adl_serializer<global_coords>::from_json(const json& j, global_coords& val) { using nlohmann::from_json; global_coords_ x; from_json(j, x); val = {x.chunk, x.local}; }
-
} // namespace nlohmann
diff --git a/serialize/tile.hpp b/serialize/tile.hpp
index 318c86bb..09c23f9a 100644
--- a/serialize/tile.hpp
+++ b/serialize/tile.hpp
@@ -2,10 +2,12 @@
#include <nlohmann/json_fwd.hpp>
namespace floormat {
+
struct tile_image;
struct tile;
struct chunk;
struct local_coords;
+
} // namespace floormat
namespace nlohmann {
diff --git a/serialize/world.cpp b/serialize/world.cpp
new file mode 100644
index 00000000..b52fe3b9
--- /dev/null
+++ b/serialize/world.cpp
@@ -0,0 +1,29 @@
+#include "world.hpp"
+#include "tile.hpp"
+#include "global-coords.hpp"
+#include <nlohmann/json.hpp>
+
+namespace floormat {
+
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y)
+
+struct global_coords_ final {
+ chunk_coords chunk;
+ local_coords local;
+};
+
+NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(global_coords_, chunk, local)
+
+} // namespace floormat
+
+namespace nlohmann {
+
+using namespace floormat;
+
+void adl_serializer<chunk_coords>::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); }
+void adl_serializer<chunk_coords>::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); }
+
+void adl_serializer<global_coords>::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); }
+void adl_serializer<global_coords>::from_json(const json& j, global_coords& val) { using nlohmann::from_json; global_coords_ x; from_json(j, x); val = {x.chunk, x.local}; }
+
+} // namespace nlohmann
diff --git a/serialize/world.hpp b/serialize/world.hpp
new file mode 100644
index 00000000..05c88b40
--- /dev/null
+++ b/serialize/world.hpp
@@ -0,0 +1,25 @@
+#pragma once
+#include <nlohmann/json_fwd.hpp>
+
+namespace floormat {
+
+struct chunk_coords;
+struct global_coords;
+
+} // namespace floormat
+
+namespace nlohmann {
+
+template<>
+struct adl_serializer<floormat::chunk_coords> {
+ static void to_json(json& j, const floormat::chunk_coords& val);
+ static void from_json(const json& j, floormat::chunk_coords& val);
+};
+
+template<>
+struct adl_serializer<floormat::global_coords> {
+ static void to_json(json& j, const floormat::global_coords& val);
+ static void from_json(const json& j, floormat::global_coords& val);
+};
+
+} // namespace nlohmann