2018-01-29 16:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocosbuilder/CCNodeLoaderLibrary.h"
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2016-03-20 21:53:44 +08:00
|
|
|
#include "editor-support/cocosbuilder/CCLayerLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCLayerColorLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCLayerGradientLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCLabelBMFontLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCLabelTTFLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCSpriteLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCScale9SpriteLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCBFileLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCMenuLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCMenuItemLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCMenuItemImageLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCControlButtonLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/CCParticleSystemQuadLoader.h"
|
|
|
|
#include "editor-support/cocosbuilder/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) {
|
2016-10-12 01:59:44 +08:00
|
|
|
for(auto& it : this->_nodeLoaders) {
|
|
|
|
it.second->release();
|
2012-06-06 08:15:28 +08:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|