Merge pull request #7201 from chengstory/cleanupBinaryLoader_AddSceneBinaryParse

Cleanup binary loader add scene binary parse
This commit is contained in:
minggo 2014-07-01 13:47:35 +08:00
commit 80204e3048
17 changed files with 1777 additions and 199 deletions

View File

@ -144,14 +144,42 @@ ComAttribute* ComAttribute::create(void)
bool ComAttribute::serialize(void* r)
{
bool bRet = false;
do
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *fileData = cocoNode[3].GetChildArray();
CC_BREAK_IF(!fileData);
file = fileData[0].GetValue();
CC_BREAK_IF(file == nullptr);
resType = atoi(fileData[2].GetValue());
CC_BREAK_IF(resType != 0);
}
if (comName != nullptr)
{
setName(comName);
@ -160,22 +188,17 @@ bool ComAttribute::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr)
{
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
parse(filePath.c_str());
bRet = true;
} while (0);
return bRet;
if (parse(filePath.c_str()))
{
ret = true;
}
}while (0);
return ret;
}
bool ComAttribute::parse(const std::string &jsonFile)

View File

@ -69,14 +69,46 @@ void ComAudio::setEnabled(bool b)
bool ComAudio::serialize(void* r)
{
bool bRet = false;
do
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
std::string filePath;
int resType = 0;
bool loop = false;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
}
else if (cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue();
CC_BREAK_IF(file == nullptr);
resType = atoi(pfileData[2].GetValue());
CC_BREAK_IF(resType != 0);
loop = atoi(cocoNode[5].GetValue()) != 0? true:false;
ret = true;
}
if (comName != nullptr)
{
setName(comName);
@ -85,17 +117,14 @@ bool ComAudio::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
CC_BREAK_IF(file == nullptr);
std::string filePath;
if (file != nullptr)
{
if (strcmp(file, "") == 0)
{
continue;
}
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
CC_BREAK_IF(resType != 0);
if (strcmp(className, "CCBackgroundAudio") == 0)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
@ -108,9 +137,8 @@ bool ComAudio::serialize(void* r)
filePath.replace(pos, filePath.length(), ".wav");
#endif
preloadBackgroundMusic(filePath.c_str());
bool loop = DICTOOL->getIntValue_json(*v, "loop") != 0? true:false;
setLoop(loop);
playBackgroundMusic(filePath.c_str(), loop);
playBackgroundMusic(filePath.c_str(), loop);
}
else if(strcmp(className, "CCComAudio") == 0)
{
@ -120,10 +148,9 @@ bool ComAudio::serialize(void* r)
{
CC_BREAK_IF(true);
}
bRet = true;
} while (0);
return bRet;
ret = true;
}while (0);
return ret;
}
ComAudio* ComAudio::create(void)

View File

