From 80de57be39a18f4214099f550defa10904cab067 Mon Sep 17 00:00:00 2001 From: zhangcheng Date: Wed, 16 Jul 2014 14:50:35 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=20fixes=20lua=20TriggerTest=20bug.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../editor-support/cocostudio/TriggerMng.cpp | 6 +- .../editor-support/cocostudio/TriggerObj.cpp | 148 +++++++++--------- .../CocoStudioSceneTest.lua | 5 +- 3 files changed, 79 insertions(+), 80 deletions(-) diff --git a/cocos/editor-support/cocostudio/TriggerMng.cpp b/cocos/editor-support/cocostudio/TriggerMng.cpp index 779b5dca86..d1e8d33fe3 100755 --- a/cocos/editor-support/cocostudio/TriggerMng.cpp +++ b/cocos/editor-support/cocostudio/TriggerMng.cpp @@ -191,7 +191,7 @@ bool TriggerMng::isEmpty(void) const } - void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode) +void TriggerMng::buildJson(rapidjson::Document &document, cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode) { int count = pCocoNode[13].GetChildNum(); int length = 0; @@ -262,12 +262,12 @@ bool TriggerMng::isEmpty(void) const } else { - rapidjson::Type type = pDataItemArray[i4].GetType(pCocoLoader); + rapidjson::Type type = pDataItemArray[i5].GetType(pCocoLoader); if (type == rapidjson::kStringType) { dataitem.AddMember("value", str3, allocator); } - else if(type == rapidjson::kNumberType) + else { int nV = atoi(str3); float fV = atof(str3); diff --git a/cocos/editor-support/cocostudio/TriggerObj.cpp b/cocos/editor-support/cocostudio/TriggerObj.cpp index 7fec68a848..06cd96986e 100755 --- a/cocos/editor-support/cocostudio/TriggerObj.cpp +++ b/cocos/editor-support/cocostudio/TriggerObj.cpp @@ -241,98 +241,98 @@ void TriggerObj::serialize(const rapidjson::Value &val) } - void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode) +void TriggerObj::serialize(cocostudio::CocoLoader *pCocoLoader, cocostudio::stExpCocoNode *pCocoNode) +{ + int length = pCocoNode->GetChildNum(); + int count = 0; + int num = 0; + stExpCocoNode *pTriggerObjArray = pCocoNode->GetChildArray(pCocoLoader); + for (int i0 = 0; i0 < length; ++i0) { - int length = pCocoNode->GetChildNum(); - int count = 0; - int num = 0; - stExpCocoNode *pTriggerObjArray = pCocoNode->GetChildArray(pCocoLoader); - for (int i0 = 0; i0 < length; ++i0) + std::string key = pTriggerObjArray[i0].GetName(pCocoLoader); + const char* str0 = pTriggerObjArray[i0].GetValue(pCocoLoader); + if (key.compare("id") == 0) { - std::string key = pTriggerObjArray[i0].GetName(pCocoLoader); - const char* str0 = pTriggerObjArray[i0].GetValue(pCocoLoader); - if (key.compare("id") == 0) + if (str0 != nullptr) { - if (str0 != nullptr) - { - _id = atoi(str0); //(unsigned int)(DICTOOL->getIntValue_json(val, "id")); - } + _id = atoi(str0); } - else if (key.compare("conditions") == 0) + } + else if (key.compare("conditions") == 0) + { + count = pTriggerObjArray[i0].GetChildNum(); + stExpCocoNode *pConditionsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader); + for (int i1 = 0; i1 < count; ++i1) { - count = pTriggerObjArray[i0].GetChildNum(); - stExpCocoNode *pConditionsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader); - for (int i1 = 0; i1 < count; ++i1) + num = pConditionsArray[i1].GetChildNum(); + stExpCocoNode *pConditionArray = pConditionsArray[i1].GetChildArray(pCocoLoader); + const char *classname = pConditionArray[0].GetValue(pCocoLoader); + if (classname == nullptr) { - num = pConditionsArray[i1].GetChildNum(); - stExpCocoNode *pConditionArray = pConditionsArray[i1].GetChildArray(pCocoLoader); - const char *classname = pConditionArray[0].GetValue(pCocoLoader); - if (classname == nullptr) - { - continue; - } - BaseTriggerCondition *con = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); - CCAssert(con != nullptr, "class named classname can not implement!"); - con->serialize(pCocoLoader, &pConditionArray[1]); - con->init(); - _cons.pushBack(con); + continue; } + BaseTriggerCondition *con = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); + CCAssert(con != nullptr, "class named classname can not implement!"); + con->serialize(pCocoLoader, &pConditionArray[1]); + con->init(); + _cons.pushBack(con); } - else if (key.compare("actions") == 0) + } + else if (key.compare("actions") == 0) + { + count = pTriggerObjArray[i0].GetChildNum(); + stExpCocoNode *pActionsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader); + for (int i2 = 0; i2 < count; ++i2) { - count = pTriggerObjArray[i0].GetChildNum(); - stExpCocoNode *pActionsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader); - for (int i2 = 0; i2 < count; ++i2) + num = pActionsArray[i2].GetChildNum(); + stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray(pCocoLoader); + const char *classname = pActionArray[0].GetValue(pCocoLoader); + if (classname == nullptr) { - num = pActionsArray[i2].GetChildNum(); - stExpCocoNode *pActionArray = pActionsArray[i2].GetChildArray(pCocoLoader); - const char *classname = pActionArray[0].GetValue(pCocoLoader); - if (classname == nullptr) - { - continue; - } - BaseTriggerAction *act = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); - CCAssert(act != nullptr, "class named classname can not implement!"); - act->serialize(pCocoLoader, &pActionArray[1]); - act->init(); - _acts.pushBack(act); + continue; } + BaseTriggerAction *act = dynamic_cast(ObjectFactory::getInstance()->createObject(classname)); + CCAssert(act != nullptr, "class named classname can not implement!"); + act->serialize(pCocoLoader, &pActionArray[1]); + act->init(); + _acts.pushBack(act); } - else if (key.compare("events") == 0) + } + else if (key.compare("events") == 0) + { + count = pTriggerObjArray[i0].GetChildNum(); + stExpCocoNode *pEventsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader); + for (int i3 = 0; i3 < count; ++i3) { - count = pTriggerObjArray[i0].GetChildNum(); - stExpCocoNode *pEventsArray = pTriggerObjArray[i0].GetChildArray(pCocoLoader); - for (int i3 = 0; i3 < count; ++i3) + num = pEventsArray[i3].GetChildNum(); + stExpCocoNode *pEventArray = pEventsArray[i3].GetChildArray(pCocoLoader); + const char *str1 = pEventArray[0].GetValue(pCocoLoader); + if (str1 == nullptr) { - num = pEventsArray[i3].GetChildNum(); - stExpCocoNode *pEventArray = pEventsArray[i3].GetChildArray(pCocoLoader); - const char *str1 = pEventArray[0].GetValue(pCocoLoader); - if (str1 == nullptr) - { - continue; - } - int event = atoi(str1); - 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); + continue; } + int event = atoi(str1); + 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); } } } +} diff --git a/tests/lua-tests/src/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua b/tests/lua-tests/src/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua index 8e4e375b97..50d23a12c9 100644 --- a/tests/lua-tests/src/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua +++ b/tests/lua-tests/src/CocoStudioTest/CocoStudioSceneTest/CocoStudioSceneTest.lua @@ -174,6 +174,7 @@ function SceneEditorTestLayer:createMenu() if sceneEditorTestIdx == #SceneEditorTestLayer.title then self:unscheduleUpdate() + ccs.TriggerMng.getInstance():removeAll() end SceneEditorTestLayer.fileName = self:loadFileChangeHelper(SceneEditorTestLayer.fileName) @@ -846,13 +847,11 @@ function TriggerTest:onEnter() ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_UPDATESCENE) end self:scheduleUpdateWithPriorityLua(update,0) - - ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_ENTERSCENE) end end function TriggerTest:defaultPlay() - + ccs.sendTriggerEvent(triggerEventDef.TRIGGEREVENT_ENTERSCENE) end function TriggerTest:onExit()