dl
dl
render
dl_animation_info.h
浏览该文件的文档.
1
12
#pragma once
13
14
#include "
dl_type.h
"
15
#include "
io/dl_json.h
"
16
17
18
namespace
dl
19
{
20
constexpr
unsigned
ANIMATION_FTIME
= 125;
21
23
struct
AnimationInfo
24
{
25
struct
Node
26
{
27
unsigned
_beg
= 0;
28
unsigned
_skip
= 0;
29
unsigned
_ftime
=
ANIMATION_FTIME
;
30
unsigned
_dir
= 1;
31
unsigned
_count
= 0;
32
};
33
std::string
_type
=
""
;
// sheet.动画在一张图上 multi.多张图组成的动画
34
std::string
_format
=
"{}_{}"
;
35
unsigned
_skip
= 0;
36
unsigned
_ftime
=
ANIMATION_FTIME
;
37
unsigned
_dir
= 1;
38
unsigned
_count
= 0;
// sheet.0表示sheet的所有精灵 multi.表示1张
39
40
std::unordered_map<std::string, Node, string_hash, std::equal_to<>>
_allAni
;
41
};
42
43
inline
void
to_json
(
json
& j,
const
AnimationInfo
& info)
44
{
45
j =
json
{
46
{
"type"
, info.
_type
},
47
{
"format"
, info.
_format
},
48
{
"skip"
, info.
_skip
},
49
{
"ftime"
, info.
_ftime
},
50
{
"dir"
, info.
_dir
},
51
{
"count"
, info.
_count
},
52
};
53
json
j_ani = {};
54
for
(
auto
& iter : info.
_allAni
)
55
{
56
AnimationInfo::Node
node = iter.second;
57
json
j_node;
58
j_node[
"name"
] = iter.first;
59
j_node[
"beg"
] = node.
_beg
;
60
j_node[
"skip"
] = node.
_skip
;
61
j_node[
"ftime"
] = node.
_ftime
;
62
j_node[
"dir"
] = node.
_dir
;
63
j_node[
"count"
] = node.
_count
;
64
j_ani.push_back(j_node);
65
}
66
j[
"ani"
] = j_ani;
67
}
68
inline
void
from_json
(
const
json
& j,
AnimationInfo
& info)
69
{
70
Json::DisableLog
l;
71
Json::Get
(j,
"type"
, info.
_type
);
72
Json::Get
(j,
"format"
, info.
_format
);
73
Json::Get
(j,
"skip"
, info.
_skip
);
74
Json::Get
(j,
"ftime"
, info.
_ftime
);
75
Json::Get
(j,
"dir"
, info.
_dir
);
76
Json::Get
(j,
"count"
, info.
_count
);
77
json
j_ani;
78
Json::Get
(j,
"ani"
, j_ani);
79
for
(
auto
& iter : j_ani)
80
{
81
std::string name;
82
AnimationInfo::Node
node;
83
Json::Get
(iter,
"name"
, name);
84
Json::Get
(iter,
"beg"
, node.
_beg
);
85
if
(!
Json::Get
(iter,
"skip"
, node.
_skip
))
86
node.
_skip
= info.
_skip
;
87
if
(!
Json::Get
(iter,
"ftime"
, node.
_ftime
))
88
node.
_ftime
= info.
_ftime
;
89
if
(!
Json::Get
(iter,
"dir"
, node.
_dir
))
90
node.
_dir
= info.
_dir
;
91
if
(!
Json::Get
(iter,
"count"
, node.
_count
))
92
node.
_count
= info.
_count
;
93
auto
iter = info.
_allAni
.find(name);
94
if
(iter != info.
_allAni
.end())
95
{
96
log_warn
(
"子动画名重复,将覆盖:{}"
, name);
97
}
98
info.
_allAni
[name] = node;
99
}
100
}
101
}
dl_json.h
json格式相关
json
nlohmann::json json
定义
dl_json.h:19
log_warn
#define log_warn(...)
定义
dl_log.h:230
dl_type.h
通用类型
dl::Json::Get
bool Get(const json &j, const std::string &name, T &t)
从json返回值,不存在则返回false,打印日志
定义
dl_json.h:55
dl
定义
dl_array2.h:19
dl::to_json
void to_json(json &j, const AnimationInfo &info)
定义
dl_animation_info.h:43
dl::ANIMATION_FTIME
constexpr unsigned ANIMATION_FTIME
定义
dl_animation_info.h:20
dl::from_json
void from_json(const json &j, AnimationInfo &info)
定义
dl_animation_info.h:68
dl::AnimationInfo::Node
定义
dl_animation_info.h:26
dl::AnimationInfo::Node::_skip
unsigned _skip
定义
dl_animation_info.h:28
dl::AnimationInfo::Node::_beg
unsigned _beg
定义
dl_animation_info.h:27
dl::AnimationInfo::Node::_ftime
unsigned _ftime
定义
dl_animation_info.h:29
dl::AnimationInfo::Node::_count
unsigned _count
定义
dl_animation_info.h:31
dl::AnimationInfo::Node::_dir
unsigned _dir
定义
dl_animation_info.h:30
dl::AnimationInfo
动画信息
定义
dl_animation_info.h:24
dl::AnimationInfo::_format
std::string _format
定义
dl_animation_info.h:34
dl::AnimationInfo::_ftime
unsigned _ftime
定义
dl_animation_info.h:36
dl::AnimationInfo::_skip
unsigned _skip
定义
dl_animation_info.h:35
dl::AnimationInfo::_type
std::string _type
定义
dl_animation_info.h:33
dl::AnimationInfo::_dir
unsigned _dir
定义
dl_animation_info.h:37
dl::AnimationInfo::_count
unsigned _count
定义
dl_animation_info.h:38
dl::AnimationInfo::_allAni
std::unordered_map< std::string, Node, string_hash, std::equal_to<> > _allAni
定义
dl_animation_info.h:40
dl::Json::DisableLog
临时关闭json日志
定义
dl_json.h:34
制作者
1.13.1