@ -28,6 +28,7 @@ THE SOFTWARE.
#include <string>
#include "DictionaryHelper.h"
#include "base/ObjectFactory.h"
#include "CocoLoader.h"
#define DECLARE_CLASS_COMPONENT_INFO \
@ -45,5 +46,16 @@ THE SOFTWARE.
#define CREATE_CLASS_COMPONENT_INFO(className) \
cocos2d::ObjectFactory::TInfo(#className, &className::createInstance)
struct SerData
{
const rapidjson::Value *_rData;
cocostudio::stExpCocoNode *_cocoNode;
SerData()
{
_rData = NULL;
_cocoNode = NULL;
}
};
#endif

View File

@ -90,14 +90,44 @@ void ComRender::setNode(cocos2d::Node *node)
bool ComRender::serialize(void* r)
{
bool bRet = false;
do
{
CC_BREAK_IF(r == nullptr);
rapidjson::Value *v = (rapidjson::Value *)r;
const char *className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
const char *comName = DICTOOL->getStringValue_json(*v, "name");
bool ret = false;
do
{
CC_BREAK_IF(r == nullptr);
SerData *serData = (SerData *)(r);
const rapidjson::Value *v = serData->_rData;
stExpCocoNode *cocoNode = serData->_cocoNode;
const char *className = nullptr;
const char *comName = nullptr;
const char *file = nullptr;
const char *plist = nullptr;
std::string filePath;
std::string plistPath;
int resType = 0;
if (v != nullptr)
{
className = DICTOOL->getStringValue_json(*v, "classname");
CC_BREAK_IF(className == nullptr);
comName = DICTOOL->getStringValue_json(*v, "name");
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
file = DICTOOL->getStringValue_json(fileData, "path");
plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
}
else if(cocoNode != nullptr)
{
className = cocoNode[1].GetValue();
CC_BREAK_IF(className == nullptr);
comName = cocoNode[2].GetValue();
stExpCocoNode *pfileData = cocoNode[4].GetChildArray();
CC_BREAK_IF(!pfileData);
file = pfileData[0].GetValue();
plist = pfileData[1].GetValue();
CC_BREAK_IF(file == nullptr && plist == nullptr);
resType = atoi(pfileData[2].GetValue());
}
if (comName != nullptr)
{
setName(comName);
@ -106,72 +136,175 @@ bool ComRender::serialize(void* r)
{
setName(className);
}
const rapidjson::Value &fileData = DICTOOL->getSubDictionary_json(*v, "fileData");
CC_BREAK_IF(!DICTOOL->checkObjectExist_json(fileData));
const char *file = DICTOOL->getStringValue_json(fileData, "path");
const char *plist = DICTOOL->getStringValue_json(fileData, "plistFile");
CC_BREAK_IF(file == nullptr && plist == nullptr);
std::string filePath;
std::string plistPath;
if (file != nullptr)
{
filePath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(file));
filePath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(file));
}
if (plist != nullptr)
{
plistPath.assign(cocos2d::CCFileUtils::getInstance()->fullPathForFilename(plist));
plistPath.assign(cocos2d::FileUtils::getInstance()->fullPathForFilename(plist));
}
int resType = DICTOOL->getIntValue_json(fileData, "resourceType", -1);
if (resType == 0)
{
if (strcmp(className, "CCSprite") == 0 && filePath.find(".png") != std::string::npos)
if (strcmp(className, "CCSprite") == 0 && (filePath.find(".png") != filePath.npos || filePath.find(".pvr.ccz") != filePath.npos))
{
_render = Sprite::create(filePath.c_str());
_render->retain();
_render = CCSprite::create(filePath.c_str());
_render->retain();
ret = true;
}
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != std::string::npos)
else if(strcmp(className, "CCTMXTiledMap") == 0 && filePath.find(".tmx") != filePath.npos)
{
_render = TMXTiledMap::create(filePath.c_str());
_render->retain();
_render = CCTMXTiledMap::create(filePath.c_str());
_render->retain();
ret = true;
}
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != std::string::npos)
else if(strcmp(className, "CCParticleSystemQuad") == 0 && filePath.find(".plist") != filePath.npos)
{
_render = ParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Vec2(0.0f, 0.0f));
_render->retain();
_render = CCParticleSystemQuad::create(filePath.c_str());
_render->setPosition(Point(0.0f, 0.0f));
_render->retain();
ret = true;
}
else if(strcmp(className, "CCArmature") == 0)
{
std::string reDir = filePath;
std::string file_path = "";
size_t pos = reDir.find_last_of('/');
std::string file_extension = filePath;
size_t pos = filePath.find_last_of('.');
if (pos != std::string::npos)
{
file_path = reDir.substr(0, pos+1);
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
rapidjson::Document doc;
if(!readJson(filePath.c_str(), doc))
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
rapidjson::Document doc;
if(!readJson(filePath.c_str(), doc))
{
log("read json file[%s] error!\n", filePath.c_str());
continue;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue();//DICTOOL->getStringValue_json(*v, "selectedactionname");
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
const rapidjson::Value &subData = DICTOOL->getDictionaryFromArray_json(doc, "armature_data", 0);
const char *name = DICTOOL->getStringValue_json(subData, "name");
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = Armature::create(name);
_render = pAr;
_render->retain();
const char *actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
if (actionName != nullptr && pAr->getAnimation() != nullptr)
else if (file_extension == ".CSB")
{
pAr->getAnimation()->play(actionName);
ssize_t size = 0;
unsigned char *pBytes = nullptr;
std::string binaryFilePath = FileUtils::getInstance()->fullPathForFilename(filePath.c_str());
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
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)
{
if (str1 != nullptr)
{
ArmatureDataManager::getInstance()->addArmatureFileInfo(filePath.c_str());
Armature *pAr = CCArmature::create(str1);
_render = pAr;
_render->retain();
const char *actionName = nullptr;
if (cocoNode != nullptr)
{
actionName = cocoNode[6].GetValue();
}
else
{
actionName = DICTOOL->getStringValue_json(*v, "selectedactionname");
}
if (actionName != nullptr && pAr->getAnimation() != nullptr)
{
pAr->getAnimation()->play(actionName);
}
ret = true;
}
}
}
}
}
}
}
else
{
continue;
}
}
else
{
continue;
}
}
else if(strcmp(className, "GUIComponent") == 0)
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
std::string file_extension = filePath;
size_t pos = filePath.find_last_of('.');
if (pos != std::string::npos)
{
file_extension = filePath.substr(pos, filePath.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON" || file_extension == ".EXPORTJSON")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromJsonFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
else if (file_extension == ".CSB")
{
cocos2d::ui::Widget* widget = GUIReader::getInstance()->widgetFromBinaryFile(filePath.c_str());
_render = widget;
_render->retain();
ret = true;
}
}
else
{
@ -190,8 +323,10 @@ bool ComRender::serialize(void* r)
}
strPngFile.replace(pos, strPngFile.length(), ".png");
SpriteFrameCache::getInstance()->addSpriteFramesWithFile(plistPath.c_str(), strPngFile.c_str());
_render = Sprite::createWithSpriteFrameName(filePath.c_str());
_render->retain();
_render = CCSprite::createWithSpriteFrameName(filePath.c_str());
_render->retain();
ret = true;
}
else
{
@ -202,10 +337,9 @@ bool ComRender::serialize(void* r)
{
CC_BREAK_IF(true);
}
bRet = true;
} while (0);
return bRet;
} while (0);
return ret;
}
ComRender* ComRender::create(void)

View File

