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-09-24 11:47:33 +08:00
|
|
|
|
2012-07-19 17:22:36 +08:00
|
|
|
|
|
|
|
NS_CC_EXT_BEGIN
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoaderLibrary::NodeLoaderLibrary() {
|
2012-06-06 08:15:28 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoaderLibrary::~NodeLoaderLibrary() {
|
2012-06-06 08:15:28 +08:00
|
|
|
this->purge(true);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void NodeLoaderLibrary::registerDefaultNodeLoaders() {
|
|
|
|
this->registerNodeLoader("CCNode", NodeLoader::loader());
|
|
|
|
this->registerNodeLoader("CCLayer", LayerLoader::loader());
|
|
|
|
this->registerNodeLoader("CCLayerColor", LayerColorLoader::loader());
|
|
|
|
this->registerNodeLoader("CCLayerGradient", LayerGradientLoader::loader());
|
|
|
|
this->registerNodeLoader("CCSprite", SpriteLoader::loader());
|
|
|
|
this->registerNodeLoader("CCLabelBMFont", LabelBMFontLoader::loader());
|
|
|
|
this->registerNodeLoader("CCLabelTTF", LabelTTFLoader::loader());
|
|
|
|
this->registerNodeLoader("CCScale9Sprite", Scale9SpriteLoader::loader());
|
|
|
|
this->registerNodeLoader("CCScrollView", ScrollViewLoader::loader());
|
|
|
|
this->registerNodeLoader("CCBFile", CCBFileLoader::loader());
|
|
|
|
this->registerNodeLoader("CCMenu", MenuLoader::loader());
|
|
|
|
this->registerNodeLoader("CCMenuItemImage", MenuItemImageLoader::loader());
|
|
|
|
this->registerNodeLoader("CCControlButton", ControlButtonLoader::loader());
|
|
|
|
this->registerNodeLoader("CCParticleSystemQuad", ParticleSystemQuadLoader::loader());
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void NodeLoaderLibrary::registerNodeLoader(const char * pClassName, NodeLoader * pNodeLoader) {
|
|
|
|
pNodeLoader->retain();
|
2013-07-27 22:31:57 +08:00
|
|
|
this->_nodeLoaders.insert(NodeLoaderMapEntry(pClassName, pNodeLoader));
|
2012-06-15 04:51:32 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void NodeLoaderLibrary::unregisterNodeLoader(const char * pClassName) {
|
2013-07-27 22:31:57 +08:00
|
|
|
NodeLoaderMap::iterator ccNodeLoadersIterator = this->_nodeLoaders.find(pClassName);
|
|
|
|
if (ccNodeLoadersIterator != this->_nodeLoaders.end())
|
2012-11-26 21:51:05 +08:00
|
|
|
{
|
|
|
|
ccNodeLoadersIterator->second->release();
|
2013-07-27 22:31:57 +08:00
|
|
|
_nodeLoaders.erase(ccNodeLoadersIterator);
|
2012-11-26 21:51:05 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("The loader (%s) doesn't exist", pClassName);
|
|
|
|
}
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoader * NodeLoaderLibrary::getNodeLoader(const char* pClassName) {
|
2013-07-27 22:31:57 +08:00
|
|
|
NodeLoaderMap::iterator ccNodeLoadersIterator = this->_nodeLoaders.find(pClassName);
|
|
|
|
assert(ccNodeLoadersIterator != this->_nodeLoaders.end());
|
2012-06-06 08:15:28 +08:00
|
|
|
return ccNodeLoadersIterator->second;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void NodeLoaderLibrary::purge(bool pReleaseNodeLoaders) {
|
|
|
|
if(pReleaseNodeLoaders) {
|
2013-07-27 22:31:57 +08:00
|
|
|
for(NodeLoaderMap::iterator it = this->_nodeLoaders.begin(); it != this->_nodeLoaders.end(); it++) {
|
2012-06-06 08:15:28 +08:00
|
|
|
it->second->release();
|
|
|
|
}
|
|
|
|
}
|
2013-07-27 22:31:57 +08:00
|
|
|
this->_nodeLoaders.clear();
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
static NodeLoaderLibrary * sSharedNodeLoaderLibrary = NULL;
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-07-24 18:00:02 +08:00
|
|
|
NodeLoaderLibrary * NodeLoaderLibrary::getInstance() {
|
2013-06-20 14:15:53 +08:00
|
|
|
if(sSharedNodeLoaderLibrary == NULL) {
|
|
|
|
sSharedNodeLoaderLibrary = new NodeLoaderLibrary();
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
sSharedNodeLoaderLibrary->registerDefaultNodeLoaders();
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
2013-06-20 14:15:53 +08:00
|
|
|
return sSharedNodeLoaderLibrary;
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
|
|
|
|
2013-07-24 18:00:02 +08:00
|
|
|
void NodeLoaderLibrary::destroyInstance() {
|
2013-06-20 14:15:53 +08:00
|
|
|
CC_SAFE_DELETE(sSharedNodeLoaderLibrary);
|
2012-06-12 01:43:07 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoaderLibrary * NodeLoaderLibrary::newDefaultNodeLoaderLibrary() {
|
|
|
|
NodeLoaderLibrary * ccNodeLoaderLibrary = NodeLoaderLibrary::library();
|
2012-06-19 10:34:15 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
ccNodeLoaderLibrary->registerDefaultNodeLoaders();
|
2012-06-06 08:15:28 +08:00
|
|
|
|
|
|
|
return ccNodeLoaderLibrary;
|
2012-07-19 17:22:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_EXT_END
|