2013-06-04 17:38:43 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-06-04 17:38:43 +08:00
|
|
|
|
|
|
|
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/CCComRender.h"
|
2014-01-05 02:22:32 +08:00
|
|
|
#include "cocostudio/CocoStudio.h"
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
2013-06-04 17:38:43 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocostudio {
|
2013-06-04 17:38:43 +08:00
|
|
|
|
2014-01-05 02:22:32 +08:00
|
|
|
IMPLEMENT_CLASS_COMPONENT_INFO(ComRender)
|
2013-09-09 19:51:26 +08:00
|
|
|
ComRender::ComRender(void)
|
2013-11-14 14:05:24 +08:00
|
|
|
: _render(nullptr)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-01-03 19:30:47 +08:00
|
|
|
_name = "CCComRender";
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
ComRender::ComRender(cocos2d::Node *node, const char *comName)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-03-26 16:39:32 +08:00
|
|
|
if (node != nullptr)
|
|
|
|
{
|
|
|
|
_render = node;
|
|
|
|
_render->retain();
|
|
|
|
}
|
2013-09-09 19:51:26 +08:00
|
|
|
_name.assign(comName);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
ComRender::~ComRender(void)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-03-26 16:39:32 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_render);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
void ComRender::onEnter()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-01-03 19:30:47 +08:00
|
|
|
if (_owner != nullptr)
|
2013-09-09 19:51:26 +08:00
|
|
|
{
|
|
|
|
_owner->addChild(_render);
|
|
|
|
}
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
void ComRender::onExit()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-03-26 16:39:32 +08:00
|
|
|
if (_owner != nullptr)
|
|
|
|
{
|
|
|
|
_owner->removeChild(_render, true);
|
|
|
|
}
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2013-09-09 19:51:26 +08:00
|
|
|
cocos2d::Node* ComRender::getNode()
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2013-09-09 19:51:26 +08:00
|
|
|
return _render;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
void ComRender::setNode(cocos2d::Node *node)
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-03-26 16:39:32 +08:00
|
|
|
if (_render != nullptr)
|
|
|
|
{
|
|
|
|
_render->release();
|
|
|
|
_render = nullptr;
|
|
|
|
}
|
|
|
|
if (node != nullptr)
|
|
|
|
{
|
|
|
|
_render = node;
|
|
|
|
_render->retain();
|
|
|
|
}
|
2014-01-03 01:42:14 +08:00
|
|
|
}
|
|
|
|
|
2014-01-05 02:22:32 +08:00
|
|
|
|
|
|
|
bool ComRender::serialize(void* r)
|
2014-01-03 01:42:14 +08:00
|
|
|
{
|
2014-06-30 17:15:55 +08:00
|
|
|
bool ret = false;
|
2014-06-25 11:58:36 +08:00
|
|
|
do
|
|
|
|
{
|
2014-06-30 17:15:55 +08:00
|
|
|
CC_BREAK_IF(r == nullptr);
|
2014-06-25 18:10:06 +08:00
|
|
|
SerData *serData = (SerData *)(r);
|
|
|
|
const rapidjson::Value *v = serData->_rData;
|
|
|
|
stExpCocoNode *cocoNode = serData->_cocoNode;
|
2014-06-30 17:15:55 +08:00
|
|
|
const char *className = nullptr;
|
|
|
|
const char *comName = nullptr;
|
|
|
|
const char *file = nullptr;
|
|
|
|
const char *plist = nullptr;
|
2014-06-25 18:10:06 +08:00
|
|
|
std::string filePath;
|
|
|
|
std::string plistPath;
|
|
|
|
int resType = 0;
|
2014-06-30 17:15:55 +08:00
|
|
|
if (v != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
className = DICTOOL->getStringValue_json(*v, "classname");
|
2014-06-30 17:15:55 +08:00
|
|
|
CC_BREAK_IF(className == nullptr);
|
2014-06-25 18:10:06 +08:00
|
|
|
comName = DICTOOL->getStringValue_json(*v, "name");
|
2014-06-25 11:58:36 +08:00
|
|
|
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
|
|
|
|
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
|
2014-06-25 18:10:06 +08:00
|
|
|
file = DICTOOL->getStringValue_json(fileData, "path");
|
|
|
|
plist = DICTOOL->getStringValue_json(fileData, "plistFile");
|
2014-06-30 17:15:55 +08:00
|
|
|
CC_BREAK_IF(file == nullptr && plist == nullptr);
|
2014-06-25 18:10:06 +08:00
|
|
|
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
else if(cocoNode != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
className = cocoNode[1].GetValue();
|
2014-06-30 17:15:55 +08:00
|
|
|
CC_BREAK_IF(className == nullptr);
|
2014-06-25 18:10:06 +08:00
|
|
|
comName = cocoNode[2].GetValue();
|
|
|
|
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
|
2014-06-25 11:58:36 +08:00
|
|
|
CC_BREAK_IF(!pfileData);
|
2014-06-25 18:10:06 +08:00
|
|
|
file = pfileData[0].GetValue();
|
|
|
|
plist = pfileData[1].GetValue();
|
2014-06-30 17:15:55 +08:00
|
|
|
CC_BREAK_IF(file == nullptr && plist == nullptr);
|
2014-06-25 18:10:06 +08:00
|
|
|
resType = atoi(pfileData[2].GetValue());
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
if (comName != nullptr)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
setName(comName);
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
setName(className);
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 11:58:36 +08:00
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
if (file != nullptr)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
if (plist != nullptr)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
plistPath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(plist));
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 18:10:06 +08:00
|
|
|
if (resType == 0)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
if (strcmp(className, "CCSprite") == 0 && (filePath.find(".png") != filePath.npos || filePath.find(".pvr.ccz") != filePath.npos))
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
_render = CCSprite::create(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
_render->retain();
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 18:10:06 +08:00
|
|
|
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != filePath.npos)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
_render = CCTMXTiledMap::create(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
_render->retain();
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 18:10:06 +08:00
|
|
|
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != filePath.npos)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
_render = CCParticleSystemQuad::create(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
_render->setPosition(Point(0.0f, 0.0f));
|
|
|
|
_render->retain();
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 18:10:06 +08:00
|
|
|
else if(strcmp(className, "CCArmature") == 0)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
std::string file_extension = filePath;
|
|
|
|
size_t pos = filePath.find_last_of('.');
|
2014-01-05 02:22:32 +08:00
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
file_extension = filePath.substr(pos, filePath.length());
|
2014-06-25 11:58:36 +08:00
|
|
|
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 11:58:36 +08:00
|
|
|
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 11:58:36 +08:00
|
|
|
rapidjson::Document doc;
|
2014-06-25 18:10:06 +08:00
|
|
|
if(!readJson(filePath.c_str(), doc))
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
log("read json file[%s] error!\n", filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
|
|
|
|
const char *name = DICTOOL->getStringValue_json(subData, "name");
|
2014-06-25 18:10:06 +08:00
|
|
|
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
Armature *pAr = Armature::create(name);
|
|
|
|
_render = pAr;
|
|
|
|
_render->retain();
|
2014-06-30 17:15:55 +08:00
|
|
|
const char *actionName = nullptr;
|
|
|
|
if (cocoNode != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
actionName = cocoNode[6].GetValue();//DICTOOL->getStringValue_json(*v, "selectedactionname");
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
|
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
if (actionName != nullptr && pAr->getAnimation() != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
|
|
|
pAr->getAnimation()->play(actionName);
|
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 11:58:36 +08:00
|
|
|
else if (file_extension == ".CSB")
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 11:58:36 +08:00
|
|
|
ssize_t size = 0;
|
2014-06-30 17:15:55 +08:00
|
|
|
unsigned char *pBytes = nullptr;
|
2014-06-25 18:10:06 +08:00
|
|
|
std::string binaryFilePath = FileUtils::getInstance()->fullPathForFilename(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
|
2014-06-30 17:15:55 +08:00
|
|
|
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
|
2014-06-25 11:58:36 +08:00
|
|
|
CocoLoader tCocoLoader;
|
|
|
|
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
|
|
|
|
{
|
|
|
|
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
|
|
|
|
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
|
|
|
|
if (rapidjson::kObjectType == tType)
|
|
|
|
{
|
|
|
|
int count = tpRootCocoNode->GetChildNum();
|
|
|
|
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
std::string key = tpChildArray[i].GetName(&tCocoLoader);
|
|
|
|
if (key.compare("armature_data") == 0)
|
|
|
|
{
|
|
|
|
int length = tpChildArray[i].GetChildNum();
|
|
|
|
stExpCocoNode *armature_dataArray = tpChildArray[i].GetChildArray();
|
|
|
|
if (length < 1)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
length = armature_dataArray[0].GetChildNum();
|
|
|
|
stExpCocoNode *armature_data = armature_dataArray[0].GetChildArray();
|
|
|
|
for (int j = 0; j < length; ++j)
|
|
|
|
{
|
|
|
|
std::string key1 = armature_data[j].GetName(&tCocoLoader);
|
|
|
|
const char *str1 = armature_data[j].GetValue();
|
|
|
|
if (key.compare("name") == 0)
|
|
|
|
{
|
2014-06-30 17:15:55 +08:00
|
|
|
if (str1 != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
Armature *pAr = CCArmature::create(str1);
|
|
|
|
_render = pAr;
|
|
|
|
_render->retain();
|
2014-06-30 17:15:55 +08:00
|
|
|
const char *actionName = nullptr;
|
|
|
|
if (cocoNode != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
actionName = cocoNode[6].GetValue();
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
|
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
if (actionName != nullptr && pAr->getAnimation() != nullptr)
|
2014-06-25 11:58:36 +08:00
|
|
|
{
|
|
|
|
pAr->getAnimation()->play(actionName);
|
|
|
|
}
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 11:58:36 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
2014-06-25 18:10:06 +08:00
|
|
|
else if(strcmp(className, "GUIComponent") == 0)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
std::string file_extension = filePath;
|
|
|
|
size_t pos = filePath.find_last_of('.');
|
2014-06-25 11:58:36 +08:00
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
file_extension = filePath.substr(pos, filePath.length());
|
2014-06-25 11:58:36 +08:00
|
|
|
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
|
|
|
|
}
|
|
|
|
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
|
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
_render = widget;
|
|
|
|
_render->retain();
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
|
|
|
else if (file_extension == ".CSB")
|
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromBinaryFile(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
_render = widget;
|
|
|
|
_render->retain();
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-06-25 11:58:36 +08:00
|
|
|
}
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_BREAK_IF(true);
|
|
|
|
}
|
|
|
|
}
|
2014-06-25 18:10:06 +08:00
|
|
|
else if (resType == 1)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
if (strcmp(className, "CCSprite") == 0)
|
2014-01-05 02:22:32 +08:00
|
|
|
{
|
2014-06-25 18:10:06 +08:00
|
|
|
std::string strPngFile = plistPath;
|
2014-01-05 02:22:32 +08:00
|
|
|
std::string::size_type pos = strPngFile.find(".plist");
|
|
|
|
if (pos == strPngFile.npos)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
strPngFile.replace(pos, strPngFile.length(), ".png");
|
2014-06-25 18:10:06 +08:00
|
|
|
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath.c_str(), strPngFile.c_str());
|
|
|
|
_render = CCSprite::createWithSpriteFrameName(filePath.c_str());
|
2014-06-25 11:58:36 +08:00
|
|
|
_render->retain();
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
ret = true;
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_BREAK_IF(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_BREAK_IF(true);
|
|
|
|
}
|
2014-06-25 11:58:36 +08:00
|
|
|
} while (0);
|
|
|
|
|
2014-06-30 17:15:55 +08:00
|
|
|
return ret;
|
2014-01-05 02:22:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ComRender* ComRender::create(void)
|
|
|
|
{
|
|
|
|
ComRender * ret = new ComRender();
|
2014-01-03 19:30:47 +08:00
|
|
|
if (ret != nullptr && ret->init())
|
2013-06-04 17:38:43 +08:00
|
|
|
{
|
2014-01-03 01:42:14 +08:00
|
|
|
ret->autorelease();
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-03 01:42:14 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
2014-01-03 01:42:14 +08:00
|
|
|
return ret;
|
2013-06-04 17:38:43 +08:00
|
|
|
}
|
|
|
|
|
2014-01-05 03:11:32 +08:00
|
|
|
ComRender* ComRender::create(cocos2d::Node *node, const char *comName)
|
|
|
|
{
|
|
|
|
ComRender * ret = new ComRender(node, comName);
|
|
|
|
if (ret != nullptr && ret->init())
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(ret);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-05 02:22:32 +08:00
|
|
|
bool ComRender::readJson(const std::string &fileName, rapidjson::Document &doc)
|
|
|
|
{
|
|
|
|
bool ret = false;
|
|
|
|
do {
|
|
|
|
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fileName);
|
|
|
|
doc.Parse<0>(contentStr.c_str());
|
|
|
|
CC_BREAK_IF(doc.HasParseError());
|
|
|
|
ret = true;
|
|
|
|
} while (0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|