summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt1
-rw-r--r--serialize/wall-atlas.cpp31
-rw-r--r--src/wall-atlas.cpp3
-rw-r--r--src/wall-atlas.hpp6
4 files changed, 32 insertions, 9 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 199a4008..1ecf2291 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -247,6 +247,7 @@ add_subdirectory(serialize)
add_subdirectory(editor)
add_subdirectory(test)
add_subdirectory(anim-crop-tool)
+add_subdirectory(wall-tileset-tool)
find_package(benchmark QUIET)
if(TARGET benchmark::benchmark OR TARGET benchmark)
diff --git a/serialize/wall-atlas.cpp b/serialize/wall-atlas.cpp
index 2e0e8cb2..2bd27626 100644
--- a/serialize/wall-atlas.cpp
+++ b/serialize/wall-atlas.cpp
@@ -2,6 +2,7 @@
#include "magnum-vector2i.hpp"
#include "magnum-vector.hpp"
#include "compat/exception.hpp"
+#include <utility>
#include <Corrade/Containers/StringStl.h>
#include <nlohmann/json.hpp>
@@ -22,23 +23,41 @@ size_t rotation_from_name(StringView s)
fm_throw("bad rotation name '{}'"_cf, fmt::string_view{s.data(), s.size()});
}
-void read_frameset_metadata(nlohmann::json& j, wall_frames& ret)
+void read_frameset_metadata(const nlohmann::json& j, wall_frames& val)
{
if (j.contains("pixel-size"))
- ret.pixel_size = j["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"))
- ret.tint_mult = Vector4(t["mult"]);
+ val.tint_mult = Vector4(t["mult"]);
if (t.contains("add"))
- ret.tint_add = Vector3(t["add"]);
+ val.tint_add = Vector3(t["add"]);
}
if (j.contains("from-rotation"))
- ret.from_rotation = (uint8_t)rotation_from_name(std::string{j["from-rotation"]});
+ val.from_rotation = (uint8_t)rotation_from_name(std::string{j["from-rotation"]});
if (j.contains("mirrored"))
- ret.mirrored = j["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
diff --git a/src/wall-atlas.cpp b/src/wall-atlas.cpp
index 9b711f60..685125cd 100644
--- a/src/wall-atlas.cpp
+++ b/src/wall-atlas.cpp
@@ -47,7 +47,8 @@ StringView wall_atlas::name() const { return _info.name; }
ArrayView<const wall_frame> wall_frames::items(const wall_atlas& a) const
{
- fm_debug_assert(index != (uint32_t)-1);
+ fm_assert(index < a.array().size());
+ fm_debug_assert(count != (uint32_t)-1);
return { a.array() + index, count };
}
diff --git a/src/wall-atlas.hpp b/src/wall-atlas.hpp
index 02d0ce91..4706a47b 100644
--- a/src/wall-atlas.hpp
+++ b/src/wall-atlas.hpp
@@ -18,13 +18,15 @@ struct wall_frame
struct wall_frames
{
- uint32_t index = (uint32_t)-1, count = (uint32_t)-1;
+ ArrayView<const wall_frame> items(const wall_atlas& a) const;
+
+ uint32_t index = (uint32_t)-1, count = (uint32_t)-1; // not serialized
+
Vector2ui pixel_size;
Color4 tint_mult{1,1,1,1};
Color3 tint_add;
uint8_t from_rotation = (uint8_t)-1;
bool mirrored : 1 = false;
- ArrayView<const wall_frame> items(const wall_atlas& a) const;
};
struct wall_frame_set