summaryrefslogtreecommitdiffhomepage
path: root/serialize/anim.hpp
blob: 8915e8f11334c98a03c3e751e478a47b5036e6a2 (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 <Corrade/Containers/String.h>
#include <Magnum/Magnum.h>
#include <Magnum/Math/Vector2.h>
#include <nlohmann/json_fwd.hpp>

namespace floormat::Serialize {

struct anim_frame final
{
    Vector2ui 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;
    Vector2ui ground;
};

struct anim final
{
    static constexpr int default_fps = 24;

    String object_name, anim_name;
    std::vector<anim_group> groups;
    Vector2ui pixel_size;
    std::size_t nframes = 0, width = 0, height = 0, fps = default_fps, actionframe = 0;
};

} // 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