summaryrefslogtreecommitdiffhomepage
path: root/serialize/anim.hpp
blob: f03e3c8c1f59e4884459b330f66a159075232205 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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