From 087f5021200e6c80bfdc1f039a47a1d6240d0a87 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 21 Oct 2022 21:42:38 +0200 Subject: serialize world --- serialize/world.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 serialize/world.cpp (limited to 'serialize/world.cpp') 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 + +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::to_json(json& j, const chunk_coords& val) { using nlohmann::to_json; to_json(j, val); } +void adl_serializer::from_json(const json& j, chunk_coords& val) { using nlohmann::from_json; from_json(j, val); } + +void adl_serializer::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, global_coords_{val.chunk(), val.local()}); } +void adl_serializer::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 -- cgit v1.2.3