summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-02-11 12:55:19 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-02-11 17:57:39 +0100
commit24fd873d96e1e6bc3284b404033802fb963e5c7f (patch)
tree97ebaeccaac8e25909c432d47edfbb0e229180a3
parentfeafb7e71370fa9d041be2f0e7f72f93fa03c33f (diff)
serialize/anim: skip default value fields
-rw-r--r--scenery/control-panel.json4
-rw-r--r--serialize/anim.cpp83
-rw-r--r--src/anim.hpp4
3 files changed, 81 insertions, 10 deletions
diff --git a/scenery/control-panel.json b/scenery/control-panel.json
index d410ea31..a446c041 100644
--- a/scenery/control-panel.json
+++ b/scenery/control-panel.json
@@ -1,13 +1,9 @@
{
- "actionframe": 0,
- "anim_name": "",
- "fps": 0,
"groups": [
{
"frames": [
{
"ground": "17 x 66",
- "offset": "0 x 0",
"size": "41 x 78"
}
],
diff --git a/serialize/anim.cpp b/serialize/anim.cpp
index f0c1eae0..e7985824 100644
--- a/serialize/anim.cpp
+++ b/serialize/anim.cpp
@@ -6,9 +6,86 @@
namespace floormat {
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_frame, ground, offset, size)
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_group, name, frames, ground, offset)
-NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_def, object_name, anim_name, pixel_size, nframes, actionframe, fps, groups, scale)
+//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_frame, ground, offset, size)
+//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_group, name, frames, ground, offset)
+//NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_def, object_name, anim_name, pixel_size, nframes, actionframe, fps, groups, scale)
+
+static void to_json(nlohmann::json& j, const anim_frame& val)
+{
+ if (!val.ground.isZero())
+ j["ground"] = val.ground;
+ if (!val.offset.isZero())
+ j["offset"] = val.offset;
+ if (!val.size.isZero())
+ j["size"] = val.size;
+}
+
+static void from_json(const nlohmann::json& j, anim_frame& val)
+{
+ val = {};
+ if (j.contains("ground"))
+ val.ground = j["ground"];
+ if (j.contains("offset"))
+ val.offset = j["offset"];
+ if (j.contains("size"))
+ val.size = j["size"];
+}
+
+static void to_json(nlohmann::json& j, const anim_group& val)
+{
+ j["name"] = val.name;
+ j["frames"] = val.frames;
+ if (!val.ground.isZero())
+ j["ground"] = val.ground;
+ if (!val.offset.isZero())
+ j["offset"] = val.offset;
+}
+
+static void from_json(const nlohmann::json& j, anim_group& val)
+{
+ val = {};
+ val.name = j["name"];
+ val.frames = j["frames"];
+ if (j.contains("ground"))
+ val.ground = j["ground"];
+ if (j.contains("offset"))
+ val.offset = j["offset"];
+}
+
+static void to_json(nlohmann::json& j, const anim_def& val)
+{
+ j["object_name"] = val.object_name;
+ if (!val.anim_name.isEmpty())
+ j["anim_name"] = val.anim_name;
+ if (!val.pixel_size.isZero())
+ j["pixel_size"] = val.pixel_size;
+ if (val.nframes > 0)
+ j["nframes"] = val.nframes;
+ if (val.actionframe > 0)
+ j["actionframe"] = val.actionframe;
+ if (val.fps > 0)
+ j["fps"] = val.fps;
+ j["groups"] = val.groups;
+ j["scale"] = val.scale;
+}
+
+static void from_json(const nlohmann::json& j, anim_def& val)
+{
+ val = {};
+ val.object_name = j["object_name"];
+ if (j.contains("anim_name"))
+ val.anim_name = j["anim_name"];
+ if (j.contains("pixel_size"))
+ val.pixel_size = j["pixel_size"];
+ if (j.contains("nframes"))
+ val.nframes = j["nframes"];
+ if (j.contains("actionframe"))
+ val.actionframe = j["actionframe"];
+ if (j.contains("fps"))
+ val.fps = j["fps"];
+ val.groups = j["groups"];
+ val.scale = j["scale"];
+}
} // namespace floormat
diff --git a/src/anim.hpp b/src/anim.hpp
index bee8147a..2927b7e3 100644
--- a/src/anim.hpp
+++ b/src/anim.hpp
@@ -47,13 +47,11 @@ struct anim_scale final
struct anim_def final
{
- static constexpr int default_fps = 24;
-
String object_name, anim_name;
std::vector<anim_group> groups;
Vector2ui pixel_size;
anim_scale scale;
- std::size_t nframes = 0, fps = default_fps, actionframe = 0;
+ std::size_t nframes = 0, fps = 0, actionframe = 0;
};
} // namespace floormat