#include "tile.hpp" #include "ground-atlas.hpp" #include "compat/borrowed-ptr.inl" #include "src/tile.hpp" #include "src/global-coords.hpp" #include "src/ground-atlas.hpp" #include #include namespace floormat { using nlohmann::json; inline void to_json(json& j, const tile_image_ref& val) { j = tile_image_proto(val); } inline void from_json(const json& j, tile_image_ref& val) { val = tile_image_proto(j); } struct local_coords_ final { uint8_t x, y; }; 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) inline void to_json(json& j, global_coords coord) { j = std::tuple{ coord.chunk(), coord.local(), coord.z() }; } inline void from_json(const json& j, global_coords& coord) { std::tuple t = j; auto [ch, pos, z] = t; coord = { ch, pos, z }; } } // namespace floormat namespace nlohmann { using namespace floormat; void adl_serializer::to_json(json& j, const tile_image_ref& val) { using nlohmann::to_json; if (val.atlas) to_json(j, val); else j = nullptr; } void adl_serializer::from_json(const json& j, tile_image_ref& val) { using nlohmann::from_json; if (j.is_null()) val = {}; else from_json(j, val); } void adl_serializer::to_json(json& j, const floormat::tile_image_proto& val) { using nlohmann::to_json; j["atlas"] = val.atlas; j["variant"] = val.variant; } void adl_serializer::from_json(const json& j, floormat::tile_image_proto& val) { using nlohmann::from_json; val.atlas = j["atlas"]; val.variant = j["variant"]; } void adl_serializer::to_json(json& j, const local_coords& val) { using nlohmann::to_json; to_json(j, local_coords_{val.x, val.y}); } void adl_serializer::from_json(const json& j, local_coords& val) { using nlohmann::from_json; local_coords_ proxy{}; from_json(j, proxy); val = {proxy.x, proxy.y}; } 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 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, val); } void adl_serializer::from_json(const json& j, global_coords& val) { using nlohmann::from_json; from_json(j, val); } } // namespace nlohmann