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:
parent
64406419c1
commit
eb1f38d86c
4 changed files with 80 additions and 23 deletions
|
@ -311,7 +311,7 @@ void Path::refreshScript()
|
|||
if (exists(scr))
|
||||
{
|
||||
script = dsq->scriptInterface.openScript(scr);
|
||||
updateFunction = activateFunction = true;
|
||||
updateFunction = activateFunction = !!script;
|
||||
}
|
||||
|
||||
if (label == "seting")
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue