2013-09-09 19:51:26 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "cocostudio/CocoStudio.h"
|
|
|
|
#include "gui/CocosGUI.h"
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
|
|
|
using namespace gui;
|
|
|
|
|
|
|
|
namespace cocostudio {
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
SceneReader* SceneReader::s_sharedReader = nullptr;
|
2013-09-09 19:51:26 +08:00
|
|
|
|
|
|
|
SceneReader::SceneReader()
|
2013-12-24 21:23:24 +08:00
|
|
|
: _pListener(NULL)
|
|
|
|
, _pfnSelector(NULL)
|
|
|
|
, _pNode(NULL)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-15 09:45:03 +08:00
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
|
|
|
SceneReader::~SceneReader()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
const char* SceneReader::sceneReaderVersion()
|
|
|
|
{
|
|
|
|
return "1.0.0.0";
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
|
|
|
cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
rapidjson::Document jsonDict;
|
|
|
|
do {
|
|
|
|
CC_BREAK_IF(!readJson(pszFileName, jsonDict));
|
|
|
|
_pNode = createObject(jsonDict, NULL);
|
2013-12-25 17:40:54 +08:00
|
|
|
TriggerMng::getInstance()->parse(jsonDict);
|
2013-09-09 19:51:26 +08:00
|
|
|
} while (0);
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
return _pNode;
|
2013-11-15 09:45:03 +08:00
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
bool SceneReader::readJson(const char *pszFileName, rapidjson::Document &doc)
|
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
do {
|
|
|
|
CC_BREAK_IF(pszFileName == NULL);
|
2013-12-24 21:23:24 +08:00
|
|
|
std::string jsonpath = CCFileUtils::getInstance()->fullPathForFilename(pszFileName);
|
2013-12-24 22:05:13 +08:00
|
|
|
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
|
|
|
|
doc.Parse<0>(contentStr.c_str());
|
2013-12-24 20:33:55 +08:00
|
|
|
CC_BREAK_IF(doc.HasParseError());
|
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* SceneReader::nodeByTag(Node *pParent, int nTag)
|
|
|
|
{
|
|
|
|
if (pParent == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-24 21:23:24 +08:00
|
|
|
Node *_retNode = NULL;
|
2013-12-24 20:33:55 +08:00
|
|
|
Vector<Node*>& Children = pParent->getChildren();
|
|
|
|
Vector<Node*>::iterator iter = Children.begin();
|
|
|
|
while (iter != Children.end())
|
|
|
|
{
|
2013-12-24 21:23:24 +08:00
|
|
|
Node* pNode = *iter;
|
2013-12-24 20:33:55 +08:00
|
|
|
if(pNode != NULL && pNode->getTag() == nTag)
|
|
|
|
{
|
|
|
|
_retNode = pNode;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_retNode = nodeByTag(pNode, nTag);
|
|
|
|
if (_retNode != NULL)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-12-26 01:17:04 +08:00
|
|
|
++iter;
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
return _retNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-12-24 21:23:24 +08:00
|
|
|
Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* parent)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *className = DICTOOL->getStringValue_json(dict, "classname");
|
2013-09-09 19:51:26 +08:00
|
|
|
if(strcmp(className, "CCNode") == 0)
|
|
|
|
{
|
2013-11-14 14:05:24 +08:00
|
|
|
Node* gb = nullptr;
|
2013-12-24 20:33:55 +08:00
|
|
|
if(nullptr == parent)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
gb = Node::create();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gb = Node::create();
|
2013-12-24 20:33:55 +08:00
|
|
|
parent->addChild(gb);
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
setPropertyFromJsonDict(dict, gb);
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int count = DICTOOL->getArrayCount_json(dict, "components");
|
2013-09-09 19:51:26 +08:00
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "components", i);
|
|
|
|
if (!DICTOOL->checkObjectExist_json(subDict))
|
2013-11-15 09:45:03 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
break;
|
2013-11-15 09:45:03 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
|
|
|
|
const char *pComName = DICTOOL->getStringValue_json(subDict, "name");
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(subDict, "fileData");
|
2013-11-15 09:45:03 +08:00
|
|
|
std::string pPath;
|
2013-09-09 19:51:26 +08:00
|
|
|
std::string pPlistFile;
|
2013-11-15 09:45:03 +08:00
|
|
|
int nResType = 0;
|
2013-12-24 20:33:55 +08:00
|
|
|
if (DICTOOL->checkObjectExist_json(fileData))
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *file = DICTOOL->getStringValue_json(fileData, "path");
|
|
|
|
nResType = DICTOOL->getIntValue_json(fileData, "resourceType", - 1);
|
|
|
|
const char *plistFile = DICTOOL->getStringValue_json(fileData, "plistFile");
|
2013-11-15 09:45:03 +08:00
|
|
|
if (file != nullptr)
|
|
|
|
{
|
|
|
|
pPath.append(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
if (plistFile != nullptr)
|
|
|
|
{
|
|
|
|
pPlistFile.append(cocos2d::FileUtils::getInstance()->fullPathForFilename(plistFile));
|
|
|
|
}
|
2013-12-25 17:40:54 +08:00
|
|
|
|
|
|
|
if (file == nullptr && plistFile == nullptr)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
|
|
|
|
2013-11-14 14:05:24 +08:00
|
|
|
if (comName != nullptr && strcmp(comName, "CCSprite") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-15 09:45:03 +08:00
|
|
|
cocos2d::Sprite *pSprite = nullptr;
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
if (nResType == 0)
|
|
|
|
{
|
|
|
|
if (pPath.find(".png") == pPath.npos)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pSprite = Sprite::create(pPath.c_str());
|
|
|
|
}
|
|
|
|
else if (nResType == 1)
|
|
|
|
{
|
|
|
|
std::string pngFile = pPlistFile;
|
|
|
|
std::string::size_type pos = pngFile.find(".plist");
|
|
|
|
if (pos == pPath.npos)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pngFile.replace(pos, pngFile.length(), ".png");
|
|
|
|
CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(pPlistFile.c_str(), pngFile.c_str());
|
|
|
|
pSprite = Sprite::createWithSpriteFrameName(pPath.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
ComRender *pRender = ComRender::create(pSprite, "CCSprite");
|
2013-11-14 14:05:24 +08:00
|
|
|
if (pComName != nullptr)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
pRender->setName(pComName);
|
|
|
|
}
|
|
|
|
|
|
|
|
gb->addComponent(pRender);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
|
|
|
(_pListener->*_pfnSelector)(pSprite, (void*)(&subDict));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-14 14:05:24 +08:00
|
|
|
else if(comName != nullptr && strcmp(comName, "CCTMXTiledMap") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-15 09:45:03 +08:00
|
|
|
cocos2d::TMXTiledMap *pTmx = nullptr;
|
|
|
|
if (nResType == 0)
|
|
|
|
{
|
|
|
|
if (pPath.find(".tmx") == pPath.npos)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
pTmx = TMXTiledMap::create(pPath.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
|
|
|
ComRender *pRender = ComRender::create(pTmx, "CCTMXTiledMap");
|
2013-11-14 14:05:24 +08:00
|
|
|
if (pComName != nullptr)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
pRender->setName(pComName);
|
|
|
|
}
|
|
|
|
gb->addComponent(pRender);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
|
|
|
(_pListener->*_pfnSelector)(pTmx, (void*)(&subDict));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-14 14:05:24 +08:00
|
|
|
else if(comName != nullptr && strcmp(comName, "CCParticleSystemQuad") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
std::string::size_type pos = pPath.find(".plist");
|
|
|
|
if (pos == pPath.npos)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
cocos2d::ParticleSystemQuad *pParticle = nullptr;
|
|
|
|
if (nResType == 0)
|
|
|
|
{
|
|
|
|
pParticle = ParticleSystemQuad::create(pPath.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("unknown resourcetype on CCParticleSystemQuad!");
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
pParticle->setPosition(0, 0);
|
2013-09-09 19:51:26 +08:00
|
|
|
ComRender *pRender = ComRender::create(pParticle, "CCParticleSystemQuad");
|
2013-11-14 14:05:24 +08:00
|
|
|
if (pComName != nullptr)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
pRender->setName(pComName);
|
|
|
|
}
|
|
|
|
gb->addComponent(pRender);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
|
|
|
(_pListener->*_pfnSelector)(pParticle, (void*)(&subDict));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-14 14:05:24 +08:00
|
|
|
else if(comName != nullptr && strcmp(comName, "CCArmature") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-15 09:45:03 +08:00
|
|
|
if (nResType != 0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
std::string reDir = pPath;
|
|
|
|
std::string file_path = "";
|
|
|
|
size_t pos = reDir.find_last_of('/');
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
|
|
|
file_path = reDir.substr(0, pos+1);
|
|
|
|
}
|
2013-12-24 18:08:40 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
rapidjson::Document jsonDict;
|
|
|
|
if(!readJson(pPath.c_str(), jsonDict))
|
2013-11-15 09:45:03 +08:00
|
|
|
{
|
2013-12-24 22:05:13 +08:00
|
|
|
log("read json file[%s] error!\n", pPath.c_str());
|
2013-12-24 20:33:55 +08:00
|
|
|
continue;
|
2013-11-15 09:45:03 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
|
|
|
|
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(jsonDict, "armature_data", 0);
|
2013-11-15 09:45:03 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(subData, "name");
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-25 19:46:09 +08:00
|
|
|
ArmatureDataManager::getInstance()->addArmatureFileInfo(pPath.c_str());
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
Armature *pAr = Armature::create(name);
|
|
|
|
ComRender *pRender = ComRender::create(pAr, "CCArmature");
|
|
|
|
if (pComName != nullptr)
|
|
|
|
{
|
|
|
|
pRender->setName(pComName);
|
|
|
|
}
|
|
|
|
gb->addComponent(pRender);
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *actionName = DICTOOL->getStringValue_json(subDict, "selectedactionname");
|
2013-11-15 09:45:03 +08:00
|
|
|
if (actionName != nullptr && pAr->getAnimation() != nullptr)
|
|
|
|
{
|
|
|
|
pAr->getAnimation()->play(actionName);
|
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
|
|
|
(_pListener->*_pfnSelector)(pAr, (void*)(&subDict));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-14 14:05:24 +08:00
|
|
|
else if(comName != nullptr && strcmp(comName, "CCComAudio") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-15 09:45:03 +08:00
|
|
|
ComAudio *pAudio = nullptr;
|
|
|
|
if (nResType == 0)
|
|
|
|
{
|
|
|
|
pAudio = ComAudio::create();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
pAudio->preloadEffect(pPath.c_str());
|
|
|
|
gb->addComponent(pAudio);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
|
|
|
(_pListener->*_pfnSelector)(pAudio, (void*)(&subDict));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-14 14:05:24 +08:00
|
|
|
else if(comName != nullptr && strcmp(comName, "CCComAttribute") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-14 14:05:24 +08:00
|
|
|
ComAttribute *pAttribute = nullptr;
|
2013-11-15 09:45:03 +08:00
|
|
|
if (nResType == 0)
|
|
|
|
{
|
|
|
|
pAttribute = ComAttribute::create();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCLOG("unknown resourcetype on CCComAttribute!");
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
gb->addComponent(pAttribute);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
|
|
|
(_pListener->*_pfnSelector)(pAttribute, (void*)(&subDict));
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-14 14:05:24 +08:00
|
|
|
else if (comName != nullptr && strcmp(comName, "CCBackgroundAudio") == 0)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-11-15 09:45:03 +08:00
|
|
|
ComAudio *pAudio = nullptr;
|
|
|
|
if (nResType == 0)
|
|
|
|
{
|
|
|
|
pAudio = ComAudio::create();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
pAudio->preloadBackgroundMusic(pPath.c_str());
|
2013-11-15 09:45:03 +08:00
|
|
|
pAudio->setFile(pPath.c_str());
|
2013-12-24 20:33:55 +08:00
|
|
|
const bool bLoop = (DICTOOL->getIntValue_json(subDict, "loop") != 0);
|
2013-11-15 09:45:03 +08:00
|
|
|
pAudio->setLoop(bLoop);
|
2013-09-09 19:51:26 +08:00
|
|
|
gb->addComponent(pAudio);
|
2013-11-15 09:45:03 +08:00
|
|
|
pAudio->playBackgroundMusic(pPath.c_str(), bLoop);
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
2013-11-15 09:45:03 +08:00
|
|
|
else if(comName != nullptr && strcmp(comName, "GUIComponent") == 0)
|
|
|
|
{
|
2013-12-23 15:02:52 +08:00
|
|
|
Widget* widget= GUIReader::shareReader()->widgetFromJsonFile(pPath.c_str());
|
|
|
|
ComRender *pRender = ComRender::create(widget, "GUIComponent");
|
2013-11-15 09:45:03 +08:00
|
|
|
if (pComName != nullptr)
|
|
|
|
{
|
|
|
|
pRender->setName(pComName);
|
|
|
|
}
|
|
|
|
gb->addComponent(pRender);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (_pListener && _pfnSelector)
|
|
|
|
{
|
2013-12-26 12:55:52 +08:00
|
|
|
(_pListener->*_pfnSelector)(widget, (void*)(&subDict));
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(dict, "gameobjects");
|
|
|
|
for (int i = 0; i < length; ++i)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "gameobjects", i);
|
|
|
|
if (!DICTOOL->checkObjectExist_json(subDict))
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
createObject(subDict, gb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return gb;
|
|
|
|
}
|
|
|
|
|
2013-11-14 14:05:24 +08:00
|
|
|
return nullptr;
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
void SceneReader::setTarget(Object *rec, SEL_CallFuncOD selector)
|
|
|
|
{
|
|
|
|
_pListener = rec;
|
|
|
|
_pfnSelector = selector;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* SceneReader::getNodeByTag(int nTag)
|
|
|
|
{
|
|
|
|
if (_pNode == NULL)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (_pNode->getTag() == nTag)
|
|
|
|
{
|
|
|
|
return _pNode;
|
|
|
|
}
|
|
|
|
return nodeByTag(_pNode, nTag);
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-24 21:23:24 +08:00
|
|
|
void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d::Node *node)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
float x = DICTOOL->getFloatValue_json(root, "x");
|
|
|
|
float y = DICTOOL->getFloatValue_json(root, "y");
|
2013-11-15 09:45:03 +08:00
|
|
|
node->setPosition(Point(x, y));
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const bool bVisible = (DICTOOL->getIntValue_json(root, "visible", 1) != 0);
|
2013-11-15 09:45:03 +08:00
|
|
|
node->setVisible(bVisible);
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int nTag = DICTOOL->getIntValue_json(root, "objecttag", -1);
|
2013-09-09 19:51:26 +08:00
|
|
|
node->setTag(nTag);
|
2013-11-15 09:45:03 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int nZorder = DICTOOL->getIntValue_json(root, "zorder");
|
2013-11-15 09:45:03 +08:00
|
|
|
node->setZOrder(nZorder);
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float fScaleX = DICTOOL->getFloatValue_json(root, "scalex", 1.0);
|
|
|
|
float fScaleY = DICTOOL->getFloatValue_json(root, "scaley", 1.0);
|
2013-09-09 19:51:26 +08:00
|
|
|
node->setScaleX(fScaleX);
|
|
|
|
node->setScaleY(fScaleY);
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
float fRotationZ = DICTOOL->getFloatValue_json(root, "rotation");
|
2013-09-09 19:51:26 +08:00
|
|
|
node->setRotation(fRotationZ);
|
|
|
|
}
|
|
|
|
|
2013-11-15 09:45:03 +08:00
|
|
|
SceneReader* SceneReader::getInstance()
|
|
|
|
{
|
|
|
|
if (s_sharedReader == nullptr)
|
|
|
|
{
|
|
|
|
s_sharedReader = new SceneReader();
|
|
|
|
}
|
|
|
|
return s_sharedReader;
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
|
2013-12-27 20:54:05 +08:00
|
|
|
void SceneReader::destroyInstance()
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
2013-12-27 20:54:05 +08:00
|
|
|
DictionaryHelper::destroyInstance();
|
|
|
|
TriggerMng::destroyInstance();
|
2013-12-27 12:39:21 +08:00
|
|
|
CC_SAFE_DELETE(s_sharedReader);
|
2013-09-09 19:51:26 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|