From 66ee29df9c19e35b4c126e12e48bc144fe72eb22 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 6 Oct 2022 07:11:48 +0200 Subject: a --- serialize/CMakeLists.txt | 5 ----- serialize/tile-atlas.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ serialize/tile-atlas.hpp | 27 ++++++++------------------- 3 files changed, 50 insertions(+), 24 deletions(-) delete mode 100644 serialize/CMakeLists.txt create mode 100644 serialize/tile-atlas.cpp (limited to 'serialize') diff --git a/serialize/CMakeLists.txt b/serialize/CMakeLists.txt deleted file mode 100644 index e695aff2..00000000 --- a/serialize/CMakeLists.txt +++ /dev/null @@ -1,5 +0,0 @@ -find_package(nlohmann_json QUIET REQUIRED) -set(self "${PROJECT_NAME}-serialize") -link_libraries(Magnum::Magnum nlohmann_json::nlohmann_json) -file(GLOB sources "*.cpp" CONFIGURE_ARGS) -add_library(${self} STATIC ${sources}) diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp new file mode 100644 index 00000000..0f03e6b2 --- /dev/null +++ b/serialize/tile-atlas.cpp @@ -0,0 +1,42 @@ +#include "../tile-atlas.hpp" +#include "serialize/tile-atlas.hpp" +#include "serialize/magnum-vector.hpp" +#include "loader.hpp" + +#include + +namespace Magnum::Examples::Serialize { + +struct proxy_atlas final { + std::string name; + Vector2i size; +}; + +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy_atlas, name, size) + +} // namespace Magnum::Examples::Serialize + +namespace nlohmann { + +using namespace Magnum::Examples; +using namespace Magnum::Examples::Serialize; + +using shared_atlas = std::shared_ptr; + +void adl_serializer::to_json(json& j, const shared_atlas& x) +{ + if (!x) + j = nullptr; + else { + using nlohmann::to_json; + to_json(j, proxy_atlas{x->name(), x->dimensions()}); + } +} + +void adl_serializer::from_json(const json& j, shared_atlas& x) +{ + proxy_atlas proxy = j; + x = loader.tile_atlas(proxy.name, proxy.size); +} + +} // namespace nlohmann diff --git a/serialize/tile-atlas.hpp b/serialize/tile-atlas.hpp index af279251..c49b8a72 100644 --- a/serialize/tile-atlas.hpp +++ b/serialize/tile-atlas.hpp @@ -1,27 +1,16 @@ #pragma once -#include "../tile-atlas.hpp" -#include +#include "loader.hpp" +#include +#include + +namespace Magnum::Examples { struct tile_atlas; } namespace nlohmann { template<> -struct adl_serializer final { - static void to_json(json& j, const Magnum::Examples::tile_atlas& x); - static void from_json(const json& j, Magnum::Examples::tile_atlas& x); +struct adl_serializer> final { + static void to_json(json& j, const std::shared_ptr& x); + static void from_json(const json& j, std::shared_ptr& x); }; -void adl_serializer::to_json(json& j, const Magnum::Examples::tile_atlas& x) -{ -} - -void adl_serializer::from_json(const json& j, Magnum::Examples::tile_atlas& x) -{ -} - } // namespace nlohmann - -namespace Magnum::Examples::Serialize { - - - -} // namespace Magnum::Examples::Serialize -- cgit v1.2.3