summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--anim-crop-tool/main.cpp5
-rw-r--r--compat/assert.hpp7
-rw-r--r--serialize/anim.cpp32
-rw-r--r--serialize/anim.hpp18
4 files changed, 39 insertions, 23 deletions
diff --git a/anim-crop-tool/main.cpp b/anim-crop-tool/main.cpp
index be3f7469..a95d3bae 100644
--- a/anim-crop-tool/main.cpp
+++ b/anim-crop-tool/main.cpp
@@ -1,5 +1,6 @@
#include "atlas.hpp"
#include "serialize/anim.hpp"
+#include "serialize/json-helper.hpp"
#include "compat/defs.hpp"
#include "compat/sysexits.hpp"
#include "compat/assert.hpp"
@@ -244,7 +245,7 @@ int main(int argc, char** argv)
if (!opts_ok)
return usage(args);
- auto [anim_info, anim_ok] = anim::from_json(opts.input_file);
+ auto [anim_info, anim_ok] = json_helper::from_json<anim>(opts.input_file);
if (!anim_ok)
return EX_DATAERR;
@@ -285,7 +286,7 @@ int main(int argc, char** argv)
<< std::strerror(errno); // NOLINT(concurrency-mt-unsafe)
return EX_CANTCREAT;
}
- if (!anim_info.to_json(opts.output_dir/(anim_info.name + ".json")))
+ if (!json_helper::to_json<anim>(anim_info, opts.output_dir/(anim_info.name + ".json")))
return EX_CANTCREAT;
return 0;
diff --git a/compat/assert.hpp b/compat/assert.hpp
index 81d5d4ab..8383d333 100644
--- a/compat/assert.hpp
+++ b/compat/assert.hpp
@@ -41,6 +41,13 @@ namespace Magnum::Examples {
} \
} while(false)
+#define ASSERT_EXPR(var, expr, cond) \
+ [&] { \
+ decltype(auto) var = (expr); \
+ ASSERT(cond); \
+ return (var); \
+ }()
+
#define GAME_DEBUG_OUT(pfx, ...) ([&]() { \
if constexpr (sizeof((pfx)) > 1) \
std::fputs((pfx), stderr); \
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