diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-05 06:30:59 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-12-05 06:30:59 +0100 |
commit | 960e346159dbf152d9847f0998e1e717fb7dbfef (patch) | |
tree | 6aab5985d1a2f20542e152d70c9be46bbed0025e /serialize | |
parent | 4ad635e8dfe21d2dd0e0582c44379dde26ca57a8 (diff) |
src: add pass_mode field to tile_atlas
Diffstat (limited to 'serialize')
-rw-r--r-- | serialize/tile-atlas.cpp | 37 | ||||
-rw-r--r-- | serialize/world-reader.cpp | 4 |
2 files changed, 32 insertions, 9 deletions
diff --git a/serialize/tile-atlas.cpp b/serialize/tile-atlas.cpp index a92dfc28..6a51da4c 100644 --- a/serialize/tile-atlas.cpp +++ b/serialize/tile-atlas.cpp @@ -3,12 +3,25 @@ #include "serialize/corrade-string.hpp" #include "serialize/magnum-vector2i.hpp" #include "loader/loader.hpp" -#include <tuple> - +#include "serialize/pass-mode.hpp" +#include <Corrade/Containers/Optional.h> +#include <Corrade/Containers/String.h> #include <nlohmann/json.hpp> using namespace floormat; +namespace { + +struct proxy { + String name; + Vector2ub size; + Optional<pass_mode> passability; +}; + +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(proxy, name, size) + +} // namespace + namespace nlohmann { void adl_serializer<std::shared_ptr<tile_atlas>>::to_json(json& j, const std::shared_ptr<const tile_atlas>& x) @@ -17,18 +30,26 @@ void adl_serializer<std::shared_ptr<tile_atlas>>::to_json(json& j, const std::sh if (!x) j = nullptr; else - to_json(j, std::tuple<StringView, Vector2ub>{x->name(), x->num_tiles2()}); + { + to_json(j, proxy{x->name(), x->num_tiles2(), NullOpt}); + if (auto p = x->pass_mode()) + j["pass-mode"] = *p; + } } -void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std::shared_ptr<tile_atlas>& x) +void adl_serializer<std::shared_ptr<tile_atlas>>::from_json(const json& j, std::shared_ptr<tile_atlas>& val) { if (j.is_null()) - x = nullptr; + val = nullptr; else { - std::tuple<String, Vector2ub> proxy = j; - const auto& [name, num_tiles] = proxy; - x = loader.tile_atlas(name, num_tiles); + using nlohmann::from_json; + proxy x; + from_json(j, x); + Optional<pass_mode> p; + if (j.contains("pass-mode")) + p = {InPlaceInit, j["pass-mode"]}; + val = loader.tile_atlas(x.name, x.size, p); } } diff --git a/serialize/world-reader.cpp b/serialize/world-reader.cpp index b0e14254..98704599 100644 --- a/serialize/world-reader.cpp +++ b/serialize/world-reader.cpp @@ -45,7 +45,9 @@ void reader_state::read_atlases(reader_t& s) size[0] << s; size[1] << s; const auto& [buf, len] = s.read_asciiz_string<atlas_name_max>(); - atlases.push_back(loader.tile_atlas({buf, len}, size)); + auto atlas = loader.tile_atlas({buf, len}); + fm_soft_assert(size == atlas->num_tiles2()); + atlases.push_back(std::move(atlas)); } } |