Triggers now adapt if the object they want to do something with gets deleted or changes its index.

This commit is contained in:
Steffen Fündgens 2015-01-13 18:18:13 +01:00
parent f4408b76e8
commit a137d2544a
5 changed files with 36 additions and 25 deletions

View File

@ -21,8 +21,8 @@
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>deleteRandomObject</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>5</toChangeIdBlue>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
<trigger>
@ -65,9 +65,9 @@
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -94,9 +94,9 @@
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -123,9 +123,9 @@
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>
@ -152,9 +152,9 @@
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>-</luaScript>
<toChangeIdGreen>-</toChangeIdGreen>
<toChangeIdBlue>-</toChangeIdBlue>
<toChangeObjNum>-</toChangeObjNum>
<toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>0</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition>

View File

@ -194,9 +194,9 @@ std::vector<int> Converter::newComposition(int type, float posX, float posZ){
isBiggerThan->SetText("false");
objectNum->SetText("0");
luaScript->SetText("-");
toChangeIdGreen->SetText("-");
toChangeIdBlue->SetText("-");
toChangeObjNum->SetText("-");
toChangeIdGreen->SetText("0");
toChangeIdBlue->SetText("0");
toChangeObjNum->SetText("0");
trigger->InsertEndChild(name);
trigger->InsertEndChild(xPosition);

View File

@ -365,7 +365,7 @@ void Level::load() {
}
std::string luaScript = charLuaScript;
int toChangeIdGreen, toChangeIdBlue, toChangeObjNum, objectToChange=0;
int toChangeIdGreen, toChangeIdBlue, toChangeObjNum, objectToChange=-1;
errorCheck(xmlTrigger->FirstChildElement("toChangeIdGreen")->QueryIntText(&toChangeIdGreen));
errorCheck(xmlTrigger->FirstChildElement("toChangeIdBlue")->QueryIntText(&toChangeIdBlue));
errorCheck(xmlTrigger->FirstChildElement("toChangeObjNum")->QueryIntText(&toChangeObjNum));
@ -375,13 +375,8 @@ void Level::load() {
}
}
if (object != 0) {
if (objectToChange != 0) {
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange);
triggers.push_back(trigger);
}
else {
printf("Object to be changed by a trigger not found.\n");
}
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, L, objectToChange);
triggers.push_back(trigger);
}
else {
printf("Triggering object not found.\n");
@ -484,6 +479,11 @@ std::vector<Object*>* Level::getObjects() {
void Level::deleteObject(int objectIndex){
objects.erase(objects.begin() + objectIndex);
for(unsigned int i = 0; i<triggers.size(); i++) {
if(triggers.at(i).deleteNotification(objectIndex)){
triggers.erase(triggers.begin() + i);
}
}
}
int Level::getObjectCount(){

View File

@ -34,3 +34,13 @@ void Trigger::triggerUpdate(){
}
}
}
bool Trigger::deleteNotification(int deletedObjectIndex){
if (deletedObjectIndex < objectToChange){
objectToChange-=1;
}
if (deletedObjectIndex == objectToChange){
return true;
}
return false;
}

View File

@ -18,6 +18,7 @@ class Trigger {
Trigger();
~Trigger();
void triggerUpdate();
bool deleteNotification(int deletedObjectIndex);
private:
glm::vec3 position;
float distance;