@ -56,28 +56,133 @@ const char* SceneReader::sceneReaderVersion()
cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName, AttachComponentType attachComponent /*= AttachComponentType::EMPTY_NODE*/)
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
std::string reDir = fileName;
std::string file_extension = "";
size_t pos = reDir.find_last_of('.');
if (pos != std::string::npos)
{
file_extension = reDir.substr(pos, reDir.length());
std::transform(file_extension.begin(),file_extension.end(), file_extension.begin(), (int(*)(int))toupper);
}
if (file_extension == ".JSON")
{
_node = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, nullptr, attachComponent);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _node;
}
else if(file_extension == ".CSB")
{
ssize_t size = 0;
unsigned char *pBytes = nullptr;
do {
std::string binaryFilePath = CCFileUtils::getInstance()->fullPathForFilename(fileName);
pBytes = cocos2d::FileUtils::getInstance()->getFileData(binaryFilePath.c_str(), "rb", &size);
CC_BREAK_IF(pBytes == nullptr || strcmp((char*)pBytes, "") == 0);
CocoLoader tCocoLoader;
if (tCocoLoader.ReadCocoBinBuff((char*)pBytes))
{
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
if (rapidjson::kObjectType == tType)
{
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray();
CC_BREAK_IF(tpRootCocoNode->GetChildNum() == 0);
_node = Node::create();
int nCount = 0;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
std::string key = tpChildArray[15].GetName(&tCocoLoader);
if (key == "components")
{
nCount = tpChildArray[15].GetChildNum();
}
stExpCocoNode *pComponents = tpChildArray[15].GetChildArray();
SerData *data = new SerData();
for (int i = 0; i < nCount; i++)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray();
if (subDict == nullptr)
{
continue;
}
std::string key = subDict[1].GetName(&tCocoLoader);
const char *comName = subDict[1].GetValue();
Component *pCom = nullptr;
if (key == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
setPropertyFromJsonDict(&tCocoLoader, tpRootCocoNode, _node);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
_node->addComponent(*iter);
}
stExpCocoNode *pGameObjects = tpChildArray[11].GetChildArray();
int length = tpChildArray[11].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(&tCocoLoader, &pGameObjects[i], _node, attachComponent);
}
TriggerMng::getInstance()->parse(&tCocoLoader, tpChildArray);
}
}
}while (0);
return _node;
}
else
{
log("read file [%s] error!\n", fileName.c_str());
}
return nullptr;
}
bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool bRet = false;
bool ret = false;
do {
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
bRet = true;
ret = true;
} while (0);
return bRet;
return ret;
}
Node* SceneReader::nodeByTag(Node *parent, int tag)
@ -172,9 +277,13 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
Component *com = this->createComponent(comName);
CCLOG("classname = %s", comName);
SerData *data = new SerData();
if (com != nullptr)
{
if (com->serialize((void*)(&subDict)))
data->_rData = &subDict;
data->_cocoNode = nullptr;
if (com->serialize(data))
{
ComRender *tRender = dynamic_cast<ComRender*>(com);
if (tRender == nullptr)
@ -187,9 +296,10 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
}
}
CC_SAFE_DELETE(data);
if(_fnSelector != nullptr)
{
_fnSelector(com, (void*)(&subDict));
_fnSelector(com, data);
}
}
@ -234,6 +344,111 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
return nullptr;
}
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent)
{
const char *className = nullptr;
stExpCocoNode *pNodeArray = cocoNode->GetChildArray();
std::string Key = pNodeArray[1].GetName(cocoLoader);
if (Key == "classname")
{
className = pNodeArray[1].GetValue();
}
if(strcmp(className, "CCNode") == 0)
{
Node* gb = nullptr;
std::vector<Component*> _vecComs;
ComRender *pRender = nullptr;
int count = 0;
std::string key = pNodeArray[13].GetName(cocoLoader);
if (key == "components")
{
count = pNodeArray[13].GetChildNum();
}
stExpCocoNode *pComponents = pNodeArray[13].GetChildArray();
SerData *data = new SerData();
for (int i = 0; i < count; ++i)
{
stExpCocoNode *subDict = pComponents[i].GetChildArray();
if (subDict == nullptr)
{
continue;
}
std::string key = subDict[1].GetName(cocoLoader);
const char *comName = subDict[1].GetValue();//DICTOOL->getStringValue_json(subDict, "classname");
Component *pCom = nullptr;
if (key == "classname" && comName != nullptr)
{
pCom = createComponent(comName);
}
CCLOG("classname = %s", comName);
if (pCom != nullptr)
{
data->_rData = nullptr;
data->_cocoNode = subDict;
if (pCom->serialize(data))
{
ComRender *pTRender = dynamic_cast<ComRender*>(pCom);
if (pTRender != nullptr)
{
pRender = pTRender;
}
else
{
_vecComs.push_back(pCom);
}
}
else
{
CC_SAFE_RELEASE_NULL(pCom);
}
}
if(_fnSelector != nullptr)
{
_fnSelector(pCom, (void*)(data));
}
}
CC_SAFE_DELETE(data);
if (parent != nullptr)
{
if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE)
{
gb = CCNode::create();
if (pRender != nullptr)
{
_vecComs.push_back(pRender);
}
}
else
{
gb = pRender->getNode();
gb->retain();
pRender->setNode(nullptr);
CC_SAFE_RELEASE_NULL(pRender);
}
parent->addChild(gb);
}
setPropertyFromJsonDict(cocoLoader, cocoNode, gb);
for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter)
{
gb->addComponent(*iter);
}
stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray();
if (pGameObjects != nullptr)
{
int length = pNodeArray[12].GetChildNum();
for (int i = 0; i < length; ++i)
{
createObject(cocoLoader, &pGameObjects[i], gb, attachComponent);
}
}
return gb;
}
return nullptr;
}
void SceneReader::setTarget(const std::function<void(cocos2d::Ref* obj, void* doc)>& selector)
{
@ -276,6 +491,62 @@ void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d:
float fRotationZ = DICTOOL->getFloatValue_json(root, "rotation");
node->setRotation(fRotationZ);
}
void SceneReader::setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node)
{
stExpCocoNode *stChildArray = cocoNode->GetChildArray();
float x = 0.0f, y = 0.0f, fScaleX = 1.0f, fScaleY = 1.0f, fRotationZ = 1.0f;
bool bVisible = false;
int nTag = 0, nZorder = -1;
for (int i = 0; i < cocoNode->GetChildNum(); ++i)
{
std::string key = stChildArray[i].GetName(cocoLoader);
std::string value = stChildArray[i].GetValue();
if (key == "x")
{
x = atof(value.c_str());
node->setPositionX(x);
}
else if (key == "y")
{
y = atof(value.c_str());
node->setPositionY(y);
}
else if (key == "visible")
{
bVisible = (bool)atoi(value.c_str());
node->setVisible(bVisible);
}
else if (key == "objecttag")
{
nTag = atoi(value.c_str());
node->setTag(nTag);
}
else if (key == "zorder")
{
nZorder = atoi(value.c_str());
node->setZOrder(nZorder);
}
else if(key == "scalex")
{
fScaleX = atof(value.c_str());
node->setScaleX(fScaleX);
}
else if(key == "scaley")
{
fScaleY = atof(value.c_str());
node->setScaleY(fScaleY);
}
else if(key == "rotation")
{
fRotationZ = atof(value.c_str());
node->setRotation(fRotationZ);
}
}
}
SceneReader* SceneReader::getInstance()
{

View File

@ -76,6 +76,10 @@ private:
cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(const rapidjson::Value& dict, cocos2d::Node *node);
bool readJson(const std::string &fileName, rapidjson::Document& doc);
cocos2d::Node* createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent);
void setPropertyFromJsonDict(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node *node);
cocos2d::Node* nodeByTag(cocos2d::Node *parent, int tag);
private:
static SceneReader* s_sharedReader;

View File

@ -96,8 +96,8 @@ public:
stExpCocoNode* GetChildArray();
public:
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
inline void ReBuild(char* cocoNodeAddr,char* pStringMemoryAddr);
void WriteJson(CocoLoader* pCoco, void* pFileName = NULL, int vLayer = 0, bool bEndNode = false, bool bParentNodeIsArray = false);
};

View File

