Changed triggers so the undo function can be in the same lua file. Fixed triggers for the second door.

This commit is contained in:
Steffen Fündgens 2015-03-04 14:35:14 +01:00
parent 8b5f6f9b74
commit 6fee8a81b1
12 changed files with 231 additions and 74 deletions

View File

@ -715,6 +715,7 @@
</positionConstraint> </positionConstraint>
<trigger> <trigger>
<name>openSecondDoor1</name> <name>openSecondDoor1</name>
<undo>false</undo>
<xPosition>-6.5</xPosition> <xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition> <yPosition>22.0</yPosition>
<zPosition>51.5</zPosition> <zPosition>51.5</zPosition>
@ -728,6 +729,22 @@
<toChangeIdBlue>8</toChangeIdBlue> <toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
<trigger>
<name>openSecondDoor1Undo</name>
<undo>true</undo>
<xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>51.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor1.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition> </composition>
<composition> <composition>
@ -751,6 +768,7 @@
</positionConstraint> </positionConstraint>
<trigger> <trigger>
<name>openSecondDoor3</name> <name>openSecondDoor3</name>
<undo>false</undo>
<xPosition>-6.5</xPosition> <xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition> <yPosition>22.0</yPosition>
<zPosition>29.5</zPosition> <zPosition>29.5</zPosition>
@ -764,6 +782,22 @@
<toChangeIdBlue>8</toChangeIdBlue> <toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
<trigger>
<name>openSecondDoor3Undo</name>
<undo>true</undo>
<xPosition>-6.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>29.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor3.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition> </composition>
<composition> <composition>
@ -2411,6 +2445,7 @@
</positionConstraint> </positionConstraint>
<trigger> <trigger>
<name>openSecondDoor4</name> <name>openSecondDoor4</name>
<undo>false</undo>
<xPosition>-53.5</xPosition> <xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition> <yPosition>22.0</yPosition>
<zPosition>51.5</zPosition> <zPosition>51.5</zPosition>
@ -2424,6 +2459,22 @@
<toChangeIdBlue>8</toChangeIdBlue> <toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
<trigger>
<name>openSecondDoor4Undo</name>
<undo>true</undo>
<xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>51.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor4.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition> </composition>
<composition> <composition>
@ -2476,6 +2527,7 @@
</positionConstraint> </positionConstraint>
<trigger> <trigger>
<name>openSecondDoor2</name> <name>openSecondDoor2</name>
<undo>false</undo>
<xPosition>-53.5</xPosition> <xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition> <yPosition>22.0</yPosition>
<zPosition>29.5</zPosition> <zPosition>29.5</zPosition>
@ -2489,6 +2541,22 @@
<toChangeIdBlue>8</toChangeIdBlue> <toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
</trigger> </trigger>
<trigger>
<name>openSecondDoor2Undo</name>
<undo>true</undo>
<xPosition>-53.5</xPosition>
<yPosition>22.0</yPosition>
<zPosition>29.5</zPosition>
<targetIdGreen>-</targetIdGreen>
<targetIdBlue>-</targetIdBlue>
<distance>0.2</distance>
<isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum>
<luaScript>openSecondDoor2.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>8</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum>
</trigger>
</composition> </composition>
<composition> <composition>
@ -3672,6 +3740,7 @@
</positionConstraint> </positionConstraint>
<trigger> <trigger>
<name>openThirdDoor</name> <name>openThirdDoor</name>
<undo>false</undo>
<xPosition>-161.5</xPosition> <xPosition>-161.5</xPosition>
<yPosition>21.7</yPosition> <yPosition>21.7</yPosition>
<zPosition>67.5</zPosition> <zPosition>67.5</zPosition>
@ -3687,6 +3756,7 @@
</trigger> </trigger>
<trigger> <trigger>
<name>openThirdDoorUndo</name> <name>openThirdDoorUndo</name>
<undo>true</undo>
<xPosition>-161.5</xPosition> <xPosition>-161.5</xPosition>
<yPosition>21.7</yPosition> <yPosition>21.7</yPosition>
<zPosition>67.5</zPosition> <zPosition>67.5</zPosition>
@ -3695,7 +3765,7 @@
<distance>0.2</distance> <distance>0.2</distance>
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>openThirdDoorUndo.lua</luaScript> <luaScript>openThirdDoor.lua</luaScript>
<toChangeIdGreen>0</toChangeIdGreen> <toChangeIdGreen>0</toChangeIdGreen>
<toChangeIdBlue>178</toChangeIdBlue> <toChangeIdBlue>178</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>
@ -6159,6 +6229,7 @@
</positionConstraint> </positionConstraint>
<trigger> <trigger>
<name>openFirstDoor</name> <name>openFirstDoor</name>
<undo>false</undo>
<xPosition>17.5</xPosition> <xPosition>17.5</xPosition>
<yPosition>21.8</yPosition> <yPosition>21.8</yPosition>
<zPosition>159.5</zPosition> <zPosition>159.5</zPosition>
@ -6174,6 +6245,7 @@
</trigger> </trigger>
<trigger> <trigger>
<name>openFirstDoorUndo</name> <name>openFirstDoorUndo</name>
<undo>true</undo>
<xPosition>17.5</xPosition> <xPosition>17.5</xPosition>
<yPosition>21.8</yPosition> <yPosition>21.8</yPosition>
<zPosition>159.5</zPosition> <zPosition>159.5</zPosition>
@ -6182,7 +6254,7 @@
<distance>0.2</distance> <distance>0.2</distance>
<isBiggerThan>false</isBiggerThan> <isBiggerThan>false</isBiggerThan>
<objectNum>0</objectNum> <objectNum>0</objectNum>
<luaScript>openFirstDoorUndo.lua</luaScript> <luaScript>openFirstDoor.lua</luaScript>
<toChangeIdGreen>1</toChangeIdGreen> <toChangeIdGreen>1</toChangeIdGreen>
<toChangeIdBlue>94</toChangeIdBlue> <toChangeIdBlue>94</toChangeIdBlue>
<toChangeObjNum>0</toChangeObjNum> <toChangeObjNum>0</toChangeObjNum>

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenFirstDoor == nil) then if(global.triggeredOpenFirstDoor == nil) then
global.triggeredOpenFirstDoor = false global.triggeredOpenFirstDoor = false
end end
if(global.triggeredOpenFirstDoorUndo == nil) then
global.triggeredOpenFirstDoorUndo = true
end
function trigger(objectToChange) function trigger(objectToChange)
if(global.triggeredOpenFirstDoor == false) then if(global.triggeredOpenFirstDoor == false) then
if(not level) then if(not level) then
@ -21,3 +25,23 @@ function trigger(objectToChange)
print("openFirstDoor") print("openFirstDoor")
end end
end end
function triggerUndo(objectToChange)
if(global.triggeredOpenFirstDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = 17.5
local yPos = 25
local zPos = 81.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenFirstDoor = false
global.triggeredOpenFirstDoorUndo = true
print("openFirstDoorUndo")
end
end

View File

@ -1,23 +0,0 @@
local global = require( "global" )
if(global.triggeredOpenFirstDoorUndo == nil) then
global.triggeredOpenFirstDoorUndo = true
end
function trigger(objectToChange)
if(global.triggeredOpenFirstDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = 17.5
local yPos = 25
local zPos = 81.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenFirstDoor = false
global.triggeredOpenFirstDoorUndo = true
print("openFirstDoorUndo")
end
end

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenSecondDoor1 == nil) then if(global.triggeredOpenSecondDoor1 == nil) then
global.triggeredOpenSecondDoor1 = false global.triggeredOpenSecondDoor1 = false
end end
if(global.triggeredOpenSecondDoor1Undo == nil) then
global.triggeredOpenSecondDoor1Undo = true
end
function trigger(objectToChange) function trigger(objectToChange)
if(global.triggeredOpenSecondDoor1 == false) then if(global.triggeredOpenSecondDoor1 == false) then
if(not level) then if(not level) then
@ -25,14 +29,28 @@ function trigger(objectToChange)
local zPos = 4.5 local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos) level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else else
global.openSecondDoorCounter = 0 global.triggeredOpenSecondDoor1Undo = false
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end end
end end
print("openSecondDoor1") print("openSecondDoor1")
end end
end end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor1Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor1Undo = true
print("openSecondDoor1Undo")
end
end

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenSecondDoor2 == nil) then if(global.triggeredOpenSecondDoor2 == nil) then
global.triggeredOpenSecondDoor2 = false global.triggeredOpenSecondDoor2 = false
end end
if(global.triggeredOpenSecondDoor2Undo == nil) then
global.triggeredOpenSecondDoor2Undo = true
end
function trigger(objectToChange) function trigger(objectToChange)
if(global.triggeredOpenSecondDoor2 == false) then if(global.triggeredOpenSecondDoor2 == false) then
if(not level) then if(not level) then
@ -25,14 +29,28 @@ function trigger(objectToChange)
local zPos = 4.5 local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos) level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else else
global.openSecondDoorCounter = 0 global.triggeredOpenSecondDoor2Undo = false
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end end
end end
print("openSecondDoor2") print("openSecondDoor2")
end end
end end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor2Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor2Undo = true
print("openSecondDoor2Undo")
end
end

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenSecondDoor3 == nil) then if(global.triggeredOpenSecondDoor3 == nil) then
global.triggeredOpenSecondDoor3 = false global.triggeredOpenSecondDoor3 = false
end end
if(global.triggeredOpenSecondDoor3Undo == nil) then
global.triggeredOpenSecondDoor3Undo = true
end
function trigger(objectToChange) function trigger(objectToChange)
if(global.triggeredOpenSecondDoor3 == false) then if(global.triggeredOpenSecondDoor3 == false) then
if(not level) then if(not level) then
@ -25,14 +29,28 @@ function trigger(objectToChange)
local zPos = 4.5 local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos) level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else else
global.openSecondDoorCounter = 0 global.triggeredOpenSecondDoor3Undo = false
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end end
end end
print("openSecondDoor3") print("openSecondDoor3")
end end
end end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor3Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor3Undo = true
print("openSecondDoor3Undo")
end
end

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenSecondDoor4 == nil) then if(global.triggeredOpenSecondDoor4 == nil) then
global.triggeredOpenSecondDoor4 = false global.triggeredOpenSecondDoor4 = false
end end
if(global.triggeredOpenSecondDoor4Undo == nil) then
global.triggeredOpenSecondDoor4Undo = true
end
function trigger(objectToChange) function trigger(objectToChange)
if(global.triggeredOpenSecondDoor4 == false) then if(global.triggeredOpenSecondDoor4 == false) then
if(not level) then if(not level) then
@ -25,14 +29,28 @@ function trigger(objectToChange)
local zPos = 4.5 local zPos = 4.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos) level:moveObject(objectToChange, strength, xPos, yPos, zPos)
else else
global.openSecondDoorCounter = 0 global.triggeredOpenSecondDoor4Undo = false
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
end end
end end
print("openSecondDoor4") print("openSecondDoor4")
end end
end end
function triggerUndo(objectToChange)
if(global.triggeredOpenSecondDoor4Undo == false) then
if(not level) then
print("No level found in Lua!")
return
end
global.openSecondDoorCounter = 0
global.triggeredOpenSecondDoor1 = false
global.triggeredOpenSecondDoor2 = false
global.triggeredOpenSecondDoor3 = false
global.triggeredOpenSecondDoor4 = false
global.triggeredOpenSecondDoor4Undo = true
print("openSecondDoor4Undo")
end
end

