1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-29 03:33:48 +00:00

Minor script interface cleanup and prep for next commit

This commit is contained in:
fgenesis 2017-11-01 19:25:19 +01:00
parent 64406419c1
commit eb1f38d86c
4 changed files with 80 additions and 23 deletions

View file

@ -311,7 +311,7 @@ void Path::refreshScript()
if (exists(scr)) if (exists(scr))
{ {
script = dsq->scriptInterface.openScript(scr); script = dsq->scriptInterface.openScript(scr);
updateFunction = activateFunction = true; updateFunction = activateFunction = !!script;
} }
if (label == "seting") if (label == "seting")

View file

@ -109,6 +109,7 @@ static const char * const interfaceFunctions[] = {
"songNote", "songNote",
"songNoteDone", "songNoteDone",
"sporesDropped", "sporesDropped",
"targetDied",
"update", "update",
"useIngredient", "useIngredient",
"useTreasure", "useTreasure",
@ -12002,6 +12003,42 @@ bool Script::call(const char *name, void *param1, void *param2, void *param3, fl
return true; 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) bool Script::call(const char *name, const char *param, bool *ret)
{ {
lookupFunc(name); lookupFunc(name);
@ -12067,3 +12104,34 @@ int Script::pushLocalVars(lua_State *Ltarget)
pushLocalVarTab(Ltarget, L); pushLocalVarTab(Ltarget, L);
return 1; 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";
}

View file

@ -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); 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) // boolean = function(string)
bool call(const char *name, const char *param, bool *ret); 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) // string = function(string)
bool call(const char *name, const char *param, std::string *ret); bool call(const char *name, const char *param, std::string *ret);
// string = function(string, string, string) // string = function(string, string, string)
@ -105,6 +111,8 @@ public:
bool runScript(const std::string &file, const std::string &func, bool ignoremissing = false); 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); bool runScriptNum(const std::string &file, const std::string &func, int num);
static std::string MakeScriptFileName(const std::string& name, const char *subdir);
protected: protected:
lua_State *createLuaVM(); lua_State *createLuaVM();
void destroyLuaVM(lua_State *state); void destroyLuaVM(lua_State *state);

View file

@ -50,29 +50,10 @@ ScriptedEntity::ScriptedEntity(const std::string &scriptName, Vector position, E
reverseSegments = false; reverseSegments = false;
manaBallAmount = 1; manaBallAmount = 1;
this->name = scriptName; this->name = scriptName;
if(scriptName.length() && scriptName[0] == '@')
this->name = this->name.substr(1, this->name.size());
std::string file; std::string file = ScriptInterface::MakeScriptFileName(scriptName, "entities");
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";
}
}
script = dsq->scriptInterface.openScript(file); script = dsq->scriptInterface.openScript(file);
if (!script) if (!script)
{ {