diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-08 12:05:15 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-08 12:05:15 +0100 |
commit | e70bd100853827b9bafb21103f78ebaa74a2af20 (patch) | |
tree | 5071853cf9774acc23be9b9da203148dd3a0c43c /serialize/anim.cpp | |
parent | 0ab80a1322dd63ec30abc4170d69aa55a028a8fc (diff) |
apparently we can have nice things
Diffstat (limited to 'serialize/anim.cpp')
-rw-r--r-- | serialize/anim.cpp | 108 |
1 files changed, 54 insertions, 54 deletions
diff --git a/serialize/anim.cpp b/serialize/anim.cpp index bea7f3ce..aad40f33 100644 --- a/serialize/anim.cpp +++ b/serialize/anim.cpp @@ -7,7 +7,7 @@ namespace floormat { -using namespace std::string_literals; +using namespace std::string_view_literals; //NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_frame, ground, offset, size) //NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_group, name, frames, ground, offset) @@ -18,106 +18,106 @@ static void to_json(nlohmann::json& j, const anim_frame& val) constexpr anim_frame def; if (val.ground != def.ground) - j["ground"s] = val.ground; + j["ground"sv] = val.ground; if (val.offset != def.offset) - j["offset"s] = val.offset; + j["offset"sv] = val.offset; if (val.size != def.size) - j["size"s] = val.size; + j["size"sv] = val.size; } static void from_json(const nlohmann::json& j, anim_frame& val) { val = {}; - if (j.contains("ground"s)) - val.ground = j["ground"s]; - if (j.contains("offset"s)) - val.offset = j["offset"s]; - if (j.contains("size"s)) - val.size = j["size"s]; + if (j.contains("ground"sv)) + val.ground = j["ground"sv]; + if (j.contains("offset"sv)) + val.offset = j["offset"sv]; + if (j.contains("size"sv)) + val.size = j["size"sv]; } static void to_json(nlohmann::json& j, const anim_group& val) { const anim_group def{}; - j["name"s] = val.name; + j["name"sv] = val.name; if (val.mirror_from) - j["mirror-from"s] = val.mirror_from; + j["mirror-from"sv] = val.mirror_from; else - j["frames"s] = val.frames; + j["frames"sv] = val.frames; if (val.ground != def.ground) - j["ground"s] = val.ground; + j["ground"sv] = val.ground; if (val.offset != def.offset) - j["offset"s] = val.offset; + j["offset"sv] = val.offset; if (val.z_offset != def.z_offset) - j["z-offset"s] = val.z_offset; + j["z-offset"sv] = val.z_offset; if (val.depth_offset != def.depth_offset) - j["depth-offset"s] = val.depth_offset; + j["depth-offset"sv] = val.depth_offset; } static void from_json(const nlohmann::json& j, anim_group& val) { val = {}; - val.name = j["name"s]; + val.name = j["name"sv]; fm_soft_assert(!val.name.isEmpty()); - if (j.contains("mirror-from"s)) + if (j.contains("mirror-from"sv)) { - fm_soft_assert(!j.contains("frames"s)); - val.mirror_from = j["mirror-from"s]; + fm_soft_assert(!j.contains("frames"sv)); + val.mirror_from = j["mirror-from"sv]; } else - val.frames = j["frames"s]; - if (j.contains("ground"s)) - val.ground = j["ground"s]; - if (j.contains("offset"s)) - val.offset = j["offset"s]; - if (j.contains("z-offset"s)) - val.z_offset = j["z-offset"s]; - if (j.contains("depth-offset"s)) - val.depth_offset = j["depth-offset"s]; + val.frames = j["frames"sv]; + if (j.contains("ground"sv)) + val.ground = j["ground"sv]; + if (j.contains("offset"sv)) + val.offset = j["offset"sv]; + if (j.contains("z-offset"sv)) + val.z_offset = j["z-offset"sv]; + if (j.contains("depth-offset"sv)) + val.depth_offset = j["depth-offset"sv]; } static void to_json(nlohmann::json& j, const anim_def& val) { const anim_def def{}; - j["object_name"s] = val.object_name; + j["object_name"sv] = val.object_name; if (val.anim_name != def.anim_name) - j["anim_name"s] = val.anim_name; + j["anim_name"sv] = val.anim_name; if (val.pixel_size != def.pixel_size) - j["pixel_size"s] = val.pixel_size; + j["pixel_size"sv] = val.pixel_size; if (val.nframes != def.nframes) - j["nframes"s] = val.nframes; + j["nframes"sv] = val.nframes; if (val.action_frame != def.action_frame) - j["action-frame"s] = val.action_frame; + j["action-frame"sv] = val.action_frame; if (val.action_frame2 != def.action_frame2) - j["action-frame-2"s] = val.action_frame2; + j["action-frame-2"sv] = val.action_frame2; if (val.fps != def.fps) - j["fps"s] = val.fps; - j["groups"s] = val.groups; - j["scale"s] = val.scale; + j["fps"sv] = val.fps; + j["groups"sv] = val.groups; + j["scale"sv] = val.scale; } static void from_json(const nlohmann::json& j, anim_def& val) { val = {}; - val.object_name = j["object_name"s]; + val.object_name = j["object_name"sv]; fm_soft_assert(!val.object_name.isEmpty()); - if (j.contains("anim_name"s)) // todo underscore to hyphen - val.anim_name = j["anim_name"s]; - if (j.contains("pixel_size"s)) - val.pixel_size = j["pixel_size"s]; - if (j.contains("nframes"s)) - val.nframes = j["nframes"s]; - if (j.contains("action-frame"s)) - val.action_frame = j["action-frame"s]; - if (j.contains("action-frame-2"s)) - val.action_frame2 = j["action-frame-2"s]; - if (j.contains("fps"s)) - val.fps = j["fps"s]; - val.groups = j["groups"s]; + if (j.contains("anim_name"sv)) // todo underscore to hyphen + val.anim_name = j["anim_name"sv]; + if (j.contains("pixel_size"sv)) + val.pixel_size = j["pixel_size"sv]; + if (j.contains("nframes"sv)) + val.nframes = j["nframes"sv]; + if (j.contains("action-frame"sv)) + val.action_frame = j["action-frame"sv]; + if (j.contains("action-frame-2"sv)) + val.action_frame2 = j["action-frame-2"sv]; + if (j.contains("fps"sv)) + val.fps = j["fps"sv]; + val.groups = j["groups"sv]; fm_soft_assert(!val.groups.empty()); - val.scale = j["scale"s]; + val.scale = j["scale"sv]; fm_soft_assert(val.scale.type != anim_scale_type::invalid); } |