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"
|
|
|
|
|
|
|
|
|
2013-06-17 21:32:15 +08:00
|
|
|
namespace cocos2d { namespace extension { namespace armature {
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
static ArmatureDataManager *s_sharedArmatureDataManager = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ArmatureDataManager *ArmatureDataManager::sharedArmatureDataManager()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
if (s_sharedArmatureDataManager == NULL)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
s_sharedArmatureDataManager = new ArmatureDataManager();
|
2013-06-06 12:02:54 +08:00
|
|
|
if (!s_sharedArmatureDataManager || !s_sharedArmatureDataManager->init())
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(s_sharedArmatureDataManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return s_sharedArmatureDataManager;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ArmatureDataManager::ArmatureDataManager(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_armarureDatas = NULL;
|
|
|
|
_animationDatas = NULL;
|
|
|
|
_textureDatas = NULL;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ArmatureDataManager::~ArmatureDataManager(void)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-08-22 11:12:09 +08:00
|
|
|
CCLOGINFO("deallocing ArmatureDataManager: %p", this);
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
removeAll();
|
|
|
|
|
2013-08-22 11:12:09 +08:00
|
|
|
CC_SAFE_RELEASE(_animationDatas);
|
|
|
|
CC_SAFE_RELEASE(_armarureDatas);
|
|
|
|
CC_SAFE_RELEASE(_textureDatas);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::purgeArmatureSystem()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
SpriteFrameCacheHelper::purgeSpriteFrameCacheHelper();
|
|
|
|
PhysicsWorld::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
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
bool ArmatureDataManager::init()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
do
|
|
|
|
{
|
2013-08-22 11:12:09 +08:00
|
|
|
_armarureDatas = new Dictionary;
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(_armarureDatas, "create ArmatureDataManager::_armarureDatas fail!");
|
2013-08-22 11:12:09 +08:00
|
|
|
_armarureDatas->init();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-08-22 11:12:09 +08:00
|
|
|
_animationDatas = new Dictionary;
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(_animationDatas, "create ArmatureDataManager::_animationDatas fail!");
|
2013-08-22 11:12:09 +08:00
|
|
|
_animationDatas->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-08-22 11:12:09 +08:00
|
|
|
_textureDatas = new Dictionary;
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(_textureDatas, "create ArmatureDataManager::_textureDatas fail!");
|
2013-08-22 11:12:09 +08:00
|
|
|
_textureDatas->init();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
while (0);
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::addArmatureData(const char *id, ArmatureData *armatureData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_armarureDatas)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_armarureDatas->setObject(armatureData, id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ArmatureData *ArmatureDataManager::getArmatureData(const char *id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
ArmatureData *armatureData = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_armarureDatas)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
armatureData = (ArmatureData *)_armarureDatas->objectForKey(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
return armatureData;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::addAnimationData(const char *id, AnimationData *animationData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_animationDatas)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_animationDatas->setObject(animationData, id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::addTextureData(const char *id, TextureData *textureData)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_textureDatas)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_textureDatas->setObject(textureData, id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
AnimationData *ArmatureDataManager::getAnimationData(const char *id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
AnimationData *animationData = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_animationDatas)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
animationData = (AnimationData *)_animationDatas->objectForKey(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
return animationData;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
TextureData *ArmatureDataManager::getTextureData(const char *id)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
TextureData *textureData = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_textureDatas)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
textureData = (TextureData *)_textureDatas->objectForKey(id);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::addArmatureFileInfo(const char *armatureName, const char *useExistFileInfo, const char *imagePath, const char *plistPath, const char *configFilePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
addArmatureFileInfo(imagePath, plistPath, configFilePath);
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::addArmatureFileInfo(const char *imagePath, const char *plistPath, const char *configFilePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DataReaderHelper::addDataFromFile(configFilePath);
|
2013-06-07 10:52:32 +08:00
|
|
|
addSpriteFrameFromFile(plistPath, imagePath);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::addSpriteFrameFromFile(const char *plistPath, const char *imagePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
// if(Game::sharedGame()->isUsePackage())
|
|
|
|
// {
|
2013-06-20 14:15:53 +08:00
|
|
|
// SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromPak(plistPath, imagePath);
|
2013-06-07 10:52:32 +08:00
|
|
|
// }
|
|
|
|
// else
|
|
|
|
// {
|
2013-06-20 14:15:53 +08:00
|
|
|
// SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath);
|
2013-06-07 10:52:32 +08:00
|
|
|
// }
|
2013-06-20 14:15:53 +08:00
|
|
|
SpriteFrameCacheHelper::sharedSpriteFrameCacheHelper()->addSpriteFrameFromFile(plistPath, imagePath);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void ArmatureDataManager::removeAll()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _animationDatas )
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_animationDatas->removeAllObjects();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _armarureDatas )
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_armarureDatas->removeAllObjects();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _textureDatas )
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_textureDatas->removeAllObjects();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DataReaderHelper::clear();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-06-17 21:32:15 +08:00
|
|
|
}}} // namespace cocos2d { namespace extension { namespace armature {
|