@ -104,6 +104,44 @@ void TriggerMng::parse(const rapidjson::Value &root)
}
}
}
void TriggerMng::parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
CCLOG("%s", triggerMngVersion());
int count = pCocoNode[13].GetChildNum();
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray();
#if CC_ENABLE_SCRIPT_BINDING
ScriptEngineProtocol* engine = ScriptEngineManager::getInstance()->getScriptEngine();
bool useBindings = engine != NULL;
if (useBindings)
{
if (count > 0 )
{
rapidjson::Document document;
buildJson(document, pCocoLoader, pCocoNode);
rapidjson::StringBuffer buffer;
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
document.Accept(writer);
engine->parseConfig(ScriptEngineProtocol::ConfigType::COCOSTUDIO, buffer.GetString());
}
}
else
#endif // #if CC_ENABLE_SCRIPT_BINDING
{
for (int i = 0; i < count; ++i)
{
TriggerObj *obj = TriggerObj::create();
obj->serialize(pCocoLoader, &pTriggersArray[i]);
_triggerObjs.insert(std::pair<unsigned int, TriggerObj*>(obj->getId(), obj));
obj->retain();
}
}
}
TriggerObj* TriggerMng::getTriggerObj(unsigned int id) const
{
@ -152,6 +190,217 @@ bool TriggerMng::isEmpty(void) const
return _triggerObjs.empty();
}
void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int count = pCocoNode[13].GetChildNum();
int length = 0;
int num = 0;
int size = 0;
int extent = 0;
int border = 0;
std::string key;
stExpCocoNode *pTriggersArray = pCocoNode[13].GetChildArray();
document.SetArray();
rapidjson::Document::AllocatorType& allocator = document.GetAllocator();
for (int i = 0; i < count; ++i)
{
rapidjson::Value vElemItem(rapidjson::kObjectType);
border = pTriggersArray[i].GetChildNum();
stExpCocoNode *pTriggerArray = pTriggersArray[i].GetChildArray();
for (int i = 0; i < border; ++i)
{
std::string key = pTriggerArray[i].GetName(pCocoLoader);
const char *str = pTriggerArray[i].GetValue();
rapidjson::Type type = pTriggerArray[i].GetType(pCocoLoader);
if (key.compare("actions") == 0)
{
rapidjson::Value actionsItem(rapidjson::kArrayType);
length = pTriggerArray[i].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerArray[i].GetChildArray();
for (int i = 0; i < length; ++i)
{
rapidjson::Value action(rapidjson::kObjectType);
num = pActionsArray[i].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i].GetChildArray();
for (int i = 0; i < num; ++i)
{
std::string key = pActionArray[i].GetName(pCocoLoader);
const char *str = pActionArray[i].GetValue();
if (key.compare("classname") == 0)
{
if (str != NULL)
{
action.AddMember("classname", str, allocator);
}
}
else if (key.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pActionArray[i].GetChildNum();
stExpCocoNode *pDataItemsArray = pActionArray[i].GetChildArray();
for (int i = 0; i < size; ++i)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
for (int i = 0; i < extent; ++i)
{
std::string key = pDataItemArray[i].GetName(pCocoLoader);
const char *str = pDataItemArray[i].GetValue();
if (key.compare("key") == 0)
{
if (str != NULL)
{
dataitem.AddMember("key", str, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str);
float fV = atof(str);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
action.AddMember("dataitems", dataitems, allocator);
}
}
actionsItem.PushBack(action, allocator);
}
vElemItem.AddMember("actions", actionsItem, allocator);
}
else if (key.compare("conditions") == 0)
{
rapidjson::Value condsItem(rapidjson::kArrayType);
length = pTriggerArray[i].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerArray[i].GetChildArray();
for (int i = 0; i < length; ++i)
{
rapidjson::Value cond(rapidjson::kObjectType);
num = pConditionsArray[i].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i].GetChildArray();
for (int i = 0; i < num; ++i)
{
std::string key = pConditionArray[i].GetName(pCocoLoader);
const char *str = pConditionArray[i].GetValue();
if (key.compare("classname") == 0)
{
if (str != NULL)
{
cond.AddMember("classname", str, allocator);
}
}
else if (key.compare("dataitems") == 0)
{
rapidjson::Value dataitems(rapidjson::kArrayType);
size = pConditionArray[i].GetChildNum();
stExpCocoNode *pDataItemsArray = pConditionArray[i].GetChildArray();
for (int i = 0; i < size; ++i)
{
rapidjson::Value dataitem(rapidjson::kObjectType);
extent = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
for (int i = 0; i < extent; ++i)
{
std::string key = pDataItemArray[i].GetName(pCocoLoader);
const char *str = pDataItemArray[i].GetValue();
if (key.compare("key") == 0)
{
if (str != NULL)
{
dataitem.AddMember("key", str, allocator);
}
}
else
{
rapidjson::Type type = pDataItemArray[i].GetType(pCocoLoader);
if (type == rapidjson::kStringType)
{
dataitem.AddMember("value", str, allocator);
}
else if(type == rapidjson::kNumberType)
{
int nV = atoi(str);
float fV = atof(str);
if (fabs(nV - fV) < 0.0000001)
{
dataitem.AddMember("value", nV, allocator);
}
else
{
dataitem.AddMember("value", fV, allocator);
}
}
}
}
dataitems.PushBack(dataitem, allocator);
}
cond.AddMember("dataitems", dataitems, allocator);
}
}
condsItem.PushBack(cond, allocator);
}
vElemItem.AddMember("conditions", condsItem, allocator);
}
else if (key.compare("events") == 0)
{
rapidjson::Value eventsItem(rapidjson::kArrayType);
length = pTriggerArray[i].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerArray[i].GetChildArray();
for (int i = 0; i < length; ++i)
{
rapidjson::Value event(rapidjson::kObjectType);
stExpCocoNode *pEventArray = pEventsArray->GetChildArray();
std::string key = pEventArray[0].GetName(pCocoLoader);
const char *str = pEventArray[0].GetValue();
if (key.compare("id") == 0 && str != NULL)
{
event.AddMember("id", atoi(str), allocator);
eventsItem.PushBack(event, allocator);
}
}
vElemItem.AddMember("events", eventsItem, allocator);
}
else if (key.compare("id") == 0)
{
if (str != NULL)
{
vElemItem.AddMember("id", atoi(str), allocator);
}
}
}
document.PushBack(vElemItem, allocator);
}
}
void TriggerMng::addArmatureMovementCallBack(Armature *pAr, Ref *pTarget, SEL_MovementEventCallFunc mecf)
{
if (pAr == nullptr || _movementDispatches == nullptr || pTarget == nullptr || mecf == nullptr)

View File

@ -64,6 +64,7 @@ public:
public:
void parse(const rapidjson::Value &root);
void parse(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
void removeAll(void);
cocos2d::Vector<TriggerObj*>* get(unsigned int event) const;
TriggerObj* getTriggerObj(unsigned int id) const;
@ -78,6 +79,8 @@ public:
void dispatchEvent(cocos2d::EventCustom* tEvent);
void removeEventListener(cocos2d::EventListener* listener);
void addEventListenerWithFixedPriority(cocos2d::EventListener* listener, int fixedPriority);
private:
void buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
private:
static TriggerMng *_sharedTriggerMng;

View File

@ -48,6 +48,11 @@ bool BaseTriggerCondition::detect()
void BaseTriggerCondition::serialize(const rapidjson::Value &val)
{
}
void BaseTriggerCondition::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerCondition::removeAll()
{
@ -75,6 +80,10 @@ void BaseTriggerAction::serialize(const rapidjson::Value &val)
{
}
void BaseTriggerAction::serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode)
{
}
void BaseTriggerAction::removeAll()
{
}
@ -231,6 +240,102 @@ void TriggerObj::serialize(const rapidjson::Value &val)
}
}
void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
int num = 0;
stExpCocoNode *pTriggerObjArray = pCocoNode->GetChildArray();
for (int i = 0; i < length; ++i)
{
std::string key = pTriggerObjArray[i].GetName(pCocoLoader);
const char* str = pTriggerObjArray[i].GetValue();
if (key.compare("id") == 0)
{
if (str != NULL)
{
_id = atoi(str); //(unsigned int)(DICTOOL->getIntValue_json(val, "id"));
}
}
else if (key.compare("conditions") == 0)
{
count = pTriggerObjArray[i].GetChildNum();
stExpCocoNode *pConditionsArray = pTriggerObjArray[i].GetChildArray();
for (int i = 0; i < count; ++i)
{
num = pConditionsArray[i].GetChildNum();
stExpCocoNode *pConditionArray = pConditionsArray[i].GetChildArray();
const char *classname = pConditionArray[0].GetValue();
if (classname == NULL)
{
continue;
}
BaseTriggerCondition *con = dynamic_cast<BaseTriggerCondition*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(con != NULL, "class named classname can not implement!");
con->serialize(pCocoLoader, &pConditionArray[1]);
con->init();
_cons.pushBack(con);
}
}
else if (key.compare("actions") == 0)
{
count = pTriggerObjArray[i].GetChildNum();
stExpCocoNode *pActionsArray = pTriggerObjArray[i].GetChildArray();
for (int i = 0; i < count; ++i)
{
num = pActionsArray[i].GetChildNum();
stExpCocoNode *pActionArray = pActionsArray[i].GetChildArray();
const char *classname = pActionArray[0].GetValue();
if (classname == NULL)
{
continue;
}
BaseTriggerAction *act = dynamic_cast<BaseTriggerAction*>(ObjectFactory::getInstance()->createObject(classname));
CCAssert(act != NULL, "class named classname can not implement!");
act->serialize(pCocoLoader, &pActionArray[1]);
act->init();
_acts.pushBack(act);
}
}
else if (key.compare("events") == 0)
{
count = pTriggerObjArray[i].GetChildNum();
stExpCocoNode *pEventsArray = pTriggerObjArray[i].GetChildArray();
for (int i = 0; i < count; ++i)
{
num = pEventsArray[i].GetChildNum();
stExpCocoNode *pEventArray = pEventsArray[i].GetChildArray();
const char *str = pEventArray[0].GetValue();
if (str == NULL)
{
continue;
}
int event = atoi(str);
if (event < 0)
{
continue;
}
char* buf = new char[10];
sprintf(buf, "%d", event);
std::string custom_event_name(buf);
CC_SAFE_DELETE_ARRAY(buf);
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){
if (detect())
{
done();
}
});
_listeners.pushBack(listener);
TriggerMng::getInstance()->addEventListenerWithFixedPriority(listener, 1);
}
}
}
}
unsigned int TriggerObj::getId()
{
return _id;

View File

@ -44,6 +44,7 @@ public:
virtual bool init();
virtual bool detect();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
virtual void removeAll();
};
@ -56,6 +57,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
virtual void removeAll();
};
@ -72,6 +74,7 @@ public:
virtual void done();
virtual void removeAll();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *cocoLoader, cocostudio::stExpCocoNode *cocoNode);
unsigned int getId();
void setEnabled(bool enabled);

