diff --git a/cocos/editor-support/cocostudio/CCComAttribute.cpp b/cocos/editor-support/cocostudio/CCComAttribute.cpp index 2c4311690b..c269dbd52d 100644 --- a/cocos/editor-support/cocostudio/CCComAttribute.cpp +++ b/cocos/editor-support/cocostudio/CCComAttribute.cpp @@ -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) diff --git a/cocos/editor-support/cocostudio/CCComAudio.cpp b/cocos/editor-support/cocostudio/CCComAudio.cpp index 8fedf09c0e..717e8f701d 100644 --- a/cocos/editor-support/cocostudio/CCComAudio.cpp +++ b/cocos/editor-support/cocostudio/CCComAudio.cpp @@ -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) diff --git a/cocos/editor-support/cocostudio/CCComBase.h b/cocos/editor-support/cocostudio/CCComBase.h index 461a5a4b8e..9467b7381a 100644 --- a/cocos/editor-support/cocostudio/CCComBase.h +++ b/cocos/editor-support/cocostudio/CCComBase.h @@ -28,6 +28,7 @@ THE SOFTWARE. #include #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 diff --git a/cocos/editor-support/cocostudio/CCComRender.cpp b/cocos/editor-support/cocostudio/CCComRender.cpp index 2037518eee..3bc3b995b6 100644 --- a/cocos/editor-support/cocostudio/CCComRender.cpp +++ b/cocos/editor-support/cocostudio/CCComRender.cpp @@ -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) diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.cpp b/cocos/editor-support/cocostudio/CCSSceneReader.cpp index 894d4aa39b..39bab7ef3c 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.cpp +++ b/cocos/editor-support/cocostudio/CCSSceneReader.cpp @@ -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 _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(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::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(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 _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(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::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& 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() { diff --git a/cocos/editor-support/cocostudio/CCSSceneReader.h b/cocos/editor-support/cocostudio/CCSSceneReader.h index d80fa1b2d5..7d982858b2 100644 --- a/cocos/editor-support/cocostudio/CCSSceneReader.h +++ b/cocos/editor-support/cocostudio/CCSSceneReader.h @@ -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; diff --git a/cocos/editor-support/cocostudio/CocoLoader.h b/cocos/editor-support/cocostudio/CocoLoader.h index 5f59b496ee..d728b0f396 100644 --- a/cocos/editor-support/cocostudio/CocoLoader.h +++ b/cocos/editor-support/cocostudio/CocoLoader.h @@ -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); }; diff --git a/cocos/editor-support/cocostudio/TriggerMng.cpp b/cocos/editor-support/cocostudio/TriggerMng.cpp index 833cf73ee4..2111a57e2e 100755 --- a/cocos/editor-support/cocostudio/TriggerMng.cpp +++ b/cocos/editor-support/cocostudio/TriggerMng.cpp @@ -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 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(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) diff --git a/cocos/editor-support/cocostudio/TriggerMng.h b/cocos/editor-support/cocostudio/TriggerMng.h index c1e8661a46..afae1d2eb5 100755 --- a/cocos/editor-support/cocostudio/TriggerMng.h +++ b/cocos/editor-support/cocostudio/TriggerMng.h @@ -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* 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; diff --git a/cocos/editor-support/cocostudio/TriggerObj.cpp b/cocos/editor-support/cocostudio/TriggerObj.cpp index ad75ea058b..c9ddd6dc35 100755 --- a/cocos/editor-support/cocostudio/TriggerObj.cpp +++ b/cocos/editor-support/cocostudio/TriggerObj.cpp @@ -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(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(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; diff --git a/cocos/editor-support/cocostudio/TriggerObj.h b/cocos/editor-support/cocostudio/TriggerObj.h index 69a7e4e168..e026cc738a 100755 --- a/cocos/editor-support/cocostudio/TriggerObj.h +++ b/cocos/editor-support/cocostudio/TriggerObj.h @@ -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); diff --git a/cocos/platform/android/ControllerDelegate/.classpath b/cocos/platform/android/ControllerAutoAdapter/.classpath similarity index 100% rename from cocos/platform/android/ControllerDelegate/.classpath rename to cocos/platform/android/ControllerAutoAdapter/.classpath diff --git a/cocos/platform/android/ControllerDelegate/.project b/cocos/platform/android/ControllerAutoAdapter/.project similarity index 95% rename from cocos/platform/android/ControllerDelegate/.project rename to cocos/platform/android/ControllerAutoAdapter/.project index 6711d455fd..c49a037939 100644 --- a/cocos/platform/android/ControllerDelegate/.project +++ b/cocos/platform/android/ControllerAutoAdapter/.project @@ -1,6 +1,6 @@ - libcontrollerdelegate + libControllerAutoAdapter diff --git a/cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs b/cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs similarity index 100% rename from cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs rename to cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs diff --git a/cocos/platform/android/ControllerDelegate/AndroidManifest.xml b/cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml similarity index 100% rename from cocos/platform/android/ControllerDelegate/AndroidManifest.xml rename to cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml diff --git a/cocos/platform/android/ControllerDelegate/ant.properties b/cocos/platform/android/ControllerAutoAdapter/ant.properties similarity index 100% rename from cocos/platform/android/ControllerDelegate/ant.properties rename to cocos/platform/android/ControllerAutoAdapter/ant.properties diff --git a/cocos/platform/android/ControllerNibiru/build.xml b/cocos/platform/android/ControllerAutoAdapter/build.xml similarity index 98% rename from cocos/platform/android/ControllerNibiru/build.xml rename to cocos/platform/android/ControllerAutoAdapter/build.xml index 5e73af0ac0..413effd90c 100644 --- a/cocos/platform/android/ControllerNibiru/build.xml +++ b/cocos/platform/android/ControllerAutoAdapter/build.xml @@ -1,5 +1,5 @@ - + - - - - - - - - - - - - - - - - - - - diff --git a/cocos/platform/android/ControllerNibiru/.classpath b/cocos/platform/android/ControllerNibiru/.classpath deleted file mode 100644 index 51769745b2..0000000000 --- a/cocos/platform/android/ControllerNibiru/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/cocos/platform/android/ControllerNibiru/.project b/cocos/platform/android/ControllerNibiru/.project deleted file mode 100644 index c540b70b88..0000000000 --- a/cocos/platform/android/ControllerNibiru/.project +++ /dev/null @@ -1,33 +0,0 @@ - - - libcontrollernibiru - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff --git a/cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs b/cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b080d2ddc8..0000000000 --- a/cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/cocos/platform/android/ControllerNibiru/AndroidManifest.xml b/cocos/platform/android/ControllerNibiru/AndroidManifest.xml deleted file mode 100644 index d1f4a837d8..0000000000 --- a/cocos/platform/android/ControllerNibiru/AndroidManifest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/cocos/platform/android/ControllerNibiru/ant.properties b/cocos/platform/android/ControllerNibiru/ant.properties deleted file mode 100644 index b0971e891e..0000000000 --- a/cocos/platform/android/ControllerNibiru/ant.properties +++ /dev/null @@ -1,17 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked into Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - diff --git a/cocos/platform/android/ControllerNibiru/proguard-project.txt b/cocos/platform/android/ControllerNibiru/proguard-project.txt deleted file mode 100644 index f2fe1559a2..0000000000 --- a/cocos/platform/android/ControllerNibiru/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/cocos/platform/android/ControllerNibiru/res/.gitignore b/cocos/platform/android/ControllerNibiru/res/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cocos/platform/android/ControllerOuya/.classpath b/cocos/platform/android/ControllerOuya/.classpath deleted file mode 100644 index 51769745b2..0000000000 --- a/cocos/platform/android/ControllerOuya/.classpath +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs b/cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index b080d2ddc8..0000000000 --- a/cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.source=1.6 diff --git a/cocos/platform/android/ControllerOuya/AndroidManifest.xml b/cocos/platform/android/ControllerOuya/AndroidManifest.xml deleted file mode 100644 index d1f4a837d8..0000000000 --- a/cocos/platform/android/ControllerOuya/AndroidManifest.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/cocos/platform/android/ControllerOuya/ant.properties b/cocos/platform/android/ControllerOuya/ant.properties deleted file mode 100644 index b0971e891e..0000000000 --- a/cocos/platform/android/ControllerOuya/ant.properties +++ /dev/null @@ -1,17 +0,0 @@ -# This file is used to override default values used by the Ant build system. -# -# This file must be checked into Version Control Systems, as it is -# integral to the build system of your project. - -# This file is only used by the Ant script. - -# You can use this to override default values such as -# 'source.dir' for the location of your java source folder and -# 'out.dir' for the location of your output folder. - -# You can also use it define how the release builds are signed by declaring -# the following properties: -# 'key.store' for the location of your keystore and -# 'key.alias' for the name of the key to use. -# The password will be asked during the build when you use the 'release' target. - diff --git a/cocos/platform/android/ControllerOuya/build.xml b/cocos/platform/android/ControllerOuya/build.xml deleted file mode 100644 index 7fc3634914..0000000000 --- a/cocos/platform/android/ControllerOuya/build.xml +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cocos/platform/android/ControllerOuya/proguard-project.txt b/cocos/platform/android/ControllerOuya/proguard-project.txt deleted file mode 100644 index f2fe1559a2..0000000000 --- a/cocos/platform/android/ControllerOuya/proguard-project.txt +++ /dev/null @@ -1,20 +0,0 @@ -# To enable ProGuard in your project, edit project.properties -# to define the proguard.config property as described in that file. -# -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in ${sdk.dir}/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the ProGuard -# include property in project.properties. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} diff --git a/cocos/platform/android/ControllerOuya/res/.gitignore b/cocos/platform/android/ControllerOuya/res/.gitignore deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/cocos/platform/android/java/project.properties b/cocos/platform/android/java/project.properties index 732c58e368..88ca83f9d0 100644 --- a/cocos/platform/android/java/project.properties +++ b/cocos/platform/android/java/project.properties @@ -12,5 +12,4 @@ android.library=true # Project target. -target=android-16 -android.library.reference.1=../ControllerDelegate +target=android-10 diff --git a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java index 265387c29e..78929fb300 100644 --- a/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java +++ b/cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxActivity.java @@ -24,9 +24,6 @@ THE SOFTWARE. package org.cocos2dx.lib; import org.cocos2dx.lib.Cocos2dxHelper.Cocos2dxHelperListener; -import org.cocos2dx.lib.GameControllerDelegate.ControllerEventListener; -import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat; -import org.cocos2dx.lib.inputmanagercompat.InputManagerCompat.InputDeviceListener; import android.app.Activity; import android.content.Context; @@ -36,15 +33,12 @@ import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.os.Message; -import android.view.InputDevice; -import android.view.KeyEvent; -import android.view.MotionEvent; import android.view.ViewGroup; import android.util.Log; import android.widget.FrameLayout; import android.preference.PreferenceManager.OnActivityResultListener; -public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener, InputDeviceListener { +public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelperListener { // =========================================================== // Constants // =========================================================== @@ -59,10 +53,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe private Cocos2dxHandler mHandler; private static Cocos2dxActivity sContext = null; private Cocos2dxVideoHelper mVideoHelper = null; - private InputManagerCompat mInputManager = null; - - protected GameControllerHelper mControllerHelper = null; - protected GameControllerDelegate mControllerDelegate = null; public static Context getContext() { return sContext; @@ -79,45 +69,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe } } - public void setGameControllerInstance(GameControllerDelegate controllerDelegate) { - if (mControllerDelegate != null) { - mControllerDelegate.onDestroy(); - mControllerDelegate = null; - } - mControllerDelegate = controllerDelegate; - mControllerDelegate.setControllerEventListener(mControllerEventListener); - mControllerDelegate.onCreate(this); - } - - public GameControllerDelegate getGameControllerInstance(){ - return mControllerDelegate; - } - - ControllerEventListener mControllerEventListener = new ControllerEventListener() { - - @Override - public void onButtonEvent(String vendorName, int controller, int button, - boolean isPressed, float value, boolean isAnalog) { - GameControllerAdapter.onButtonEvent(vendorName, controller, button, isPressed, value, isAnalog); - } - - @Override - public void onAxisEvent(String vendorName, int controller, int axisID, - float value, boolean isAnalog) { - GameControllerAdapter.onAxisEvent(vendorName, controller, axisID, value, isAnalog); - } - - @Override - public void onConnected(String vendorName, int controller) { - GameControllerAdapter.onConnected(vendorName, controller); - } - - @Override - public void onDisconnected(String vendorName, int controller) { - GameControllerAdapter.onDisconnected(vendorName, controller); - } - }; - // =========================================================== // Constructors // =========================================================== @@ -137,16 +88,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe if (mVideoHelper == null) { mVideoHelper = new Cocos2dxVideoHelper(this, mFrameLayout); } - - mInputManager = InputManagerCompat.Factory.getInputManager(this); - mInputManager.registerInputDeviceListener(this, null); - - if (mControllerDelegate != null) { - mControllerDelegate.onCreate(this); - } - if (mControllerHelper == null) { - mControllerHelper = new GameControllerHelper(this); - } } // =========================================================== @@ -157,96 +98,16 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe // Methods for/from SuperClass/Interfaces // =========================================================== - @Override - public boolean dispatchKeyEvent(KeyEvent event) { - boolean handled = false; - if (mControllerDelegate != null) { - handled = mControllerDelegate.dispatchKeyEvent(event); - } - else { - handled = mControllerHelper.dispatchKeyEvent(event); - } - return handled || super.dispatchKeyEvent(event); - } - - @Override - public boolean dispatchGenericMotionEvent(MotionEvent event) { - boolean handled = false; - if (mControllerDelegate != null) { - handled = mControllerDelegate.dispatchGenericMotionEvent(event); - }else { - handled = mControllerHelper.dispatchGenericMotionEvent(event); - } - return handled || super.dispatchGenericMotionEvent(event); - } - - @Override - public void onInputDeviceAdded(int deviceId) { - - Log.d(TAG,"onInputDeviceAdded:" + deviceId); - - InputDevice device = InputDevice.getDevice(deviceId); - int deviceSource = device.getSources(); - - if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - GameControllerAdapter.onConnected("Standard", deviceId); - } - } - /* - * This is an unusual case. Input devices don't typically change, but they - * certainly can --- for example a device may have different modes. We use - * this to make sure that the ship has an up-to-date InputDevice. - * - * @see - * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener - * #onInputDeviceChanged(int) - */ - @Override - public void onInputDeviceChanged(int deviceId) { - Log.d(TAG,"onInputDeviceChanged:" + deviceId); - } - - /* - * Remove any ship associated with the ID. - * - * @see - * com.example.inputmanagercompat.InputManagerCompat.InputDeviceListener - * #onInputDeviceRemoved(int) - */ - @Override - public void onInputDeviceRemoved(int deviceId) { - Log.d(TAG,"onInputDeviceRemoved:" + deviceId); - - InputDevice device = InputDevice.getDevice(deviceId); - int deviceSource = device.getSources(); - - if ( ((deviceSource & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) - || ((deviceSource & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK) ) - { - GameControllerAdapter.onDisconnected("Standard", deviceId); - } - } - @Override protected void onResume() { super.onResume(); Cocos2dxHelper.onResume(); this.mGLSurfaceView.onResume(); - - if (mControllerDelegate != null) { - mControllerDelegate.onResume(); - } } @Override protected void onPause() { - if (mControllerDelegate != null) { - mControllerDelegate.onPause(); - } - super.onPause(); Cocos2dxHelper.onPause(); @@ -255,11 +116,6 @@ public abstract class Cocos2dxActivity extends Activity implements Cocos2dxHelpe @Override protected void onDestroy() { - if (mControllerDelegate != null) { - mControllerDelegate.onDestroy(); - } - mControllerHelper.destrory(); - super.onDestroy(); } diff --git a/cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java b/cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java similarity index 100% rename from cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java rename to cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java diff --git a/templates/cocos2dx_files.json b/templates/cocos2dx_files.json index c39bed7595..e84a7ed3c1 100644 --- a/templates/cocos2dx_files.json +++ b/templates/cocos2dx_files.json @@ -747,38 +747,36 @@ "cocos/platform/android/CCGLView.h", "cocos/platform/android/CCPlatformDefine.h", "cocos/platform/android/CCStdC.h", - "cocos/platform/android/ControllerDelegate/.classpath", - "cocos/platform/android/ControllerDelegate/.project", - "cocos/platform/android/ControllerDelegate/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerDelegate/AndroidManifest.xml", - "cocos/platform/android/ControllerDelegate/ant.properties", - "cocos/platform/android/ControllerDelegate/build.xml", - "cocos/platform/android/ControllerDelegate/proguard-project.txt", - "cocos/platform/android/ControllerDelegate/src/org/cocos2dx/lib/GameControllerDelegate.java", - "cocos/platform/android/ControllerMoga/.classpath", - "cocos/platform/android/ControllerMoga/.project", - "cocos/platform/android/ControllerMoga/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerMoga/AndroidManifest.xml", - "cocos/platform/android/ControllerMoga/ant.properties", - "cocos/platform/android/ControllerMoga/build.xml", - "cocos/platform/android/ControllerMoga/proguard-project.txt", - "cocos/platform/android/ControllerMoga/src/org/cocos2dx/lib/GameControllerMoga.java", - "cocos/platform/android/ControllerNibiru/.classpath", - "cocos/platform/android/ControllerNibiru/.project", - "cocos/platform/android/ControllerNibiru/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerNibiru/AndroidManifest.xml", - "cocos/platform/android/ControllerNibiru/ant.properties", - "cocos/platform/android/ControllerNibiru/build.xml", - "cocos/platform/android/ControllerNibiru/proguard-project.txt", - "cocos/platform/android/ControllerNibiru/src/org/cocos2dx/lib/GameControllerNibiru.java", - "cocos/platform/android/ControllerOuya/.classpath", - "cocos/platform/android/ControllerOuya/.project", - "cocos/platform/android/ControllerOuya/.settings/org.eclipse.jdt.core.prefs", - "cocos/platform/android/ControllerOuya/AndroidManifest.xml", - "cocos/platform/android/ControllerOuya/ant.properties", - "cocos/platform/android/ControllerOuya/build.xml", - "cocos/platform/android/ControllerOuya/proguard-project.txt", - "cocos/platform/android/ControllerOuya/src/org/cocos2dx/lib/GameControllerOuya.java", + "cocos/platform/android/ControllerAutoAdapter/.classpath", + "cocos/platform/android/ControllerAutoAdapter/.project", + "cocos/platform/android/ControllerAutoAdapter/.settings/org.eclipse.jdt.core.prefs", + "cocos/platform/android/ControllerAutoAdapter/AndroidManifest.xml", + "cocos/platform/android/ControllerAutoAdapter/ant.properties", + "cocos/platform/android/ControllerAutoAdapter/build.xml", + "cocos/platform/android/ControllerAutoAdapter/lint.xml", + "cocos/platform/android/ControllerAutoAdapter/proguard-project.txt", + "cocos/platform/android/ControllerAutoAdapter/project.properties", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerActivity.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/GameControllerHelper.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java", + "cocos/platform/android/ControllerAutoAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java", + "cocos/platform/android/ControllerManualAdapter/.classpath", + "cocos/platform/android/ControllerManualAdapter/.project", + "cocos/platform/android/ControllerManualAdapter/.settings/org.eclipse.jdt.core.prefs", + "cocos/platform/android/ControllerManualAdapter/AndroidManifest.xml", + "cocos/platform/android/ControllerManualAdapter/ant.properties", + "cocos/platform/android/ControllerManualAdapter/build.xml", + "cocos/platform/android/ControllerManualAdapter/lint.xml", + "cocos/platform/android/ControllerManualAdapter/proguard-project.txt", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerActivity.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerHelper.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerMoga.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerNibiru.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/GameControllerOuya.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java", + "cocos/platform/android/ControllerManualAdapter/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java", "cocos/platform/android/java/.classpath", "cocos/platform/android/java/.project", "cocos/platform/android/java/.settings/org.eclipse.jdt.core.prefs", @@ -807,11 +805,8 @@ "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoHelper.java", "cocos/platform/android/java/src/org/cocos2dx/lib/Cocos2dxVideoView.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerAdapter.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerHelper.java", + "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerDelegate.java", "cocos/platform/android/java/src/org/cocos2dx/lib/GameControllerUtils.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerCompat.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV16.java", - "cocos/platform/android/java/src/org/cocos2dx/lib/inputmanagercompat/InputManagerV9.java", "cocos/platform/android/javaactivity.cpp", "cocos/platform/android/jni/DPIJni.cpp", "cocos/platform/android/jni/DPIJni.h", diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp index 708a58e0ea..e560953416 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.cpp @@ -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(node->getChildByTag(10003)->getComponent("CCSprite")); + ComRender *pSister1 = static_cast(_rootNode->getChildByTag(10003)->getComponent("CCSprite")); pSister1->getNode()->runAction(action1); - ComRender *pSister2 = static_cast(node->getChildByTag(10004)->getComponent("CCSprite")); + ComRender *pSister2 = static_cast(_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(node->getChildByTag(10007)->getComponent("CCArmature")); - pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); + defaultPlay(); + return _rootNode; +} - ComRender *pButterflyfish = static_cast(node->getChildByTag(10008)->getComponent("CCArmature")); - pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); +void ArmatureComponentTest::defaultPlay() +{ + ComRender *pBlowFish = static_cast(_rootNode->getChildByTag(10007)->getComponent("CCArmature")); + pBlowFish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0))); + + ComRender *pButterflyfish = static_cast(_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(_node->getChildByTag(10025)->getComponent("GUIComponent")); - Widget* widget = static_cast(render->getNode()); - Button* button = static_cast(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(_node->getChildByTag(10010)->getComponent("CCArmature")); + ComRender *pBlowFish = static_cast(_rootNode->getChildByTag(10010)->getComponent("CCArmature")); pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0))); - ComRender *pButterflyfish = static_cast(_node->getChildByTag(10011)->getComponent("CCArmature")); + ComRender *pButterflyfish = static_cast(_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(_rootNode->getChildByTag(10025)->getComponent("GUIComponent")); + Widget* widget = static_cast(render->getNode()); + Button* button = static_cast(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(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(_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(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(_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(_node->getChildByTag(10015)->getComponent("CCArmature")); - Armature *pAr = static_cast(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(_node->getChildByTag(10015)->getComponent("CCComAudio")); + ComAudio *pAudio = static_cast(_rootNode->getChildByTag(10015)->getComponent("CCComAudio")); pAudio->playEffect(); } } } +void EffectComponentTest::defaultPlay() +{ + ComRender *render = static_cast(_rootNode->getChildByTag(10015)->getComponent("CCArmature")); + Armature *pAr = static_cast(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(node->getComponent("CCBackgroundAudio")); +void BackgroundComponentTest::defaultPlay() +{ + ComAudio *Audio = static_cast(_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(_node->getChildByTag(10015)->getComponent("CCComAttribute")); + CC_BREAK_IF(_rootNode == nullptr); + ComAttribute *attribute = static_cast(_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() +{ } diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h index b6d68a6593..a21187c159 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/SceneEditorTest.h @@ -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__ diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp index 4e29ed3236..d637c7c9c6 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.cpp @@ -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"); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.h index 08ffae0b2a..70b2811601 100755 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/acts.h @@ -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; }; diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp index e0f402d587..18beb3cae4 100644 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.cpp @@ -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"); diff --git a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.h b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.h index 6fb23a0195..2b9da0d018 100755 --- a/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.h +++ b/tests/cpp-tests/Classes/ExtensionsTest/CocoStudioSceneTest/TriggerCode/cons.h @@ -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; diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp index 1f8a1403fd..ac8281b9f6 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.cpp @@ -341,7 +341,6 @@ Effect3DOutline::Effect3DOutline() Effect3DOutline::~Effect3DOutline() { - CC_SAFE_RELEASE_NULL(_sprite); #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) Director::getInstance()->getEventDispatcher()->removeEventListener(_backToForegroundListener); #endif @@ -371,8 +370,6 @@ void Effect3DOutline::setTarget(EffectSprite3D *sprite) if(sprite != _sprite) { - CC_SAFE_RETAIN(sprite); - CC_SAFE_RELEASE_NULL(_sprite); _sprite = sprite; auto mesh = sprite->getMesh(); diff --git a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h index 6695bcfc13..efb5052cc8 100644 --- a/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h +++ b/tests/cpp-tests/Classes/Sprite3DTest/Sprite3DTest.h @@ -103,6 +103,7 @@ protected: Vec3 _outlineColor; float _outlineWidth; + //weak reference EffectSprite3D* _sprite; #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) EventListenerCustom* _backToForegroundListener; diff --git a/tests/game-controller-test/proj.android/project.properties b/tests/game-controller-test/proj.android/project.properties index 572f7c30de..c851eff541 100644 --- a/tests/game-controller-test/proj.android/project.properties +++ b/tests/game-controller-test/proj.android/project.properties @@ -10,4 +10,4 @@ # Project target. target=android-10 -android.library.reference.1=../../../cocos/platform/android/java +android.library.reference.1=../../../cocos/platform/android/ControllerDelegate diff --git a/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java b/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java index 2675ce468b..570608bada 100644 --- a/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java +++ b/tests/game-controller-test/proj.android/src/org/cocos2dx/game_controller_test/AppActivity.java @@ -25,14 +25,14 @@ package org.cocos2dx.game_controller_test; import java.util.ArrayList; -import org.cocos2dx.lib.Cocos2dxActivity; +import org.cocos2dx.lib.GameControllerActivity; import org.cocos2dx.lib.GameControllerHelper.ControllerListener; import android.bluetooth.BluetoothDevice; import android.os.Bundle; import android.util.Log; -public class AppActivity extends Cocos2dxActivity { +public class AppActivity extends GameControllerActivity { @Override protected void onCreate(Bundle savedInstanceState) {