summaryrefslogtreecommitdiffhomepage
path: root/serialize/anim.hpp
blob: 536824d3449c3c11afe2169c00c3a1e9ac840fcb (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once

#include <vector>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
#include <nlohmann/json_fwd.hpp>

namespace floormat::Serialize {

struct anim_frame final
{
    Vector2i ground, offset, size;
};

enum class anim_direction : unsigned char
{
    N, NE, E, SE, S, SW, W, NW,
    COUNT,
};

struct anim_group final
{
    String name;
    std::vector<anim_frame> frames;
    Vector2i ground;
};

struct anim final
{
    static constexpr int default_fps = 24;

    String object_name, anim_name;
    std::vector<anim_group> groups;
    int nframes = 0;
    int width = 0, height = 0;
    int actionframe = -1, fps = default_fps;
};

} // namespace floormat::Serialize

namespace nlohmann {

template<>
struct adl_serializer<floormat::Serialize::anim_frame> {
    static void to_json(json& j, const floormat::Serialize::anim_frame& val);
    static void from_json(const json& j, floormat::Serialize::anim_frame& val);
};

template<>
struct adl_serializer<floormat::Serialize::anim_group> {
    static void to_json(json& j, const floormat::Serialize::anim_group& val);
    static void from_json(const json& j, floormat::Serialize::anim_group& val);
};

template<>
struct adl_serializer<floormat::Serialize::anim> {
    static void to_json(json& j, const floormat::Serialize::anim& val);
    static void from_json(const json& j, floormat::Serialize::anim& val);
};

} // namespace nlohmann