View File

@ -106,7 +106,7 @@ void SceneEditorTestScene::MainMenuCallback(Ref *pSender)
removeAllChildren();
}
const char* SceneEditorTestLayer::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"};
void SceneEditorTestLayer::onEnter()
{
CCLayer::onEnter();
@ -127,6 +127,13 @@ void SceneEditorTestLayer::onEnter()
addChild(l, 1, 10001);
l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
_isCsbLoad = false;
_loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12);
// #endif
MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestLayer::changeLoadTypeCallback, this));
Menu* loadtypemenu = CCMenu::create(itemlb, NULL);
loadtypemenu->setPosition(Point(VisibleRect::rightTop().x -50,VisibleRect::rightTop().y -20));
addChild(loadtypemenu,100);
// add menu
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) );
@ -199,6 +206,36 @@ void SceneEditorTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint3
Layer::draw(renderer, transform, flags);
}
void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender)
{
_isCsbLoad = !_isCsbLoad;
_loadtypelb->setString(_loadtypeStr[(int)_isCsbLoad]);
loadFileChangeHelper(_filePath);
if(_rootNode != NULL)
{
this->removeChild(_rootNode);
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return ;
}
defaultPlay();
this->addChild(_rootNode);
}
}
void SceneEditorTestLayer::loadFileChangeHelper(std::string& filePathName)
{
std::string::size_type n = filePathName.find_last_of(".");
if(n == std::string::npos)
return;
filePathName = filePathName.substr(0,n);
if(_isCsbLoad)
filePathName.append(".csb");
else
filePathName.append(".json");
}
LoadSceneEdtiorFileTest::LoadSceneEdtiorFileTest()
{
@ -238,12 +275,19 @@ void LoadSceneEdtiorFileTest::onExit()
cocos2d::Node* LoadSceneEdtiorFileTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/LoadSceneEdtiorFileTest/FishJoy2.json");
if (node == nullptr)
_filePath = "scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"; //default is json
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
return node;
defaultPlay();
return _rootNode;
}
void LoadSceneEdtiorFileTest::defaultPlay()
{
}
SpriteComponentTest::SpriteComponentTest()
@ -283,22 +327,29 @@ void SpriteComponentTest::onExit()
cocos2d::Node* SpriteComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/SpriteComponentTest/SpriteComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/SpriteComponentTest/SpriteComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
defaultPlay();
return _rootNode;
}
void SpriteComponentTest::defaultPlay()
{
ActionInterval* action1 = CCBlink::create(2, 10);
ActionInterval* action2 = CCBlink::create(2, 5);
ComRender *pSister1 = static_cast<ComRender*>(node->getChildByTag(10003)->getComponent("CCSprite"));
ComRender *pSister1 = static_cast<ComRender*>(_rootNode->getChildByTag(10003)->getComponent("CCSprite"));
pSister1->getNode()->runAction(action1);
ComRender *pSister2 = static_cast<ComRender*>(node->getChildByTag(10004)->getComponent("CCSprite"));
ComRender *pSister2 = static_cast<ComRender*>(_rootNode->getChildByTag(10004)->getComponent("CCSprite"));
pSister2->getNode()->runAction(action2);
return node;
}
ArmatureComponentTest::ArmatureComponentTest()
@ -338,22 +389,27 @@ void ArmatureComponentTest::onExit()
cocos2d::Node* ArmatureComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/ArmatureComponentTest/ArmatureComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
ComRender *pBlowFish = static_cast<ComRender*>(node->getChildByTag(10007)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
defaultPlay();
return _rootNode;
}
ComRender *pButterflyfish = static_cast<ComRender*>(node->getChildByTag(10008)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
void ArmatureComponentTest::defaultPlay()
{
ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10007)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10008)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
return node;
}
UIComponentTest::UIComponentTest()
: _node(nullptr)
{
}
@ -389,20 +445,15 @@ void UIComponentTest::onExit()
cocos2d::Node* UIComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/UIComponentTest/UIComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10025)->getComponent("GUIComponent"));
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
// button->addTouchEventListener(this, toucheventselector(UIComponentTest::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
return node;
defaultPlay();
return _rootNode;
}
void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
@ -411,10 +462,10 @@ void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
{
case ui::Widget::TouchEventType::BEGAN:
{
ComRender *pBlowFish = static_cast<ComRender*>(_node->getChildByTag(10010)->getComponent("CCArmature"));
ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10010)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
ComRender *pButterflyfish = static_cast<ComRender*>(_node->getChildByTag(10011)->getComponent("CCArmature"));
ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10011)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
}
break;
@ -423,6 +474,15 @@ void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
}
}
void UIComponentTest::defaultPlay()
{
ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10025)->getComponent("GUIComponent"));
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
}
TmxMapComponentTest::TmxMapComponentTest()
{
@ -460,24 +520,30 @@ void TmxMapComponentTest::onExit()
cocos2d::Node* TmxMapComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/TmxMapComponentTest/TmxMapComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
ComRender *tmxMap = static_cast<ComRender*>(node->getChildByTag(10015)->getComponent("CCTMXTiledMap"));
ActionInterval *actionTo = SkewTo::create(2, 0.f, 2.f);
ActionInterval *rotateTo = RotateTo::create(2, 61.0f);
ActionInterval *actionScaleTo = ScaleTo::create(2, -0.44f, 0.47f);
defaultPlay();
return _rootNode;
}
ActionInterval *actionScaleToBack = ScaleTo::create(2, 1.0f, 1.0f);
ActionInterval *rotateToBack = RotateTo::create(2, 0);
ActionInterval *actionToBack = SkewTo::create(2, 0, 0);
void TmxMapComponentTest::defaultPlay()
{
ComRender *tmxMap = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCTMXTiledMap"));
ActionInterval *actionTo = CCSkewTo::create(2, 0.f, 2.f);
ActionInterval *rotateTo = CCRotateTo::create(2, 61.0f);
ActionInterval *actionScaleTo = CCScaleTo::create(2, -0.44f, 0.47f);
tmxMap->getNode()->runAction(Sequence::create(actionTo, actionToBack, nullptr));
tmxMap->getNode()->runAction(Sequence::create(rotateTo, rotateToBack, nullptr));
tmxMap->getNode()->runAction(Sequence::create(actionScaleTo, actionScaleToBack, nullptr));
return node;
ActionInterval *actionScaleToBack = CCScaleTo::create(2, 1.0f, 1.0f);
ActionInterval *rotateToBack = CCRotateTo::create(2, 0);
ActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);
tmxMap->getNode()->runAction(CCSequence::create(actionTo, actionToBack, NULL));
tmxMap->getNode()->runAction(CCSequence::create(rotateTo, rotateToBack, NULL));
tmxMap->getNode()->runAction(CCSequence::create(actionScaleTo, actionScaleToBack, NULL));
}
ParticleComponentTest::ParticleComponentTest()
@ -516,22 +582,26 @@ void ParticleComponentTest::onExit()
cocos2d::Node* ParticleComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/ParticleComponentTest/ParticleComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
defaultPlay();
return _rootNode;
}
ComRender* Particle = static_cast<ComRender*>(node->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
ActionInterval* jump = JumpBy::create(5, Vec2(-500,0), 50, 4);
FiniteTimeAction* action = Sequence::create( jump, jump->reverse(), nullptr);
void ParticleComponentTest::defaultPlay()
{
ComRender* Particle = static_cast<ComRender*>(_rootNode->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
ActionInterval* jump = CCJumpBy::create(5, Point(-500,0), 50, 4);
FiniteTimeAction* action = CCSequence::create( jump, jump->reverse(), NULL);
Particle->getNode()->runAction(action);
return node;
}
EffectComponentTest::EffectComponentTest()
: _node(nullptr)
{
}
@ -567,16 +637,14 @@ void EffectComponentTest::onExit()
cocos2d::Node* EffectComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/EffectComponentTest/EffectComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10015)->getComponent("CCArmature"));
Armature *pAr = static_cast<Armature*>(render->getNode());
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
return node;
defaultPlay();
return _rootNode;
}
void EffectComponentTest::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
@ -587,12 +655,19 @@ void EffectComponentTest::animationEvent(Armature *armature, MovementEventType m
{
if (id.compare("Fire") == 0)
{
ComAudio *pAudio = static_cast<ComAudio*>(_node->getChildByTag(10015)->getComponent("CCComAudio"));
ComAudio *pAudio = static_cast<ComAudio*>(_rootNode->getChildByTag(10015)->getComponent("CCComAudio"));
pAudio->playEffect();
}
}
}
void EffectComponentTest::defaultPlay()
{
ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCArmature"));
Armature *pAr = static_cast<Armature*>(render->getNode());
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
BackgroundComponentTest::BackgroundComponentTest()
{
@ -629,20 +704,24 @@ void BackgroundComponentTest::onExit()
cocos2d::Node* BackgroundComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/BackgroundComponentTest/BackgroundComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/BackgroundComponentTest/BackgroundComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
defaultPlay();
return _rootNode;
}
ComAudio *Audio = static_cast<ComAudio*>(node->getComponent("CCBackgroundAudio"));
void BackgroundComponentTest::defaultPlay()
{
ComAudio *Audio = static_cast<ComAudio*>(_rootNode->getComponent("CCBackgroundAudio"));
Audio->playBackgroundMusic();
return node;
}
AttributeComponentTest::AttributeComponentTest()
: _node(nullptr)
{
}
@ -663,7 +742,7 @@ void AttributeComponentTest::onEnter()
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
initData();
defaultPlay();
this->addChild(root, 0, 1);
} while (0);
}
@ -682,8 +761,8 @@ bool AttributeComponentTest::initData()
bool bRet = false;
rapidjson::Document doc;
do {
CC_BREAK_IF(_node == nullptr);
ComAttribute *attribute = static_cast<ComAttribute*>(_node->getChildByTag(10015)->getComponent("CCComAttribute"));
CC_BREAK_IF(_rootNode == nullptr);
ComAttribute *attribute = static_cast<ComAttribute*>(_rootNode->getChildByTag(10015)->getComponent("CCComAttribute"));
CC_BREAK_IF(attribute == nullptr);
log("Name: %s, HP: %f, MP: %f", attribute->getString("name").c_str(), attribute->getFloat("maxHP"), attribute->getFloat("maxMP"));
@ -694,13 +773,18 @@ bool AttributeComponentTest::initData()
cocos2d::Node* AttributeComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/AttributeComponentTest/AttributeComponentTest.json");
if (node == nullptr)
_filePath = "scenetest/AttributeComponentTest/AttributeComponentTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
return node;
return _rootNode;
}
void AttributeComponentTest::defaultPlay()
{
initData();
}
TriggerTest::TriggerTest()
@ -783,12 +867,16 @@ void TriggerTest::gameLogic(float dt)
cocos2d::Node* TriggerTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TriggerTest/TriggerTest.json");
if (node == nullptr)
_filePath = "scenetest/TriggerTest/TriggerTest.json";
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
if (_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
return node;
defaultPlay();
return _rootNode;
}
void TriggerTest::defaultPlay()
{
}