View File

@ -2,6 +2,10 @@ local global = require( "global" )
if(global.triggeredOpenThirdDoor == nil) then if(global.triggeredOpenThirdDoor == nil) then
global.triggeredOpenThirdDoor = false global.triggeredOpenThirdDoor = false
end end
if(global.triggeredOpenThirdDoorUndo == nil) then
global.triggeredOpenThirdDoorUndo = true
end
function trigger(objectToChange) function trigger(objectToChange)
if(global.triggeredOpenThirdDoor == false) then if(global.triggeredOpenThirdDoor == false) then
if(not level) then if(not level) then
@ -21,3 +25,23 @@ function trigger(objectToChange)
print("openThirdDoor") print("openThirdDoor")
end end
end end
function triggerUndo(objectToChange)
if(global.triggeredOpenThirdDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = -172.5
local yPos = 25
local zPos = 58.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenThirdDoor = false
global.triggeredOpenThirdDoorUndo = true
print("openThirdDoorUndo")
end
end

View File

@ -1,23 +0,0 @@
local global = require( "global" )
if(global.triggeredOpenThirdDoorUndo == nil) then
global.triggeredOpenThirdDoorUndo = true
end
function trigger(objectToChange)
if(global.triggeredOpenThirdDoorUndo == false) then
if(not level) then
print("No level found in Lua!")
return
end
local strength = 100
local xPos = -172.5
local yPos = 25
local zPos = 58.5
level:moveObject(objectToChange, strength, xPos, yPos, zPos)
global.triggeredOpenThirdDoor = false
global.triggeredOpenThirdDoorUndo = true
print("openThirdDoorUndo")
end
end

View File

@ -325,6 +325,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
float xPos = queryFloat(xmlTrigger, "xPosition"); float xPos = queryFloat(xmlTrigger, "xPosition");
float yPos = queryFloat(xmlTrigger, "yPosition"); float yPos = queryFloat(xmlTrigger, "yPosition");
float zPos = queryFloat(xmlTrigger, "zPosition"); float zPos = queryFloat(xmlTrigger, "zPosition");
bool undo = queryBool(xmlTrigger, "undo");
glm::vec3 position = glm::vec3(xPos, yPos, zPos); glm::vec3 position = glm::vec3(xPos, yPos, zPos);
std::string stringTarget = queryString(xmlTrigger, "targetIdGreen"); std::string stringTarget = queryString(xmlTrigger, "targetIdGreen");
if (stringTarget.compare("-") != 0){ if (stringTarget.compare("-") != 0){
@ -381,7 +382,7 @@ void Loader::load(std::string filePath, Level* level, std::string compositionsPa
printf("No Identifier found for an object that was to be changed by a trigger.\n"); printf("No Identifier found for an object that was to be changed by a trigger.\n");
} }
if (object != 0) { if (object != 0) {
Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, level->getLuaState(), objectToChange, scriptPath); Trigger trigger = Trigger(position, distance, isBigger, object, luaScript, level->getLuaState(), objectToChange, scriptPath, undo);
level->addTrigger(trigger); level->addTrigger(trigger);
} }
else { else {

View File

@ -1,7 +1,7 @@
#include "trigger.hh" #include "trigger.hh"
#include <sys/stat.h> #include <sys/stat.h>
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* luaState, int objectToChange, std::string scriptPath) { Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* luaState, int objectToChange, std::string scriptPath, bool undo) {
this->position=position; this->position=position;
this->distance=distance; this->distance=distance;
this->isBigger=isBigger; this->isBigger=isBigger;
@ -17,6 +17,7 @@ Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* obje
printf("The Lua state is NULL in trigger!\n"); printf("The Lua state is NULL in trigger!\n");
} }
this->objectToChange = objectToChange; this->objectToChange = objectToChange;
this->undo = undo;
} }
Trigger::Trigger(){ Trigger::Trigger(){
@ -28,13 +29,21 @@ Trigger::~Trigger(){
void Trigger::triggerUpdate(){ void Trigger::triggerUpdate(){
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) { if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
luaL_dofile(luaState, luaScript.c_str()); luaL_dofile(luaState, luaScript.c_str());
if (undo){
luabridge::getGlobal(luaState, "triggerUndo")(objectToChange);
}else{
luabridge::getGlobal(luaState, "trigger")(objectToChange); luabridge::getGlobal(luaState, "trigger")(objectToChange);
} }
}
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) { else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
luaL_dofile(luaState, luaScript.c_str()); luaL_dofile(luaState, luaScript.c_str());
if (undo){
luabridge::getGlobal(luaState, "triggerUndo")(objectToChange);
}else{
luabridge::getGlobal(luaState, "trigger")(objectToChange); luabridge::getGlobal(luaState, "trigger")(objectToChange);
} }
} }
}
bool Trigger::deleteNotification(int deletedObjectIndex){ bool Trigger::deleteNotification(int deletedObjectIndex){
if (deletedObjectIndex < objectToChange){ if (deletedObjectIndex < objectToChange){

View File

@ -14,7 +14,7 @@ class Level;
class Trigger { class Trigger {
public: public:
Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, std::string scriptPath); Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* L, int objectToChange, std::string scriptPath, bool undo);
Trigger(); Trigger();
~Trigger(); ~Trigger();
void triggerUpdate(); void triggerUpdate();
@ -27,6 +27,7 @@ class Trigger {
std::string luaScript; std::string luaScript;
lua_State* luaState; lua_State* luaState;
int objectToChange; int objectToChange;
bool undo;
}; };
#endif #endif