summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
Diffstat (limited to 'serialize')
-rw-r--r--serialize/wall-atlas.cpp24
-rw-r--r--serialize/wall-atlas.hpp2
2 files changed, 21 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