diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-07 19:42:01 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-07 19:43:32 +0100 |
commit | 24c7e1915bf16b4141d0502af040791fed65aa06 (patch) | |
tree | 4f4488a388d4fb2951ee702aed1189819232a6cc | |
parent | 039677a6b78f74ef019ac37a5e789efad6093743 (diff) |
a
-rw-r--r-- | serialize/wall-atlas.cpp | 38 | ||||
-rw-r--r-- | src/wall-atlas.hpp | 5 | ||||
-rw-r--r-- | test/json/wall-atlas-02_groups.json | 13 | ||||
-rw-r--r-- | test/wall-atlas.cpp | 3 |
4 files changed, 32 insertions, 27 deletions
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp index c0824a6a..215b8eae 100644 --- a/serialize/wall-atlas.cpp +++ b/serialize/wall-atlas.cpp @@ -45,6 +45,15 @@ Group read_group_metadata(const json& jgroup) Group val; + { + int count = 0, index = -1; + bool has_count = jgroup.contains("count"s) && (count = jgroup["count"s]) != 0, + has_index = jgroup.contains("index"s); + fm_soft_assert(has_count == has_index); + fm_soft_assert(!has_index || index >= 0 && index < 1 << 20); + // todo check index within range; + } + if (jgroup.contains("pixel-size"s)) val.pixel_size = jgroup["pixel-size"s]; if (jgroup.contains("tint"s)) @@ -53,12 +62,9 @@ Group read_group_metadata(const json& jgroup) val.from_rotation = (uint8_t)direction_index_from_name(std::string{ jgroup["from-rotation"s] }); if (jgroup.contains("mirrored"s)) val.mirrored = !!jgroup["mirrored"s]; - val._default_tint_specified = jgroup.contains("default-tint"s); - if (val._default_tint_specified) + if (jgroup.contains("default-tint"s)) val.default_tint = !!jgroup["default-tint"s]; - fm_soft_assert(val.tint_mult >= Color4{0}); - return val; } @@ -90,26 +96,18 @@ Info read_info_header(const json& jroot) void write_group_metadata(json& jgroup, const Group& val) { - constexpr Group default_value; - fm_soft_assert(jgroup.is_object()); fm_soft_assert(jgroup.empty()); + //jgroup[""s] = ; + if (val.index != none) + jgroup["index"s] = val.index; + jgroup["count"s] = val.count; jgroup["pixel-size"s] = val.pixel_size; - if (val.tint_mult != default_value.tint_mult || val.tint_add != default_value.tint_add) - { - auto tint = std::pair<Vector4, Vector3>{{val.tint_mult}, {val.tint_add}}; - jgroup["tint"s] = tint; - } - if (val.from_rotation != default_value.from_rotation) - { - fm_soft_assert(val.from_rotation != none && val.from_rotation < 4); - jgroup["from-rotation"s] = val.from_rotation; - } - if (val.mirrored != default_value.mirrored) - jgroup["mirrored"s] = val.mirrored; - if (val._default_tint_specified) - jgroup["default-tint"s] = val.default_tint; + jgroup["tint"s] = std::pair<Vector4, Vector3>{{val.tint_mult}, {val.tint_add}}; + jgroup["from-rotation"s] = val.from_rotation; + jgroup["mirrored"s] = val.mirrored; + jgroup["default-tint"s] = val.default_tint; } } // namespace floormat::Wall::detail diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp index 9b41200e..fd518b66 100644 --- a/src/wall-atlas.hpp +++ b/src/wall-atlas.hpp @@ -23,10 +23,9 @@ struct Group Vector2ui pixel_size; Color4 tint_mult{1,1,1,1}; Color3 tint_add; - uint8_t from_rotation = (uint8_t)-1; + uint8_t from_rotation = (uint8_t)-1; // applies only to images bool mirrored : 1 = false, - default_tint : 1 = true, - _default_tint_specified : 1 = false; + default_tint : 1 = true; explicit operator bool() const noexcept { return !is_empty(); } bool is_empty() const noexcept { return count == 0; } diff --git a/test/json/wall-atlas-02_groups.json b/test/json/wall-atlas-02_groups.json index 5bfafe94..1a6ea806 100644 --- a/test/json/wall-atlas-02_groups.json +++ b/test/json/wall-atlas-02_groups.json @@ -2,7 +2,8 @@ "name": "foo", "depth": 42, "frames": [], - "n": {}, + "n": { + }, "w": { "wall": { "default-tint": false @@ -13,6 +14,16 @@ }, "top": { "pixel-size": "42 x 192" + }, + "overlay": { + "pixel-size": "42 x 192", + "tint-mult": [ 0.1, 0.2, 0.3, 0.4 ], + "tint-add": [ 1, 2, 3 ], + "default-tint": false, + "mirrored": true + }, + "corner-L": { + "overlay": { "from-rotation": "n" } } } } diff --git a/test/wall-atlas.cpp b/test/wall-atlas.cpp index 9d20d50a..699043a3 100644 --- a/test/wall-atlas.cpp +++ b/test/wall-atlas.cpp @@ -67,14 +67,11 @@ void test_read_groups(StringView filename) fm_assert(dir.wall.pixel_size == Vector2ui{}); fm_assert(!dir.wall.default_tint); - fm_assert(dir.wall._default_tint_specified); fm_assert(dir.side.pixel_size == Vector2ui{42, 192}); fm_assert(dir.side.default_tint); - fm_assert(dir.side._default_tint_specified); fm_assert(dir.top.default_tint == group_defaults.default_tint); - fm_assert(!dir.top._default_tint_specified); } } // namespace |