diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 18:15:00 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 18:15:00 +0100 |
commit | c93b3616adbf26673fc928fdfbbec814fec41c75 (patch) | |
tree | 517ee19f32a2ae7d098141335b04e92bffcdc564 /serialize | |
parent | 98416d95331c63affabf331afba0e1dcb307c430 (diff) |
w
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/ground-atlas.cpp | 21 | ||||
-rw-r--r-- | serialize/ground-atlas.hpp | 14 |
2 files changed, 26 insertions, 9 deletions
diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp index 3522e85c..517b8186 100644 --- a/serialize/ground-atlas.cpp +++ b/serialize/ground-atlas.cpp @@ -2,7 +2,7 @@ #include "serialize/corrade-string.hpp" #include "serialize/magnum-vector.hpp" #include "serialize/pass-mode.hpp" -#include "loader/ground-info.hpp" +#include "loader/loader.hpp" #include <tuple> #include <nlohmann/json.hpp> @@ -14,15 +14,13 @@ using namespace floormat; namespace nlohmann { -#if 0 -void adl_serializer<ground_info>::to_json(json& j, const ground_info& x) +void adl_serializer<ground_def>::to_json(json& j, const ground_def& x) { using nlohmann::to_json; j = std::tuple<StringView, Vector2ub, pass_mode>{x.name, x.size, x.pass}; } -#endif -void adl_serializer<ground_info>::from_json(const json& j, ground_info& val) +void adl_serializer<ground_def>::from_json(const json& j, ground_def& val) { using nlohmann::from_json; val.name = j["name"]; @@ -31,4 +29,17 @@ void adl_serializer<ground_info>::from_json(const json& j, ground_info& val) val.pass = j["pass-mode"]; } +void adl_serializer<std::shared_ptr<ground_atlas>>::to_json(json& j, const std::shared_ptr<const ground_atlas>& x) +{ + j = std::tuple<StringView, Vector2ub, pass_mode>{x->name(), x->num_tiles2(), x->pass_mode()}; +} + +void adl_serializer<std::shared_ptr<ground_atlas>>::from_json(const json& j, std::shared_ptr<ground_atlas>& val) +{ + char buf[FILENAME_MAX]; + ground_def info = j; + auto path = loader.make_atlas_path(buf, loader.GROUND_TILESET_PATH, info.name); + val = std::make_shared<ground_atlas>(std::move(info), path, loader.texture(""_s, path)); +} + } // namespace nlohmann diff --git a/serialize/ground-atlas.hpp b/serialize/ground-atlas.hpp index 7ca57ede..fc8acec5 100644 --- a/serialize/ground-atlas.hpp +++ b/serialize/ground-atlas.hpp @@ -1,5 +1,5 @@ #pragma once -#include "loader/ground-info.hpp" +#include "src/ground-atlas.hpp" #include <nlohmann/json_fwd.hpp> namespace floormat { @@ -11,9 +11,15 @@ struct ground_info; namespace nlohmann { template<> -struct adl_serializer<floormat::ground_info> final { - static void to_json(json& j, const floormat::ground_info& x) = delete; - static void from_json(const json& j, floormat::ground_info& x); +struct adl_serializer<floormat::ground_def> final { + static void to_json(json& j, const floormat::ground_def& x); + static void from_json(const json& j, floormat::ground_def& x); +}; + +template<> +struct adl_serializer<std::shared_ptr<floormat::ground_atlas>> final { + static void to_json(json& j, const std::shared_ptr<const floormat::ground_atlas>& x); + static void from_json(const json& j, std::shared_ptr<floormat::ground_atlas>& x); }; } // namespace nlohmann |