summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
Diffstat (limited to 'serialize')
-rw-r--r--serialize/magnum-vector.hpp2
-rw-r--r--serialize/wall-atlas.cpp23
-rw-r--r--serialize/wall-atlas.hpp4
3 files changed, 26 insertions, 3 deletions
diff --git a/serialize/magnum-vector.hpp b/serialize/magnum-vector.hpp
index a45103d8..ddd09228 100644
--- a/serialize/magnum-vector.hpp
+++ b/serialize/magnum-vector.hpp
@@ -32,7 +32,7 @@ void adl_serializer<Magnum::Math::Vector<N, T>>::from_json(const json& j, vec& v
val[i] = array[i];
}
-template<typename T> struct adl_serializer<Magnum::Math::Vector2<T>> : adl_serializer<Magnum::Math::Vector<2, T>> {};
+template<typename T> requires (!std::is_integral_v<T>) struct adl_serializer<Magnum::Math::Vector2<T>> : adl_serializer<Magnum::Math::Vector<2, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Vector3<T>> : adl_serializer<Magnum::Math::Vector<3, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Vector4<T>> : adl_serializer<Magnum::Math::Vector<4, T>> {};
template<typename T> struct adl_serializer<Magnum::Math::Color3<T>> : adl_serializer<Magnum::Math::Vector<3, T>> {};
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index 8ebe106a..7480c53f 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -5,6 +5,7 @@
#include <utility>
#include <string_view>
#include <Corrade/Containers/StringStl.h>
+#include <Corrade/Containers/StringStlView.h>
#include <nlohmann/json.hpp>
// todo add test on dummy files that generates 100% coverage on the j.contains() blocks!
@@ -38,7 +39,7 @@ StringView direction_index_to_name(size_t i)
return direction_names[i];
}
-[[nodiscard]] Group read_group_metadata(const json& jgroup)
+Group read_group_metadata(const json& jgroup)
{
fm_assert(jgroup.is_object());
@@ -60,6 +61,26 @@ StringView direction_index_to_name(size_t i)
return val;
}
+Direction read_direction_metadata(const json& jroot, Direction_ dir)
+{
+ std::string_view s = direction_index_to_name((size_t)dir);
+ if (!jroot.contains(s))
+ return {};
+ const auto& jdir = jroot[s];
+
+ Direction val;
+
+ for (auto [s_, memfn, tag] : Direction::members)
+ {
+ std::string_view s = s_;
+ if (!jdir.contains(s))
+ continue;
+ val.*memfn = read_group_metadata(jdir[s]);
+ }
+
+ return val;
+}
+
void write_group_metadata(json& jgroup, const Group& val)
{
constexpr Group default_value;
diff --git a/serialize/wall-atlas.hpp b/serialize/wall-atlas.hpp
index 9f1ba71c..16c43ab6 100644
--- a/serialize/wall-atlas.hpp
+++ b/serialize/wall-atlas.hpp
@@ -19,7 +19,9 @@ 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);
-void write_group_metadata(nlohmann::json& jgroup, const Group& val);
+[[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);
+
} // namespace floormat::Wall::detail