diff --git a/Aquaria/Path.cpp b/Aquaria/Path.cpp index 8f1b6df..2caef69 100644 --- a/Aquaria/Path.cpp +++ b/Aquaria/Path.cpp @@ -311,7 +311,7 @@ void Path::refreshScript() if (exists(scr)) { script = dsq->scriptInterface.openScript(scr); - updateFunction = activateFunction = true; + updateFunction = activateFunction = !!script; } if (label == "seting") diff --git a/Aquaria/ScriptInterface.cpp b/Aquaria/ScriptInterface.cpp index 73be74b..6a9b9da 100644 --- a/Aquaria/ScriptInterface.cpp +++ b/Aquaria/ScriptInterface.cpp @@ -109,6 +109,7 @@ static const char * const interfaceFunctions[] = { "songNote", "songNoteDone", "sporesDropped", + "targetDied", "update", "useIngredient", "useTreasure", @@ -12002,6 +12003,42 @@ bool Script::call(const char *name, void *param1, void *param2, void *param3, fl return true; } +bool Script::call(const char *name, void *param1, bool *ret1) +{ + lookupFunc(name); + luaPushPointer(L, param1); + if (!doCall(1, 1)) + return false; + *ret1 = lua_toboolean(L, -1); + lua_pop(L, 1); + return true; +} + +bool Script::call(const char *name, void *param1, bool param2, bool *ret1) +{ + lookupFunc(name); + luaPushPointer(L, param1); + lua_pushboolean(L, param2); + if (!doCall(2, 1)) + return false; + *ret1 = lua_toboolean(L, -1); + lua_pop(L, 1); + return true; +} + +bool Script::call(const char *name, void *param1, void *param2, bool *ret1) +{ + lookupFunc(name); + luaPushPointer(L, param1); + luaPushPointer(L, param2); + if (!doCall(2, 1)) + return false; + *ret1 = lua_toboolean(L, -1); + lua_pop(L, 1); + return true; +} + + bool Script::call(const char *name, const char *param, bool *ret) { lookupFunc(name); @@ -12067,3 +12104,34 @@ int Script::pushLocalVars(lua_State *Ltarget) pushLocalVarTab(Ltarget, L); return 1; } + +std::string ScriptInterface::MakeScriptFileName(const std::string& name, const char *subdir) +{ + if(name.empty()) + return name; + + std::string file; + + if (name[0]=='@' && dsq->mod.isActive()) + { + file = dsq->mod.getPath() + "scripts/" + name.substr(1, name.size()) + ".lua"; + return file; + } + else if (dsq->mod.isActive()) + { + file = dsq->mod.getPath() + "scripts/" + name + ".lua"; + if(exists(file)) + return file; + } + + if(subdir && *subdir) + { + std::ostringstream os; + os << "scripts/" << subdir << "/" << name << ".lua"; + file = os.str(); + if(exists(file)) + return file; + } + + return "scripts/" + name + ".lua"; +} diff --git a/Aquaria/ScriptInterface.h b/Aquaria/ScriptInterface.h index 5e0f70b..c20a496 100644 --- a/Aquaria/ScriptInterface.h +++ b/Aquaria/ScriptInterface.h @@ -65,6 +65,12 @@ public: bool call(const char *name, void *param1, void *param2, void *param3, float param4, float param5, float param6, float param7, void *param8, bool *ret1); // boolean = function(string) bool call(const char *name, const char *param, bool *ret); + // boolean = function(pointer) + bool call(const char *name, void *param1, bool *ret1); + // boolean = function(pointer, bool) + bool call(const char *name, void *param1, bool param2, bool *ret1); + // boolean = function(pointer, pointer) + bool call(const char *name, void *param1, void *param2, bool *ret1); // string = function(string) bool call(const char *name, const char *param, std::string *ret); // string = function(string, string, string) @@ -105,6 +111,8 @@ public: bool runScript(const std::string &file, const std::string &func, bool ignoremissing = false); bool runScriptNum(const std::string &file, const std::string &func, int num); + static std::string MakeScriptFileName(const std::string& name, const char *subdir); + protected: lua_State *createLuaVM(); void destroyLuaVM(lua_State *state); diff --git a/Aquaria/ScriptedEntity.cpp b/Aquaria/ScriptedEntity.cpp index 0beec25..1c9cabd 100644 --- a/Aquaria/ScriptedEntity.cpp +++ b/Aquaria/ScriptedEntity.cpp @@ -50,29 +50,10 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E reverseSegments = false; manaBallAmount = 1; this->name = scriptName; + if(scriptName.length() && scriptName[0] == '@') + this->name = this->name.substr(1, this->name.size()); - std::string file; - if (!scriptName.empty()) - { - if (scriptName[0]=='@' && dsq->mod.isActive()) - { - file = dsq->mod.getPath() + "scripts/" + scriptName.substr(1, scriptName.size()) + ".lua"; - this->name = scriptName.substr(1, scriptName.size()); - } - else if (dsq->mod.isActive()) - { - file = dsq->mod.getPath() + "scripts/" + scriptName + ".lua"; - - if (!exists(file)) - { - file = "scripts/entities/" + scriptName + ".lua"; - } - } - else - { - file = "scripts/entities/" + scriptName + ".lua"; - } - } + std::string file = ScriptInterface::MakeScriptFileName(scriptName, "entities"); script = dsq->scriptInterface.openScript(file); if (!script) {