2014-12-15 12:36:04 +00:00
|
|
|
#include "trigger.hh"
|
|
|
|
|
2015-02-15 18:37:13 +00:00
|
|
|
Trigger::Trigger(glm::vec3 position, float distance, bool isBigger, Object* object, std::string luaScript, lua_State* luaState, int objectToChange, std::string scriptPath) {
|
2014-12-15 13:59:03 +00:00
|
|
|
this->position=position;
|
|
|
|
this->distance=distance;
|
|
|
|
this->isBigger=isBigger;
|
|
|
|
this->object=object;
|
2015-02-15 18:34:15 +00:00
|
|
|
this->luaScript= scriptPath + luaScript;
|
2015-02-15 18:37:13 +00:00
|
|
|
this->luaState = luaState;
|
|
|
|
if(luaState == nullptr){
|
|
|
|
printf("The Lua state is NULL in trigger!\n");
|
2015-01-09 15:51:28 +00:00
|
|
|
}
|
2015-01-13 12:52:22 +00:00
|
|
|
this->objectToChange = objectToChange;
|
2014-12-15 12:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Trigger::Trigger(){
|
|
|
|
}
|
|
|
|
|
|
|
|
Trigger::~Trigger(){
|
|
|
|
}
|
2014-12-15 13:59:03 +00:00
|
|
|
|
|
|
|
void Trigger::triggerUpdate(){
|
2015-01-09 15:51:28 +00:00
|
|
|
if (isBigger && (glm::distance(object->getPosition(), position) > distance)) {
|
2015-02-15 18:37:13 +00:00
|
|
|
luaL_dofile(luaState, luaScript.c_str());
|
|
|
|
luabridge::getGlobal(luaState, "trigger")(objectToChange);
|
2015-01-09 15:51:28 +00:00
|
|
|
}
|
|
|
|
else if (!isBigger && (glm::distance(object->getPosition(), position) < distance)) {
|
2015-02-15 18:37:13 +00:00
|
|
|
luaL_dofile(luaState, luaScript.c_str());
|
|
|
|
luabridge::getGlobal(luaState, "trigger")(objectToChange);
|
2015-01-09 15:51:28 +00:00
|
|
|
}
|
2014-12-16 11:40:30 +00:00
|
|
|
}
|
2015-01-13 17:18:13 +00:00
|
|
|
|
|
|
|
bool Trigger::deleteNotification(int deletedObjectIndex){
|
|
|
|
if (deletedObjectIndex < objectToChange){
|
|
|
|
objectToChange-=1;
|
|
|
|
}
|
|
|
|
if (deletedObjectIndex == objectToChange){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|