axmol/extensions/cocostudio/CCArmatureDataManager.h

218 lines
6.9 KiB
C
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
2020-10-17 16:32:16 +08:00
Copyright (c) 2013-2017 Chukong Technologies Inc.
2019-11-23 20:27:39 +08:00
https://axis-project.github.io/
2019-11-23 20:27:39 +08:00
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 "CCArmatureDefine.h"
#include "CCDatas.h"
#include "CocosStudioExport.h"
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
namespace cocostudio
{
2019-11-23 20:27:39 +08:00
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 CCS_DLL ArmatureDataManager : public axis::Ref
2019-11-23 20:27:39 +08:00
{
public:
/** @deprecated Use getInstance() instead */
CC_DEPRECATED_ATTRIBUTE static ArmatureDataManager* sharedArmatureDataManager()
2021-12-25 10:04:45 +08:00
{
return ArmatureDataManager::getInstance();
}
2019-11-23 20:27:39 +08:00
/** @deprecated Use destroyInstance() instead */
CC_DEPRECATED_ATTRIBUTE static void purge() { ArmatureDataManager::destroyInstance(); };
2021-12-25 10:04:45 +08:00
static ArmatureDataManager* getInstance();
2019-11-23 20:27:39 +08:00
static void destroyInstance();
2021-12-25 10:04:45 +08:00
2020-10-17 16:32:16 +08:00
protected:
2019-11-23 20:27:39 +08:00
/**
* @js ctor
*/
2020-10-17 16:32:16 +08:00
ArmatureDataManager(void);
2019-11-23 20:27:39 +08:00
/**
* @js NA
* @lua NA
*/
2020-10-17 16:32:16 +08:00
~ArmatureDataManager(void);
2019-11-23 20:27:39 +08:00
public:
/**
* Init ArmatureDataManager
*/
virtual bool init();
/**
* Add armature data
* @param id The id of the armature data
* @param armatureData ArmatureData *
*/
void addArmatureData(std::string_view id, ArmatureData* armatureData, std::string_view configFilePath = "");
2019-11-23 20:27:39 +08:00
/**
* @brief get armature data
* @param id the id of the armature data you want to get
* @return ArmatureData *
*/
ArmatureData* getArmatureData(std::string_view id);
2019-11-23 20:27:39 +08:00
/**
* @brief remove armature data
* @param id the id of the armature data you want to get
*/
void removeArmatureData(std::string_view id);
2019-11-23 20:27:39 +08:00
/**
* @brief add animation data
* @param id the id of the animation data
* @return AnimationData *
*/
void addAnimationData(std::string_view id, AnimationData* animationData, std::string_view configFilePath = "");
2019-11-23 20:27:39 +08:00
/**
* @brief get animation data from _animationDatas(Dictionary)
* @param id the id of the animation data you want to get
* @return AnimationData *
*/
AnimationData* getAnimationData(std::string_view id);
2019-11-23 20:27:39 +08:00
/**
* @brief remove animation data
* @param id the id of the animation data
*/
void removeAnimationData(std::string_view id);
2019-11-23 20:27:39 +08:00
/**
* @brief add texture data
* @param id the id of the texture data
* @return TextureData *
*/
void addTextureData(std::string_view id, TextureData* textureData, std::string_view configFilePath = "");
2019-11-23 20:27:39 +08:00
/**
* @brief get texture data
* @param id the id of the texture data you want to get
* @return TextureData *
*/
TextureData* getTextureData(std::string_view id);
2019-11-23 20:27:39 +08:00
/**
* @brief remove texture data
* @param id the id of the texture data you want to get
*/
void removeTextureData(std::string_view id);
2019-11-23 20:27:39 +08:00
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
*/
void addArmatureFileInfo(std::string_view configFilePath);
2019-11-23 20:27:39 +08:00
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
* It will load data in a new thread
*/
void addArmatureFileInfoAsync(std::string_view configFilePath,
axis::Ref* target,
axis::SEL_SCHEDULE selector);
2019-11-23 20:27:39 +08:00
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
*/
void addArmatureFileInfo(std::string_view imagePath, std::string_view plistPath, std::string_view configFilePath);
2019-11-23 20:27:39 +08:00
/**
* @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
* It will load data in a new thread
*/
void addArmatureFileInfoAsync(std::string_view imagePath,
std::string_view plistPath,
std::string_view configFilePath,
axis::Ref* target,
axis::SEL_SCHEDULE selector);
2019-11-23 20:27:39 +08:00
/**
* @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
*/
void addSpriteFrameFromFile(std::string_view plistPath,
std::string_view imagePath,
std::string_view configFilePath = "");
2019-11-23 20:27:39 +08:00
virtual void removeArmatureFileInfo(std::string_view configFilePath);
2019-11-23 20:27:39 +08:00
/**
* @brief Judge whether or not need auto load sprite file
*/
bool isAutoLoadSpriteFile();
const axis::StringMap<ArmatureData*>& getArmatureDatas() const;
const axis::StringMap<AnimationData*>& getAnimationDatas() const;
const axis::StringMap<TextureData*>& getTextureDatas() const;
2019-11-23 20:27:39 +08:00
2020-10-17 16:32:16 +08:00
public:
void addRelativeData(std::string_view configFilePath);
RelativeData* getRelativeData(std::string_view configFilePath);
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
private:
/**
* @brief save armature datas
* @key std::string
* @value ArmatureData *
*/
axis::StringMap<ArmatureData*> _armarureDatas;
2019-11-23 20:27:39 +08:00
/**
* @brief save animation datas
* @key std::string
* @value AnimationData *
*/
axis::StringMap<AnimationData*> _animationDatas;
2019-11-23 20:27:39 +08:00
/**
* @brief save texture datas
* @key std::string
* @value TextureData *
*/
axis::StringMap<TextureData*> _textureDatas;
2019-11-23 20:27:39 +08:00
bool _autoLoadSpriteFile;
hlookup::string_map<RelativeData> _relativeDatas;
2019-11-23 20:27:39 +08:00
};
2021-12-25 10:04:45 +08:00
} // namespace cocostudio
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
#endif /*__CCARMATUREDATAMANAGER_H__*/