blob: 2bd2762695d8d3783ba6b17a0005752302fffa0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
#include "wall-atlas.hpp"
#include "magnum-vector2i.hpp"
#include "magnum-vector.hpp"
#include "compat/exception.hpp"
#include <utility>
#include <Corrade/Containers/StringStl.h>
#include <nlohmann/json.hpp>
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(const nlohmann::json& j, wall_frames& val)
{
if (j.contains("pixel-size"))
val.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"))
val.tint_mult = Vector4(t["mult"]);
if (t.contains("add"))
val.tint_add = Vector3(t["add"]);
}
if (j.contains("from-rotation"))
val.from_rotation = (uint8_t)rotation_from_name(std::string{j["from-rotation"]});
if (j.contains("mirrored"))
val.mirrored = j["mirrored"];
}
void write_frameset_metadata(nlohmann::json& j, const wall_atlas& a, const wall_frames& val)
{
constexpr wall_frames default_value;
#if 0
fm_soft_assert(val.index != (uint32_t)default_value.index);
fm_soft_assert(val.count != (uint32_t)default_value.count);
fm_soft_assert(val.pixel_size != default_value.pixel_size);
fm_soft_assert(val.from_rotation == (uint8_t)-1 || val.from_rotation < 4);
#endif
fm_soft_assert(val.index < a.array().size());
fm_soft_assert(val.count != (uint32_t)-1 && val.count > 0);
j["pixel-size"] = val.pixel_size;
if (val.tint_mult != default_value.tint_mult || val.tint_add != default_value.tint_add)
{
auto tint = std::pair{Vector4{val.tint_mult}, Vector3{val.tint_add}};
}
}
} // namespace
} // namespace floormat
namespace nlohmann {
using namespace floormat;
void adl_serializer<std::shared_ptr<wall_atlas>>::to_json(json& j, const std::shared_ptr<const wall_atlas>& x)
{
}
void adl_serializer<std::shared_ptr<wall_atlas>>::from_json(const json& j, std::shared_ptr<wall_atlas>& x)
{
}
} // namespace nlohmann
|