summaryrefslogtreecommitdiffhomepage
path: root/anim/serialize.hpp
blob: a8b13d41672493f963e0a04f428890b95709c591 (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
#pragma once

#include "defs.hpp"

#include <string>
#include <array>
#include <vector>

#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>

namespace std::filesystem { class path; }

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) 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;
};