Repository navigation
Expand file tree
/
Copy pathFrameAnimationMsgPack.h
More file actions
50 lines (40 loc) · 1.77 KB
/
Copy pathFrameAnimationMsgPack.h
File metadata and controls
50 lines (40 loc) · 1.77 KB
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
#pragma once
#include <cstdint>
#include <cstddef>
namespace Deki2D
{
// The MessagePack cache format for frame animations. Frames are named by
// sprite frame GUID, not pixel coordinates, and one file holds several
// animations (such as idle, walk, run).
//
// The format comes from the struct: FrameAnimationData is DEKI_SERIALIZABLE,
// so the reflection codegen emits Deki::Serialize<T> (save) and
// DeserializeMsgPack (load). Keys are the struct field names, hashed the same
// way as component fields, so the map is:
// { "spritesheetGuid": "...", "animations": [
// { "name": "idle", "frames": [ { "frameGuid": "...", "duration": 100 } ],
// "loop": true } ] }
// To change the format, change the struct fields and re-export the .anim assets.
struct FrameAnimationData;
constexpr const char* kFrameanimExtension = ".anim";
/// Reads and writes frame animations in the MessagePack format.
class FrameAnimationMsgPackHelper
{
public:
/// Loads the animation file at `msgpackPath` into `outData`. Returns false
/// on failure.
static bool LoadAnimation(const char* msgpackPath, FrameAnimationData* outData);
/// Loads an animation from MessagePack bytes in memory into `outData`.
/// Returns false on failure.
static bool LoadAnimationFromMemory(const uint8_t* data, size_t size, FrameAnimationData* outData);
#ifdef DEKI_EDITOR
/// Writes `animData` to `msgpackPath`. Editor only. Returns false on
/// failure.
static bool SaveAnimation(const char* msgpackPath, const FrameAnimationData* animData);
#endif
};
/// Registers the "Animation" asset loader. Safe to call more than once. Called
/// from Deki2DInitSystem (Deki2DInit.h), which is also what links this file
/// into a firmware.
void RegisterAnimationLoader();
} // namespace Deki2D