diff options
Diffstat (limited to 'serialize/world.cpp')
-rw-r--r-- | serialize/world.cpp | 46 |
1 files changed, 2 insertions, 44 deletions
diff --git a/serialize/world.cpp b/serialize/world.cpp index 7bdf8ba6..cd6ebd6b 100644 --- a/serialize/world.cpp +++ b/serialize/world.cpp @@ -1,10 +1,6 @@ #include "world.hpp" -#include "serialize/tile.hpp" -#include "serialize/tile-atlas.hpp" #include "src/global-coords.hpp" -#include "src/chunk.hpp" -#include "src/world.hpp" -#include <memory> +#include "serialize/tile.hpp" #include <nlohmann/json.hpp> #if defined _MSC_VER @@ -30,49 +26,11 @@ namespace nlohmann { using namespace floormat; -template<> -struct adl_serializer<std::shared_ptr<chunk>> final { - static void to_json(json& j, const std::shared_ptr<const chunk>& x); - static void from_json(const json& j, std::shared_ptr<chunk>& x); -}; - -void adl_serializer<std::shared_ptr<chunk>>::to_json(json& j, const std::shared_ptr<const chunk>& val) -{ - using nlohmann::to_json; - if (!val) - j = nullptr; - else - j = *val; -} - -void adl_serializer<std::shared_ptr<chunk>>::from_json(const json& j, std::shared_ptr<chunk>& val) -{ - using nlohmann::from_json; - if (j.is_null()) - val = nullptr; - else - *(val = std::make_shared<chunk>()) = j; -} - 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<world>::to_json(json& j, const world& val) -{ - using nlohmann::to_json; - to_json(j, val.chunks()); -} - -void adl_serializer<world>::from_json(const json& j, world& val) -{ - using T = std::remove_cvref_t<decltype(val.chunks())>; - T x{}; - using nlohmann::from_json; - from_json(j, x); - val = world{std::move(x)}; -} - } // namespace nlohmann + |