2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2013-06-06 12:02:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "2d/SpriteFrameCache.h"
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2023-06-11 13:08:08 +08:00
|
|
|
#include "ArmatureDataManager.h"
|
|
|
|
#include "TransformHelp.h"
|
|
|
|
#include "DataReaderHelper.h"
|
|
|
|
#include "SpriteFrameCacheHelper.h"
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
static ArmatureDataManager* s_sharedArmatureDataManager = nullptr;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureDataManager* ArmatureDataManager::getInstance()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
if (s_sharedArmatureDataManager == nullptr)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
s_sharedArmatureDataManager = new ArmatureDataManager();
|
|
|
|
if (!s_sharedArmatureDataManager->init())
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_DELETE(s_sharedArmatureDataManager);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return s_sharedArmatureDataManager;
|
|
|
|
}
|
|
|
|
|
2013-12-27 20:54:05 +08:00
|
|
|
void ArmatureDataManager::destroyInstance()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
SpriteFrameCacheHelper::purge();
|
|
|
|
DataReaderHelper::purge();
|
2022-07-15 19:17:01 +08:00
|
|
|
AX_SAFE_RELEASE_NULL(s_sharedArmatureDataManager);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
ArmatureDataManager::ArmatureDataManager(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-17 19:32:16 +08:00
|
|
|
_armarureDatas.clear();
|
|
|
|
_animationDatas.clear();
|
|
|
|
_textureDatas.clear();
|
2013-09-15 20:24:25 +08:00
|
|
|
_autoLoadSpriteFile = false;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
ArmatureDataManager::~ArmatureDataManager(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-17 19:32:16 +08:00
|
|
|
_animationDatas.clear();
|
|
|
|
_armarureDatas.clear();
|
|
|
|
_textureDatas.clear();
|
2013-10-31 17:28:14 +08:00
|
|
|
|
|
|
|
_relativeDatas.clear();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
bool ArmatureDataManager::init()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
do
|
|
|
|
{
|
2013-12-17 19:32:16 +08:00
|
|
|
_armarureDatas.clear();
|
|
|
|
_animationDatas.clear();
|
|
|
|
_textureDatas.clear();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
bRet = true;
|
2021-12-25 10:04:45 +08:00
|
|
|
} while (0);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::removeArmatureFileInfo(std::string_view configFilePath)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (RelativeData* data = getRelativeData(configFilePath))
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
2020-10-17 16:32:16 +08:00
|
|
|
for (std::string str : data->armatures)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
2016-02-03 23:12:37 +08:00
|
|
|
removeArmatureData(str);
|
2013-10-31 17:28:14 +08:00
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
for (std::string str : data->animations)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
2016-02-03 23:12:37 +08:00
|
|
|
removeAnimationData(str);
|
2013-10-31 17:28:14 +08:00
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
for (std::string str : data->textures)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
2016-02-03 23:12:37 +08:00
|
|
|
removeTextureData(str);
|
2013-10-31 17:28:14 +08:00
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
for (std::string str : data->plistFiles)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
2014-11-07 09:13:59 +08:00
|
|
|
SpriteFrameCacheHelper::getInstance()->removeSpriteFrameFromFile(str);
|
2013-10-31 17:28:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
_relativeDatas.erase(configFilePath);
|
2013-11-06 15:25:44 +08:00
|
|
|
DataReaderHelper::getInstance()->removeConfigFile(configFilePath);
|
2013-10-31 17:28:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addArmatureData(std::string_view id,
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* armatureData,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view configFilePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (RelativeData* data = getRelativeData(configFilePath))
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-08-09 09:54:53 +08:00
|
|
|
data->armatures.emplace_back(std::string{id});
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-12-17 19:32:16 +08:00
|
|
|
|
|
|
|
_armarureDatas.insert(id, armatureData);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ArmatureData* ArmatureDataManager::getArmatureData(std::string_view id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2017-02-09 10:57:01 +08:00
|
|
|
return dynamic_cast<ArmatureData*>(_armarureDatas.at(id));
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::removeArmatureData(std::string_view id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-17 19:32:16 +08:00
|
|
|
_armarureDatas.erase(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addAnimationData(std::string_view id,
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* animationData,
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string_view configFilePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (RelativeData* data = getRelativeData(configFilePath))
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-08-09 09:54:53 +08:00
|
|
|
data->animations.emplace_back(std::string{id});
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-12-17 19:32:16 +08:00
|
|
|
|
|
|
|
_animationDatas.insert(id, animationData);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
AnimationData* ArmatureDataManager::getAnimationData(std::string_view id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2017-02-09 10:57:01 +08:00
|
|
|
return dynamic_cast<AnimationData*>(_animationDatas.at(id));
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::removeAnimationData(std::string_view id)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-12-17 19:32:16 +08:00
|
|
|
_animationDatas.erase(id);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
void ArmatureDataManager::addTextureData(std::string_view id, TextureData* textureData, std::string_view configFilePath)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (RelativeData* data = getRelativeData(configFilePath))
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2022-08-09 09:54:53 +08:00
|
|
|
data->textures.emplace_back(std::string{id});
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-12-17 19:32:16 +08:00
|
|
|
|
|
|
|
_textureDatas.insert(id, textureData);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
TextureData* ArmatureDataManager::getTextureData(std::string_view id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2017-02-09 10:57:01 +08:00
|
|
|
return dynamic_cast<TextureData*>(_textureDatas.at(id));
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::removeTextureData(std::string_view id)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-12-17 19:32:16 +08:00
|
|
|
_textureDatas.erase(id);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addArmatureFileInfo(std::string_view configFilePath)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-10-31 17:28:14 +08:00
|
|
|
addRelativeData(configFilePath);
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_autoLoadSpriteFile = true;
|
2013-09-16 15:16:05 +08:00
|
|
|
DataReaderHelper::getInstance()->addDataFromFile(configFilePath);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-28 11:00:34 +08:00
|
|
|
void ArmatureDataManager::addArmatureFileInfoAsync(std::string_view configFilePath, Ref* target, SEL_SCHEDULE selector)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-10-31 17:28:14 +08:00
|
|
|
addRelativeData(configFilePath);
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_autoLoadSpriteFile = true;
|
2013-10-30 09:41:40 +08:00
|
|
|
DataReaderHelper::getInstance()->addDataFromFileAsync("", "", configFilePath, target, selector);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addArmatureFileInfo(std::string_view imagePath,
|
|
|
|
std::string_view plistPath,
|
|
|
|
std::string_view configFilePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-10-31 17:28:14 +08:00
|
|
|
addRelativeData(configFilePath);
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_autoLoadSpriteFile = false;
|
2013-09-16 15:16:05 +08:00
|
|
|
DataReaderHelper::getInstance()->addDataFromFile(configFilePath);
|
2014-11-07 11:43:55 +08:00
|
|
|
addSpriteFrameFromFile(plistPath, imagePath, configFilePath);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addArmatureFileInfoAsync(std::string_view imagePath,
|
|
|
|
std::string_view plistPath,
|
|
|
|
std::string_view configFilePath,
|
2021-12-25 10:04:45 +08:00
|
|
|
Ref* target,
|
|
|
|
SEL_SCHEDULE selector)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-10-31 17:28:14 +08:00
|
|
|
addRelativeData(configFilePath);
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_autoLoadSpriteFile = false;
|
2013-10-30 09:41:40 +08:00
|
|
|
DataReaderHelper::getInstance()->addDataFromFileAsync(imagePath, plistPath, configFilePath, target, selector);
|
2014-11-07 11:43:55 +08:00
|
|
|
addSpriteFrameFromFile(plistPath, imagePath, configFilePath);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addSpriteFrameFromFile(std::string_view plistPath,
|
|
|
|
std::string_view imagePath,
|
|
|
|
std::string_view configFilePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (RelativeData* data = getRelativeData(configFilePath))
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2022-08-09 09:54:53 +08:00
|
|
|
data->plistFiles.emplace_back(std::string{plistPath});
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-10-31 17:28:14 +08:00
|
|
|
SpriteFrameCacheHelper::getInstance()->addSpriteFrameFromFile(plistPath, imagePath);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
bool ArmatureDataManager::isAutoLoadSpriteFile()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _autoLoadSpriteFile;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::StringMap<ArmatureData*>& ArmatureDataManager::getArmatureDatas() const
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _armarureDatas;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::StringMap<AnimationData*>& ArmatureDataManager::getAnimationDatas() const
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _animationDatas;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2022-08-08 18:02:17 +08:00
|
|
|
const ax::StringMap<TextureData*>& ArmatureDataManager::getTextureDatas() const
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
return _textureDatas;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ArmatureDataManager::addRelativeData(std::string_view configFilePath)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
|
|
|
if (_relativeDatas.find(configFilePath) == _relativeDatas.end())
|
|
|
|
{
|
|
|
|
_relativeDatas[configFilePath] = RelativeData();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
RelativeData* ArmatureDataManager::getRelativeData(std::string_view configFilePath)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
|
|
|
return &_relativeDatas[configFilePath];
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|