2012-06-06 08:15:28 +08:00
|
|
|
#include "CCNodeLoaderLibrary.h"
|
|
|
|
|
|
|
|
#include "CCLayerLoader.h"
|
|
|
|
#include "CCLayerColorLoader.h"
|
|
|
|
#include "CCLayerGradientLoader.h"
|
|
|
|
#include "CCLabelBMFontLoader.h"
|
|
|
|
#include "CCLabelTTFLoader.h"
|
|
|
|
#include "CCSpriteLoader.h"
|
|
|
|
#include "CCScale9SpriteLoader.h"
|
|
|
|
#include "CCBFileLoader.h"
|
|
|
|
#include "CCMenuLoader.h"
|
|
|
|
#include "CCMenuItemLoader.h"
|
|
|
|
#include "CCMenuItemImageLoader.h"
|
|
|
|
#include "CCControlButtonLoader.h"
|
|
|
|
#include "CCParticleSystemQuadLoader.h"
|
2012-06-18 19:00:26 +08:00
|
|
|
#include "CCScrollViewLoader.h"
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
USING_NS_CC;
|
2012-07-19 17:22:36 +08:00
|
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
2012-06-06 08:15:28 +08:00
|
|
|
|
|
|
|
CCNodeLoaderLibrary::CCNodeLoaderLibrary() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CCNodeLoaderLibrary::~CCNodeLoaderLibrary() {
|
|
|
|
this->purge(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNodeLoaderLibrary::registerDefaultCCNodeLoaders() {
|
|
|
|
this->registerCCNodeLoader("CCNode", CCNodeLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCLayer", CCLayerLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCLayerColor", CCLayerColorLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCLayerGradient", CCLayerGradientLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCSprite", CCSpriteLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCLabelBMFont", CCLabelBMFontLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCLabelTTF", CCLabelTTFLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCScale9Sprite", CCScale9SpriteLoader::loader());
|
2012-06-18 19:00:26 +08:00
|
|
|
this->registerCCNodeLoader("CCScrollView", CCScrollViewLoader::loader());
|
2012-06-06 08:15:28 +08:00
|
|
|
this->registerCCNodeLoader("CCBFile", CCBFileLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCMenu", CCMenuLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCMenuItemImage", CCMenuItemImageLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCControlButton", CCControlButtonLoader::loader());
|
|
|
|
this->registerCCNodeLoader("CCParticleSystemQuad", CCParticleSystemQuadLoader::loader());
|
|
|
|
}
|
|
|
|
|
2012-06-14 16:16:54 +08:00
|
|
|
void CCNodeLoaderLibrary::registerCCNodeLoader(const char * pClassName, CCNodeLoader * pCCNodeLoader) {
|
2012-06-20 11:48:31 +08:00
|
|
|
this->registerCCNodeLoader(CCString::create(pClassName), pCCNodeLoader);
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
|
|
|
|
2012-06-14 16:16:54 +08:00
|
|
|
void CCNodeLoaderLibrary::registerCCNodeLoader(CCString * pClassName, CCNodeLoader * pCCNodeLoader) {
|
2012-06-15 04:51:32 +08:00
|
|
|
pClassName->retain();
|
2012-06-14 16:16:54 +08:00
|
|
|
pCCNodeLoader->retain();
|
2012-06-15 04:51:32 +08:00
|
|
|
this->mCCNodeLoaders.insert(CCNodeLoaderMapEntry(pClassName, pCCNodeLoader));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCNodeLoaderLibrary::unregisterCCNodeLoader(const char * pClassName) {
|
2012-06-20 11:48:31 +08:00
|
|
|
this->unregisterCCNodeLoader(CCString::create(pClassName));
|
2012-06-14 16:16:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCNodeLoaderLibrary::unregisterCCNodeLoader(CCString * pClassName) {
|
2012-06-15 04:51:32 +08:00
|
|
|
CCNodeLoaderMap::iterator ccNodeLoadersIterator = this->mCCNodeLoaders.find(pClassName);
|
2012-06-06 08:15:28 +08:00
|
|
|
assert(ccNodeLoadersIterator != this->mCCNodeLoaders.end());
|
2012-06-15 04:51:32 +08:00
|
|
|
ccNodeLoadersIterator->first->release();
|
2012-06-06 08:15:28 +08:00
|
|
|
ccNodeLoadersIterator->second->release();
|
|
|
|
}
|
|
|
|
|
2012-06-14 16:16:54 +08:00
|
|
|
CCNodeLoader * CCNodeLoaderLibrary::getCCNodeLoader(CCString * pClassName) {
|
2012-06-15 04:51:32 +08:00
|
|
|
CCNodeLoaderMap::iterator ccNodeLoadersIterator = this->mCCNodeLoaders.find(pClassName);
|
2012-06-06 08:15:28 +08:00
|
|
|
assert(ccNodeLoadersIterator != this->mCCNodeLoaders.end());
|
|
|
|
return ccNodeLoadersIterator->second;
|
|
|
|
}
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
void CCNodeLoaderLibrary::purge(bool pReleaseCCNodeLoaders) {
|
|
|
|
if(pReleaseCCNodeLoaders) {
|
2012-06-15 04:51:32 +08:00
|
|
|
for(CCNodeLoaderMap::iterator it = this->mCCNodeLoaders.begin(); it != this->mCCNodeLoaders.end(); it++) {
|
2012-06-19 16:31:26 +08:00
|
|
|
it->first->release();
|
2012-06-06 08:15:28 +08:00
|
|
|
it->second->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this->mCCNodeLoaders.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CCNodeLoaderLibrary * sSharedCCNodeLoaderLibrary = NULL;
|
|
|
|
|
|
|
|
CCNodeLoaderLibrary * CCNodeLoaderLibrary::sharedCCNodeLoaderLibrary() {
|
|
|
|
if(sSharedCCNodeLoaderLibrary == NULL) {
|
|
|
|
sSharedCCNodeLoaderLibrary = new CCNodeLoaderLibrary();
|
|
|
|
|
|
|
|
sSharedCCNodeLoaderLibrary->registerDefaultCCNodeLoaders();
|
|
|
|
}
|
|
|
|
return sSharedCCNodeLoaderLibrary;
|
|
|
|
}
|
|
|
|
|
2012-06-12 01:43:07 +08:00
|
|
|
void CCNodeLoaderLibrary::purgeSharedCCNodeLoaderLibrary() {
|
|
|
|
CC_SAFE_DELETE(sSharedCCNodeLoaderLibrary);
|
|
|
|
}
|
|
|
|
|
2012-06-06 08:15:28 +08:00
|
|
|
CCNodeLoaderLibrary * CCNodeLoaderLibrary::newDefaultCCNodeLoaderLibrary() {
|
|
|
|
CCNodeLoaderLibrary * ccNodeLoaderLibrary = CCNodeLoaderLibrary::library();
|
2012-06-19 10:34:15 +08:00
|
|
|
|
2012-06-06 08:15:28 +08:00
|
|
|
ccNodeLoaderLibrary->registerDefaultCCNodeLoaders();
|
|
|
|
|
|
|
|
return ccNodeLoaderLibrary;
|
2012-07-19 17:22:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_EXT_END
|