CCArmatureDataManager.h
6.87 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/****************************************************************************
Copyright (c) 2013-2016 Chukong Technologies Inc.
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCARMATUREDATAMANAGER_H__
#define __CCARMATUREDATAMANAGER_H__
#include "editor-support/cocostudio/CCArmatureDefine.h"
#include "editor-support/cocostudio/CCDatas.h"
#include "editor-support/cocostudio/CocosStudioExport.h"
namespace cocostudio {
struct RelativeData
{
std::vector<std::string> plistFiles;
std::vector<std::string> armatures;
std::vector<std::string> animations;
std::vector<std::string> textures;
};
/**
* @brief format and manage armature configuration and armature animation
*/
class CC_STUDIO_DLL ArmatureDataManager : public cocos2d::Ref
{
public:
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static ArmatureDataManager *sharedArmatureDataManager() { return ArmatureDataManager::getInstance(); }
/** @deprecated Use destroyInstance() instead */
CC_DEPRECATED_ATTRIBUTE static void purge() { ArmatureDataManager::destroyInstance(); };
static ArmatureDataManager *getInstance();
static void destroyInstance();
private:
/**
* @js ctor
*/
ArmatureDataManager();
/**
* @js NA
* @lua NA
*/
~ArmatureDataManager();
public:
/**
* Init ArmatureDataManager
*/
virtual bool init();
/**
* Add armature data
* @param id The id of the armature data
* @param armatureData ArmatureData *
*/
void addArmatureData(const std::string& id, ArmatureData *armatureData, const std::string& configFilePath = "");
/**
* @brief get armature data
* @param id the id of the armature data you want to get
* @return ArmatureData *
*/
ArmatureData *getArmatureData(const std::string& id);
/**
* @brief remove armature data
* @param id the id of the armature data you want to get
*/
void removeArmatureData(const std::string& id);
/**
* @brief add animation data
* @param id the id of the animation data
* @return AnimationData *
*/
void addAnimationData(const std::string& id, AnimationData *animationData, const std::string& configFilePath = "");
/**
* @brief get animation data from _animationDatas(Dictionary)
* @param id the id of the animation data you want to get
* @return AnimationData *
*/
AnimationData *getAnimationData(const std::string& id);
/**
* @brief remove animation data
* @param id the id of the animation data
*/
void removeAnimationData(const std::string& id);
/**
* @brief add texture data
* @param id the id of the texture data
* @return TextureData *
*/
void addTextureData(const std::string& id, TextureData *textureData, const std::string& configFilePath = "");
/**
* @brief get texture data
* @param id the id of the texture data you want to get
* @return TextureData *
*/
TextureData *getTextureData(const std::string& id);
/**
* @brief remove texture data
* @param id the id of the texture data you want to get
*/
void removeTextureData(const std::string& id);
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
*/
void addArmatureFileInfo(const std::string& configFilePath);
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
* It will load data in a new thread
*/
void addArmatureFileInfoAsync(const std::string& configFilePath, cocos2d::Ref *target, cocos2d::SEL_SCHEDULE selector);
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
*/
void addArmatureFileInfo(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath);
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
* It will load data in a new thread
*/
void addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, cocos2d::Ref *target, cocos2d::SEL_SCHEDULE selector);
/**
* @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
*/
void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath = "");
virtual void removeArmatureFileInfo(const std::string& configFilePath);
/**
* @brief Judge whether or not need auto load sprite file
*/
bool isAutoLoadSpriteFile();
const cocos2d::Map<std::string, ArmatureData*>& getArmatureDatas() const;
const cocos2d::Map<std::string, AnimationData*>& getAnimationDatas() const;
const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const;
protected:
void addRelativeData(const std::string& configFilePath);
RelativeData *getRelativeData(const std::string& configFilePath);
private:
/**
* @brief save armature datas
* @key std::string
* @value ArmatureData *
*/
cocos2d::Map<std::string, ArmatureData*> _armarureDatas;
/**
* @brief save animation datas
* @key std::string
* @value AnimationData *
*/
cocos2d::Map<std::string, AnimationData*> _animationDatas;
/**
* @brief save texture datas
* @key std::string
* @value TextureData *
*/
cocos2d::Map<std::string, TextureData*> _textureDatas;
bool _autoLoadSpriteFile;
std::unordered_map<std::string, RelativeData> _relativeDatas;
};
}
#endif/*__CCARMATUREDATAMANAGER_H__*/