diff options
-rw-r--r-- | serialize/wall-atlas.cpp | 24 | ||||
-rw-r--r-- | serialize/wall-atlas.hpp | 2 | ||||
-rw-r--r-- | src/wall-atlas.cpp | 6 | ||||
-rw-r--r-- | src/wall-atlas.hpp | 10 |
4 files changed, 37 insertions, 5 deletions
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp index 6f29026d..e2e6eee8 100644 --- a/serialize/wall-atlas.cpp +++ b/serialize/wall-atlas.cpp @@ -101,14 +101,28 @@ Info read_info_header(const json& jroot) return val; } +void write_direction_metadata(json& jroot, const Direction& dir, Direction_ i) +{ + auto name = std::string_view{direction_index_to_name((size_t)i)}; + auto j = json{json::value_t::object}; + fm_assert(!jroot.contains(name)); + + for (auto [s_, memfn, tag] : Direction::members) + { + std::string_view s = s_; + const auto& group = dir.*memfn; + write_group_metadata(j[s], group); + } + + jroot[name] = std::move(j); +} + void write_group_metadata(json& jgroup, const Group& val) { - fm_soft_assert(jgroup.is_object()); - fm_soft_assert(jgroup.empty()); + fm_assert(jgroup.is_object()); + fm_assert(jgroup.empty()); - //jgroup[""s] = ; - if (val.index != none) - jgroup["index"s] = val.index; + jgroup["index"s] = val.index; jgroup["count"s] = val.count; jgroup["pixel-size"s] = val.pixel_size; jgroup["tint-mult"s] = Vector4(val.tint_mult); diff --git a/serialize/wall-atlas.hpp b/serialize/wall-atlas.hpp index 16c43ab6..6c50da6b 100644 --- a/serialize/wall-atlas.hpp +++ b/serialize/wall-atlas.hpp @@ -18,10 +18,12 @@ namespace floormat::Wall::detail { uint8_t direction_index_from_name(StringView s); StringView direction_index_to_name(size_t i); + [[nodiscard]] Group read_group_metadata(const nlohmann::json& jgroup); [[nodiscard]] Direction read_direction_metadata(const nlohmann::json& jroot, Direction_ dir); Info read_info_header(const nlohmann::json& jroot); void write_group_metadata(nlohmann::json& jgroup, const Group& val); +void write_info_header(nlohmann::json& jroot, const Info& info); } // namespace floormat::Wall::detail diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp index 24910549..344404d3 100644 --- a/src/wall-atlas.cpp +++ b/src/wall-atlas.cpp @@ -127,4 +127,10 @@ bool Direction::is_empty() const noexcept return true; } +bool Frame::operator==(const Frame&) const noexcept = default; +bool Group::operator==(const Group&) const noexcept = default; +bool Direction::operator==(const Direction&) const noexcept = default; +bool Info::operator==(const floormat::Wall::Info&) const noexcept = default; +bool DirArrayIndex::operator==(const floormat::Wall::DirArrayIndex&) const noexcept = default; + } // namespace floormat::Wall diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp index c54c3971..8df0c1ec 100644 --- a/src/wall-atlas.hpp +++ b/src/wall-atlas.hpp @@ -15,6 +15,8 @@ namespace floormat::Wall { struct Frame { Vector2ui offset = { (unsigned)-1, (unsigned)-1 }; + + bool operator==(const Frame&) const noexcept; }; struct Group @@ -29,6 +31,8 @@ struct Group explicit operator bool() const noexcept { return !is_empty(); } bool is_empty() const noexcept { return count == 0; } + + bool operator==(const Group&) const noexcept; }; enum class Tag : uint8_t { wall, overlay, side, top, corner_L, corner_R, COUNT }; @@ -55,17 +59,23 @@ struct Direction { "corner-R"_s, &Direction::corner_R, Tag::corner_R, }, }; static_assert(arraySize(members) == (size_t)Tag::COUNT); + + bool operator==(const Direction&) const noexcept; }; struct Info { String name = "(unnamed)"_s, description = {}; unsigned depth = 0; + + bool operator==(const Info&) const noexcept; }; struct DirArrayIndex { std::uint8_t val = (uint8_t)-1; operator bool() const { return val == (uint8_t)-1; } + + bool operator==(const DirArrayIndex&) const noexcept; }; } // namespace floormat::Wall |