summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-07 11:00:05 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-07 11:00:05 +0200
commit49d18e6b8a95f6ae4755cacd958248ffbdbf59ff (patch)
tree910f1c47b71bbd14595750185bffac15a4fdfe48 /serialize
parent7740c71ecedd90f9b465dc35994e64915dbda826 (diff)
a
Diffstat (limited to 'serialize')
-rw-r--r--serialize/anim.cpp32
-rw-r--r--serialize/anim.hpp18
2 files changed, 29 insertions, 21 deletions
diff --git a/serialize/anim.cpp b/serialize/anim.cpp
index dffe2449..42ad1de2 100644
--- a/serialize/anim.cpp
+++ b/serialize/anim.cpp
@@ -1,5 +1,4 @@
#include "serialize/magnum-vector2i.hpp"
-#include "serialize/json-helper.hpp"
#include "serialize/anim.hpp"
#include <tuple>
@@ -9,28 +8,23 @@
namespace Magnum::Examples::Serialize {
-#if defined __clang__ || defined __CLION_IDE__
-# pragma clang diagnostic push
-# pragma clang diagnostic ignored "-Wweak-vtables"
-# pragma clang diagnostic ignored "-Wcovered-switch-default"
-#endif
-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_frame, ground, offset, size)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim_group, name, frames, ground)
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(anim, name, nframes, actionframe, fps, groups, width, height)
-#if defined __clang__ || defined __CLION_IDE__
-# pragma clang diagnostic pop
-#endif
+} // namespace Magnum::Examples::Serialize
-std::tuple<anim, bool> anim::from_json(const std::filesystem::path& pathname)
-{
- return json_helper::from_json<anim>(pathname);
-}
+using namespace Magnum::Examples::Serialize;
-bool anim::to_json(const std::filesystem::path& pathname) const
-{
- return json_helper::to_json(*this, pathname);
-}
+namespace nlohmann {
-} // namespace Magnum::Examples::Serialize
+void adl_serializer<anim_frame>::to_json(json& j, const anim_frame& val) { using nlohmann::to_json; to_json(j, val); }
+void adl_serializer<anim_frame>::from_json(const json& j, anim_frame& val) { using nlohmann::from_json; from_json(j, val); }
+
+void adl_serializer<anim_group>::to_json(json& j, const anim_group& val) { using nlohmann::to_json; to_json(j, val); }
+void adl_serializer<anim_group>::from_json(const json& j, anim_group& val) { using nlohmann::from_json; from_json(j, val); }
+
+void adl_serializer<anim>::to_json(json& j, const anim& val) { using nlohmann::to_json; to_json(j, val); }
+void adl_serializer<anim>::from_json(const json& j, anim& val) { using nlohmann::from_json; from_json(j, val); }
+
+} // namespace nlohmann
diff --git a/serialize/anim.hpp b/serialize/anim.hpp
index 3b5504f8..bce88923 100644
--- a/serialize/anim.hpp
+++ b/serialize/anim.hpp
@@ -32,8 +32,6 @@ struct anim_group final
struct anim final
{
- static std::tuple<anim, bool> from_json(const std::filesystem::path& pathname);
- [[nodiscard]] bool to_json(const std::filesystem::path& pathname) const;
static constexpr int default_fps = 24;
std::string name;
@@ -47,6 +45,22 @@ struct anim final
namespace nlohmann {
+template<>
+struct adl_serializer<Magnum::Examples::Serialize::anim_frame> {
+ static void to_json(json& j, const Magnum::Examples::Serialize::anim_frame& val);
+ static void from_json(const json& j, Magnum::Examples::Serialize::anim_frame& val);
+};
+
+template<>
+struct adl_serializer<Magnum::Examples::Serialize::anim_group> {
+ static void to_json(json& j, const Magnum::Examples::Serialize::anim_group& val);
+ static void from_json(const json& j, Magnum::Examples::Serialize::anim_group& val);
+};
+template<>
+struct adl_serializer<Magnum::Examples::Serialize::anim> {
+ static void to_json(json& j, const Magnum::Examples::Serialize::anim& val);
+ static void from_json(const json& j, Magnum::Examples::Serialize::anim& val);
+};
} // namespace nlohmann