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

#include <tuple>
#include <vector>
#include <string>
#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
{
    std::string name;
    std::vector<anim_frame> frames;
    Vector2i ground;
};

struct anim final
{
    static constexpr int default_fps = 24;

    std::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