2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "CCArmatureDataManager.h"
|
|
|
|
#include "CCTransformHelp.h"
|
|
|
|
#include "CCDataReaderHelper.h"
|
|
|
|
#include "CCSpriteFrameCacheHelper.h"
|
|
|
|
#include "../physics/CCPhysicsWorld.h"
|
|
|
|
|
|
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
|
|
|
|
|
|
|
static CCArmatureDataManager *s_sharedArmatureDataManager = NULL;
|
|
|
|
|
|
|
|
CCArmatureDataManager *CCArmatureDataManager::sharedArmatureDataManager()
|
|
|
|
{
|
|
|
|
if (s_sharedArmatureDataManager == NULL)
|
|
|
|
{
|
|
|
|
s_sharedArmatureDataManager = new CCArmatureDataManager();
|
|
|
|
if (!s_sharedArmatureDataManager || !s_sharedArmatureDataManager->init())
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(s_sharedArmatureDataManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s_sharedArmatureDataManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCArmatureDataManager::CCArmatureDataManager(void)
|
|
|
|
{
|
|
|
|
m_pAnimationDatas = NULL;
|
|
|
|
m_pArmarureDatas = NULL;
|
|
|
|
m_pTextureDatas = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CCArmatureDataManager::~CCArmatureDataManager(void)
|
|
|
|
{
|
|
|
|
removeAll();
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(m_pAnimationDatas);
|
|
|
|
CC_SAFE_DELETE(m_pArmarureDatas);
|
|
|
|
CC_SAFE_DELETE(m_pTextureDatas);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCArmatureDataManager::purgeArmatureSystem()
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
CCSpriteFrameCacheHelper::purgeSpriteFrameCacheHelper();
|
|
|
|
CCPhysicsWorld::purgePhysicsWorld();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(s_sharedArmatureDataManager);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCArmatureDataManager::init()
|
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
m_pArmarureDatas = CCDictionary::create();
|
|
|
|
CCAssert(m_pArmarureDatas, "create CCArmatureDataManager::m_pArmarureDatas fail!");
|
|
|
|
m_pArmarureDatas->retain();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
m_pAnimationDatas = CCDictionary::create();
|
|
|
|
CCAssert(m_pAnimationDatas, "create CCArmatureDataManager::m_pAnimationDatas fail!");
|
|
|
|
m_pAnimationDatas->retain();
|
|
|
|
|
|
|
|
m_pTextureDatas = CCDictionary::create();
|
|
|
|
CCAssert(m_pTextureDatas, "create CCArmatureDataManager::m_pTextureDatas fail!");
|
|
|
|
m_pTextureDatas->retain();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-06-06 16:22:58 +08:00
|
|
|
void CCArmatureDataManager::addArmatureData(const char *id, CCArmatureData *armatureData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
if(m_pArmarureDatas)
|
|
|
|
{
|
|
|
|
m_pArmarureDatas->setObject(armatureData, id);
|
|
|
|
}
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
CCArmatureData *CCArmatureDataManager::getArmatureData(const char *id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
CCArmatureData *armatureData = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
if (m_pArmarureDatas)
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
armatureData = (CCArmatureData *)m_pArmarureDatas->objectForKey(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
return armatureData;
|
|
|
|
}
|
|
|
|
|
2013-06-06 16:22:58 +08:00
|
|
|
void CCArmatureDataManager::addAnimationData(const char *id, CCAnimationData *animationData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
if(m_pAnimationDatas)
|
|
|
|
{
|
|
|
|
m_pAnimationDatas->setObject(animationData, id);
|
|
|
|
}
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 16:22:58 +08:00
|
|
|
void CCArmatureDataManager::addTextureData(const char *id, CCTextureData *textureData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
if(m_pTextureDatas)
|
|
|
|
{
|
|
|
|
m_pTextureDatas->setObject(textureData, id);
|
|
|
|
}
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
CCAnimationData *CCArmatureDataManager::getAnimationData(const char *id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-06 16:22:58 +08:00
|
|
|
CCAnimationData *animationData = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
if (m_pAnimationDatas)
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
animationData = (CCAnimationData *)m_pAnimationDatas->objectForKey(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
return animationData;
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
CCTextureData *CCArmatureDataManager::getTextureData(const char *id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-06 16:22:58 +08:00
|
|
|
CCTextureData *textureData = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
if (m_pTextureDatas)
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
textureData = (CCTextureData *)m_pTextureDatas->objectForKey(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CCArmatureDataManager::addArmatureFileInfo(const char *armatureName, const char *useExistFileInfo, const char *imagePath, const char *plistPath, const char *configFilePath)
|
|
|
|
{
|
|
|
|
addArmatureFileInfo(imagePath, plistPath, configFilePath);
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
void CCArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath)
|
|
|
|
{
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
CCDataReaderHelper::addDataFromFile(configFilePath);
|
|
|
|
addSpriteFrameFromFile(plistPath, imagePath);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath)
|
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
// if(Game::sharedGame()->isUsePackage())
|
|
|
|
// {
|
|
|
|
// CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromPak(plistPath, imagePath);
|
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
|
|
|
// CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath);
|
|
|
|
// }
|
2013-06-06 12:02:54 +08:00
|
|
|
CCSpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCArmatureDataManager::removeAll()
|
|
|
|
{
|
|
|
|
if( m_pAnimationDatas )
|
|
|
|
{
|
|
|
|
m_pAnimationDatas->removeAllObjects();
|
|
|
|
}
|
|
|
|
if( m_pArmarureDatas )
|
|
|
|
{
|
|
|
|
m_pArmarureDatas->removeAllObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_pTextureDatas )
|
|
|
|
{
|
|
|
|
m_pTextureDatas->removeAllObjects();
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
CCDataReaderHelper::clear();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
NS_CC_EXT_END
|