summaryrefslogtreecommitdiffhomepage
path: root/serialize/anim.hpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-05 15:47:29 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-05 15:47:29 +0200
commit6731ab0243ba437595062558e56b800d5eca9cf5 (patch)
tree39025a8ca381ff6f71cbe316c7d72b32f506a9bf /serialize/anim.hpp
parent2c26d57dc97eb7105a6dca2089fd42847a8c2b37 (diff)
a
Diffstat (limited to 'serialize/anim.hpp')
-rw-r--r--serialize/anim.hpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/serialize/anim.hpp b/serialize/anim.hpp
new file mode 100644
index 00000000..f03e3c8c
--- /dev/null
+++ b/serialize/anim.hpp
@@ -0,0 +1,47 @@
+#pragma once
+
+#include <tuple>
+#include <array>
+#include <vector>
+#include <string>
+
+#include <Magnum/Magnum.h>
+#include <Magnum/Math/Vector2.h>
+
+namespace std::filesystem { class path; }
+
+namespace Magnum::Examples::Serialize {
+
+struct anim_frame final
+{
+ Magnum::Vector2i ground, offset, size;
+};
+
+enum class anim_direction : unsigned char
+{
+ N, NE, E, SE, S, SW, W, NW,
+ COUNT,
+};
+
+struct anim_group final
+{
+ std::string name;
+ std::vector<anim_frame> frames;
+ Magnum::Vector2i ground;
+};
+
+struct anim final
+{
+ static std::tuple<anim, bool> from_json(const std::filesystem::path& pathname) noexcept;
+ [[nodiscard]] bool to_json(const std::filesystem::path& pathname) const noexcept;
+ static constexpr int default_fps = 24;
+
+ std::string name;
+ std::array<anim_group, (std::size_t)anim_direction::COUNT> groups;
+ int nframes = 0;
+ int width = 0, height = 0;
+ int actionframe = -1, fps = default_fps;
+};
+
+} // namespace Magnum::Examples::Serialize
+