diff options
Diffstat (limited to 'serialize/tile.cpp')
| -rw-r--r-- | serialize/tile.cpp | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/serialize/tile.cpp b/serialize/tile.cpp index 61431e61..783a9853 100644 --- a/serialize/tile.cpp +++ b/serialize/tile.cpp @@ -2,6 +2,7 @@ #include "src/tile.hpp" #include "src/global-coords.hpp" #include "serialize/tile-atlas.hpp" +#include <tuple> #include <nlohmann/json.hpp> namespace floormat { @@ -19,12 +20,8 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(local_coords_, x, y) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords, x, y) NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(chunk_coords_, x, y, z) -struct global_coords_ final { - chunk_coords chunk; - local_coords local; -}; - -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(global_coords_, chunk, local) +inline void to_json(nlohmann::json& j, global_coords coord) { j = std::tuple<chunk_coords, local_coords, int8_t>{ coord.chunk(), coord.local(), coord.z() }; } +inline void from_json(const nlohmann::json& j, global_coords& coord) { std::tuple<chunk_coords, local_coords, int8_t> t = j; auto [ch, pos, z] = t; coord = { ch, pos, z }; } } // namespace floormat @@ -44,8 +41,8 @@ void adl_serializer<chunk_coords>::from_json(const json& j, chunk_coords& 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}; } +void adl_serializer<global_coords>::to_json(json& j, const global_coords& val) { using nlohmann::to_json; to_json(j, val); } +void adl_serializer<global_coords>::from_json(const json& j, global_coords& val) { using nlohmann::from_json; from_json(j, val); } } // namespace nlohmann |