View File

@ -49,6 +49,20 @@ protected:
MenuItemImage *restartItem;
MenuItemImage *nextItem;
MenuItemImage *backItem;
protected:
virtual void changeLoadTypeCallback(cocos2d::Ref *pSender);
virtual void defaultPlay() = 0; // must to be overrided
void loadFileChangeHelper(std::string& filePathName ); // switch json& csb
private:
bool _isCsbLoad; // default is false
cocos2d::Label* _loadtypelb;
static const char* _loadtypeStr[2];
protected:
cocos2d::Node* _rootNode;
std::string _filePath;
};
class LoadSceneEdtiorFileTest : public SceneEditorTestLayer
@ -61,6 +75,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
@ -75,6 +91,8 @@ public:
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
class ArmatureComponentTest : public SceneEditorTestLayer
@ -88,6 +106,8 @@ public:
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
class UIComponentTest : public SceneEditorTestLayer
@ -102,7 +122,7 @@ public:
cocos2d::Node* createGameScene();
void touchEvent(cocos2d::Ref *pSender, ui::Widget::TouchEventType type);
private:
cocos2d::Node* _node;
void defaultPlay();
};
class TmxMapComponentTest : public SceneEditorTestLayer
@ -115,6 +135,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
@ -128,6 +150,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
protected:
void defaultPlay();
};
class EffectComponentTest : public SceneEditorTestLayer
@ -142,7 +166,8 @@ public:
cocos2d::Node* createGameScene();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private:
cocos2d::Node* _node;
void defaultPlay();
};
class BackgroundComponentTest : public SceneEditorTestLayer
@ -155,6 +180,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
class AttributeComponentTest : public SceneEditorTestLayer
@ -168,8 +195,9 @@ public:
virtual void onExit() override;
bool initData();
cocos2d::Node* createGameScene();
private:
cocos2d::Node* _node;
void defaultPlay();
};
class TriggerTest : public SceneEditorTestLayer
@ -197,6 +225,8 @@ public:
private:
cocos2d::Node *_node;
cocos2d::EventListener* _touchListener;
private:
void defaultPlay();
};
#endif // __HELLOWORLD_SCENE_H__

