diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-06 07:11:48 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-06 07:11:48 +0200 |
commit | 66ee29df9c19e35b4c126e12e48bc144fe72eb22 (patch) | |
tree | c5d8a80cb917a1e33d8efdf6ffc653694e67c759 /serialize/tile-atlas.cpp | |
parent | 9b2b5c5fd5880f35e2e952bb89fc709f4b814364 (diff) |
a
Diffstat (limited to 'serialize/tile-atlas.cpp')
-rw-r--r-- | serialize/tile-atlas.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
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 <nlohmann/json.hpp> + +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<Magnum::Examples::tile_atlas>; + +void adl_serializer<shared_atlas>::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<shared_atlas>::from_json(const json& j, shared_atlas& x) +{ + proxy_atlas proxy = j; + x = loader.tile_atlas(proxy.name, proxy.size); +} + +} // namespace nlohmann |