diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 16:40:29 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-11 16:40:29 +0100 |
commit | ba90ba2ca91c448d80722985811fc6bddc6e9bf2 (patch) | |
tree | 2a81ee054bad7f76457be6e91359039fcc9a8780 /serialize | |
parent | d74df1b763979d281f76f3f30543aee8d8a638b7 (diff) |
w
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/ground-atlas.cpp | 50 | ||||
-rw-r--r-- | serialize/ground-atlas.hpp | 15 | ||||
-rw-r--r-- | serialize/wall-atlas.cpp | 1 |
3 files changed, 25 insertions, 41 deletions
diff --git a/serialize/ground-atlas.cpp b/serialize/ground-atlas.cpp index 76c8686e..8703881d 100644 --- a/serialize/ground-atlas.cpp +++ b/serialize/ground-atlas.cpp @@ -1,58 +1,38 @@ +#include "ground-atlas.hpp" #include "src/ground-atlas.hpp" -#include "serialize/ground-atlas.hpp" #include "serialize/corrade-string.hpp" #include "serialize/magnum-vector.hpp" #include "loader/loader.hpp" #include "serialize/pass-mode.hpp" #include "compat/exception.hpp" +#include <tuple> #include <Corrade/Containers/Optional.h> #include <Corrade/Containers/String.h> #include <nlohmann/json.hpp> -using namespace floormat; - -namespace { +namespace floormat { -struct proxy { - StringView name; - Vector2ub size; - pass_mode passability; -}; +} // namespace floormat -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) - -} // namespace +using namespace floormat; namespace nlohmann { -void adl_serializer<std::shared_ptr<ground_atlas>>::to_json(json& j, const std::shared_ptr<const ground_atlas>& x) +#if 0 +void adl_serializer<ground_info>::to_json(json& j, const ground_info& x) { using nlohmann::to_json; - if (!x) - j = nullptr; - else - to_json(j, proxy{x->name(), x->num_tiles2(), x->pass_mode()}); + j = std::tuple<StringView, Vector2ub, pass_mode>{x.name, x.size, x.pass}; } +#endif -void adl_serializer<std::shared_ptr<ground_atlas>>::from_json(const json& j, std::shared_ptr<ground_atlas>& val) +void adl_serializer<ground_info>::from_json(const json& j, ground_info& val) { - if (j.is_null()) - val = nullptr; - else - { - using nlohmann::from_json; - proxy x; - from_json(j, x); - pass_mode p = ground_atlas::default_pass_mode; - if (j.contains("pass-mode")) - p = j["pass-mode"]; - val = loader.ground_atlas(x.name, x.size, p); - if (auto p2 = val->pass_mode(); p2 != p) - { - const auto name = val->name(); - fm_throw("atlas {} wrong pass mode {} should be {}"_cf, name, uint8_t(p2), uint8_t(p)); - } - } + using nlohmann::from_json; + val.name = j["name"]; + val.size = j["size"]; + if (j.contains("pass-mode")) + val.pass = j["pass-mode"]; } } // namespace nlohmann diff --git a/serialize/ground-atlas.hpp b/serialize/ground-atlas.hpp index 344e8714..7ca57ede 100644 --- a/serialize/ground-atlas.hpp +++ b/serialize/ground-atlas.hpp @@ -1,14 +1,19 @@ #pragma once -#include "src/ground-atlas.hpp" -#include <memory> +#include "loader/ground-info.hpp" #include <nlohmann/json_fwd.hpp> +namespace floormat { + +struct ground_info; + +} // namespace floormat + namespace nlohmann { 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); +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); }; } // namespace nlohmann diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp index dc0c42cc..85de29ec 100644 --- a/serialize/wall-atlas.cpp +++ b/serialize/wall-atlas.cpp @@ -9,7 +9,6 @@ #include <string_view> #include <Corrade/Containers/ArrayViewStl.h> #include <Corrade/Containers/StringStl.h> -#include <Corrade/Containers/TripleStl.h> #include <Magnum/ImageView.h> #include <Magnum/Trade/ImageData.h> #include <nlohmann/json.hpp> |