View File

@ -65,6 +65,44 @@ void PlayMusic::serialize(const rapidjson::Value &val)
}
}
void PlayMusic::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "componentName")
{
if (str != NULL)
{
_comName = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "type")
{
if (str != NULL)
{
_type = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
}
}
void PlayMusic::removeAll()
{
}
@ -127,6 +165,50 @@ void TMoveTo::serialize(const rapidjson::Value &val)
}
}
void TMoveTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "x")
{
if (str != NULL)
{
_pos.x = atof(str);
}
}
else if (key == "y")
{
if (str != NULL)
{
_pos.y = atoi(str);
}
}
}
}
void TMoveTo::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -205,6 +287,57 @@ void TMoveBy::serialize(const rapidjson::Value &val)
}
}
void TMoveBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "x")
{
if (str != NULL)
{
_pos.x = atof(str);
}
}
else if (key == "y")
{
if (str != NULL)
{
_pos.y = atof(str);
}
}
else if (key == "IsReverse")
{
if (str != NULL)
{
_reverse = atoi(str)!=0?true:false; //DICTOOL->getIntValue_json(subDict, "value") != 0? true: false;
}
}
}
}
void TMoveBy::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -267,6 +400,43 @@ void TRotateTo::serialize(const rapidjson::Value &val)
}
}
void TRotateTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "DeltaAngle")
{
if (str != NULL)
{
_deltaAngle = atof(str);
}
}
}
}
void TRotateTo::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -343,6 +513,50 @@ void TRotateBy::serialize(const rapidjson::Value &val)
}
}
void TRotateBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "DeltaAngle")
{
if (str != NULL)
{
_deltaAngle = atof(str);
}
}
else if (key == "IsReverse")
{
if (str != NULL)
{
_reverse = atoi(str)!=0?true:false;
}
}
}
}
void TRotateBy::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -409,6 +623,50 @@ void TScaleTo::serialize(const rapidjson::Value &val)
}
}
void TScaleTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "ScaleX")
{
if (str != NULL)
{
_scale.x = atof(str);
}
}
else if (key == "ScaleY")
{
if (str != NULL)
{
_scale.y = atof(str);
}
}
}
}
void TScaleTo::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -489,6 +747,58 @@ void TScaleBy::serialize(const rapidjson::Value &val)
}
}
void TScaleBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "ScaleX")
{
if (str != NULL)
{
_scale.x = atof(str);
}
}
else if (key == "ScaleY")
{
if (str != NULL)
{
_scale.y = atof(str);
}
}
else if (key == "IsReverse")
{
if (str != NULL)
{
_reverse = atoi(str)!=0?true:false; //DICTOOL->getIntValue_json(subDict, "value")!= 0? true:false;
}
continue;
}
}
}
void TScaleBy::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -555,6 +865,50 @@ void TSkewTo::serialize(const rapidjson::Value &val)
}
}
void TSkewTo::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "SkewX")
{
if (str != NULL)
{
_skew.x = atof(str);
}
}
else if (key == "SkewY")
{
if (str != NULL)
{
_skew.y = atof(str);
}
}
}
}
void TSkewTo::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -634,6 +988,54 @@ void TSkewBy::serialize(const rapidjson::Value &val)
}
}
void TSkewBy::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);
}
}
else if (key == "Duration")
{
if (str != NULL)
{
_duration = atof(str);
}
}
else if (key == "SkewX")
{
if (str != NULL)
{
_skew.x = atof(str);
}
}
else if (key == "SkewY")
{
if (str != NULL)
{
_skew.y = atof(str);
}
}
else if (key == "IsReverse")
{
_reverse = atoi(str)!=0?true:false; //DICTOOL->getIntValue_json(subDict, "value")!= 0? true:false;
}
}
}
void TSkewBy::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
@ -700,6 +1102,36 @@ void TriggerState::serialize(const rapidjson::Value &val)
}
}
void TriggerState::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "ID")
{
if (str != NULL)
{
_id = atoi(str);
}
}
else if (key == "State")
{
if (str != NULL)
{
_state = atoi(str);
}
}
}
}
void TriggerState::removeAll()
{
CCLOG("TriggerState::removeAll");
@ -726,7 +1158,7 @@ void ArmaturePlayAction::done()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(node == nullptr);
ComRender *pRender = (ComRender*)(node->getComponent(_ComName.c_str()));
ComRender *pRender = (ComRender*)(node->getComponent(_comName.c_str()));
CC_BREAK_IF(pRender == nullptr);
Armature *pAr = (Armature *)(pRender->getNode());
CC_BREAK_IF(pAr == nullptr);
@ -748,7 +1180,7 @@ void ArmaturePlayAction::serialize(const rapidjson::Value &val)
}
else if (key == "componentName")
{
_ComName = DICTOOL->getStringValue_json(subDict, "value");
_comName = DICTOOL->getStringValue_json(subDict, "value");
continue;
}
else if (key == "AnimationName")
@ -759,6 +1191,43 @@ void ArmaturePlayAction::serialize(const rapidjson::Value &val)
}
}
void ArmaturePlayAction::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "componentName")
{
if (str != NULL)
{
_comName = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "AnimationName")
{
if (str != NULL)
{
_aniname = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
}
}
void ArmaturePlayAction::removeAll()
{
CCLOG("ArmaturePlayAction::removeAll");

View File

@ -15,6 +15,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -32,6 +33,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -50,6 +52,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -69,6 +72,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -87,6 +91,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -106,6 +111,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -124,6 +130,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -144,6 +151,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -162,6 +170,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -181,6 +190,7 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _id;
@ -197,10 +207,11 @@ public:
virtual bool init();
virtual void done();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
std::string _ComName;
std::string _comName;
std::string _aniname;
};

View File

@ -47,6 +47,28 @@ void TimeElapsed::serialize(const rapidjson::Value &val)
}
}
void TimeElapsed::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "TotalTime")
{
if (str != NULL)
{
_totalTime = atof(str); //DICTOOL->getFloatValue_json(subDict, "value");
}
}
}
}
void TimeElapsed::removeAll()
{
_scheduler->unschedule(schedule_selector(TimeElapsed::update), this);
@ -125,6 +147,50 @@ void ArmatureActionState::serialize(const rapidjson::Value &val)
}
}
void ArmatureActionState::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "componentName")
{
if (str != NULL)
{
_comName = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "AnimationName")
{
if (str != NULL)
{
_aniname = str; //DICTOOL->getStringValue_json(subDict, "value");
}
}
else if (key == "ActionType")
{
if (str != NULL)
{
_state = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
}
}
void ArmatureActionState::removeAll()
{
do
@ -209,6 +275,56 @@ void NodeInRect::serialize(const rapidjson::Value &val)
}
}
void NodeInRect::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "originX")
{
if (str != NULL)
{
_origin.x = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "originY")
{
if (str != NULL)
{
_origin.y = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "sizeWidth")
{
if (str != NULL)
{
_size.width = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "sizeHeight")
{
if (str != NULL)
{
_size.height = atoi(str); //DICTOOL->getIntValue_json(subDict, "value");
}
}
}
}
void NodeInRect::removeAll()
{
CCLOG("NodeInRect::removeAll");
@ -261,6 +377,35 @@ void NodeVisible::serialize(const rapidjson::Value &val)
}
}
void NodeVisible::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode)
{
int length = pCocoNode->GetChildNum();
int count = 0;
stExpCocoNode *pDataItemsArray = pCocoNode->GetChildArray();
std::string key;
const char *str = NULL;
for (int i = 0; i < length; ++i)
{
count = pDataItemsArray[i].GetChildNum();
stExpCocoNode *pDataItemArray = pDataItemsArray[i].GetChildArray();
key = pDataItemArray[0].GetValue();
str = pDataItemArray[1].GetValue();
if (key == "Tag")
{
if (str != NULL)
{
_tag = atoi(str);//DICTOOL->getIntValue_json(subDict, "value");
}
}
else if (key == "Visible")
{
if (str != NULL)
{
_visible = atoi(str) != 0? true:false;//DICTOOL->getIntValue_json(subDict, "value") != 0? true:false;
}
}
}
}
void NodeVisible::removeAll()
{
CCLOG("NodeVisible::removeAll");

View File

@ -15,6 +15,7 @@ public:
virtual bool init();
virtual bool detect();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
virtual void update(float dt);
private:
@ -35,6 +36,7 @@ public:
virtual bool init();
virtual bool detect();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private:
@ -56,6 +58,7 @@ public:
virtual bool init();
virtual bool detect();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;
@ -73,6 +76,7 @@ public:
virtual bool init();
virtual bool detect();
virtual void serialize(const rapidjson::Value &val);
virtual void serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode);
virtual void removeAll();
private:
int _tag;