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
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
2012-09-24 11:47:33 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocosbuilder {
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
static NodeLoaderLibrary * sSharedNodeLoaderLibrary = nullptr;
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-07-24 18:00:02 +08:00
|
|
|
NodeLoaderLibrary * NodeLoaderLibrary::getInstance() {
|
2014-07-10 00:45:27 +08:00
|
|
|
if(sSharedNodeLoaderLibrary == nullptr) {
|
2014-08-28 07:31:57 +08:00
|
|
|
sSharedNodeLoaderLibrary = new (std::nothrow) 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
|
|
|
}
|
|
|
|
|
2014-06-19 19:45:24 +08:00
|
|
|
}
|