From ec1df0878b2f2b37055f0fce388cf9a027046c94 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 3 Nov 2023 01:13:59 +0100 Subject: wip --- serialize/wall-atlas.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ serialize/wall-atlas.hpp | 15 ++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 serialize/wall-atlas.cpp create mode 100644 serialize/wall-atlas.hpp (limited to 'serialize') diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp new file mode 100644 index 00000000..2e0e8cb2 --- /dev/null +++ b/serialize/wall-atlas.cpp @@ -0,0 +1,62 @@ +#include "wall-atlas.hpp" +#include "magnum-vector2i.hpp" +#include "magnum-vector.hpp" +#include "compat/exception.hpp" +#include +#include + +namespace floormat { + +namespace { + +constexpr StringView rotation_names[] = { "n"_s, "e"_s, "s"_s, "w"_s, }; + +size_t rotation_from_name(StringView s) +{ + for (auto i = 0uz; auto n : rotation_names) + { + if (n == s) + return i; + i++; + } + fm_throw("bad rotation name '{}'"_cf, fmt::string_view{s.data(), s.size()}); +} + +void read_frameset_metadata(nlohmann::json& j, wall_frames& ret) +{ + if (j.contains("pixel-size")) + ret.pixel_size = j["pixel-size"]; + if (j.contains("tint")) + { + auto& t = j["tint"]; + fm_soft_assert(t.contains("mult") || t.contains("add")); + if (t.contains("mult")) + ret.tint_mult = Vector4(t["mult"]); + if (t.contains("add")) + ret.tint_add = Vector3(t["add"]); + } + if (j.contains("from-rotation")) + ret.from_rotation = (uint8_t)rotation_from_name(std::string{j["from-rotation"]}); + if (j.contains("mirrored")) + ret.mirrored = j["mirrored"]; +} + +} // namespace + +} // namespace floormat + +namespace nlohmann { + +using namespace floormat; + +void adl_serializer>::to_json(json& j, const std::shared_ptr& x) +{ + +} + +void adl_serializer>::from_json(const json& j, std::shared_ptr& x) +{ + +} + +} // namespace nlohmann diff --git a/serialize/wall-atlas.hpp b/serialize/wall-atlas.hpp new file mode 100644 index 00000000..5e454f87 --- /dev/null +++ b/serialize/wall-atlas.hpp @@ -0,0 +1,15 @@ +#pragma once +#include "src/wall-atlas.hpp" +#include +#include + +namespace nlohmann { + +template<> +struct adl_serializer> +{ + static void to_json(json& j, const std::shared_ptr& x); + static void from_json(const json& j, std::shared_ptr& x); +}; + +} // namespace nlohmann -- cgit v1.2.3