1、 fixes lua TriggerTest bug.

This commit is contained in:
zhangcheng 2014-07-16 14:50:35 +08:00
parent e431d4f824
commit 80de57be39
3 changed files with 79 additions and 80 deletions

View File

@ -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);

View File

@ -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<BaseTriggerCondition*>(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<BaseTriggerCondition*>(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<BaseTriggerAction*>(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<BaseTriggerAction*>(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);
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);
}
EventListenerCustom* listener = EventListenerCustom::create(custom_event_name, [=](EventCustom* evt){
if (detect())
{
done();
}
});
_listeners.pushBack(listener);
TriggerMng::getInstance()->addEventListenerWithFixedPriority(listener, 1);
}
}
}
}

View File

@ -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()