1
0
Fork 0
mirror of https://github.com/AquariaOSE/Aquaria.git synced 2024-11-15 05:59:16 +00:00

Implement node messaging (node_msg() function); there is no reason entities have this but nodes do not.

Also made node script error messages a bit nicer.
This commit is contained in:
fgenesis 2013-07-12 03:07:40 +02:00
parent 3ad6eedd37
commit 76cfa6fe33
3 changed files with 41 additions and 7 deletions

View file

@ -235,7 +235,7 @@ void Path::song(SongType songType)
if (!script->call("song", this, int(songType)))
{
songFunc = false;
debugLog("Path [" + name + "] " + script->getLastError());
luaDebugMsg("song", script->getLastError());
}
}
}
@ -247,7 +247,7 @@ void Path::songNote(int note)
if (!script->call("songNote", this, note))
{
songNoteFunc = false;
debugLog("Path [" + name + "] " + script->getLastError() + " songNote");
luaDebugMsg("songNote", script->getLastError());
}
}
}
@ -259,7 +259,7 @@ void Path::songNoteDone(int note, float len)
if (!script->call("songNoteDone", this, note, len))
{
songNoteDoneFunc = false;
debugLog("Path [" + name + "] " + script->getLastError() + " songNoteDone");
luaDebugMsg("songNoteDone", script->getLastError());
}
}
}
@ -472,7 +472,7 @@ void Path::init()
{
if (!script->call("init", this))
{
debugLog(name + " : " + script->getLastError() + " init");
luaDebugMsg("init", script->getLastError());
}
}
}
@ -495,7 +495,7 @@ void Path::update(float dt)
{
if (!script->call("update", this, dt))
{
debugLog(name + " : " + script->getLastError() + " update");
luaDebugMsg("update", script->getLastError());
updateFunction = false;
}
}
@ -641,7 +641,7 @@ bool Path::action(int id, int state)
{
bool dontRemove = true;
if (!script->call("action", this, id, state, &dontRemove))
debugLog(name + " : " + script->getLastError() + " action");
luaDebugMsg("action", script->getLastError());
return dontRemove;
}
return true;
@ -653,7 +653,7 @@ void Path::activate(Entity *e)
{
if (!script->call("activate", this, e))
{
debugLog(name + " : " + script->getLastError() + " activate");
luaDebugMsg("activate", script->getLastError());
activateFunction = false;
}
}
@ -704,3 +704,20 @@ void Path::addNode(int idx)
}
}
int Path::messageVariadic(lua_State *L, int nparams)
{
if (script)
{
int res = script->callVariadic("msg", L, nparams, this);
if (res < 0)
luaDebugMsg("msg", script->getLastError());
else
return res;
}
return 0;
}
void Path::luaDebugMsg(const std::string &func, const std::string &msg)
{
debugLog("luaScriptError: Path [" + name + "]: " + func + " : " + msg);
}

View file

@ -149,6 +149,9 @@ public:
void parseWarpNodeData(const std::string &dataString);
int messageVariadic(lua_State *L, int nparams);
void luaDebugMsg(const std::string &func, const std::string &msg);
};
#endif

View file

@ -4785,6 +4785,19 @@ luaFunc(entity_msg)
luaReturnNil();
}
luaFunc(node_msg)
{
Path *p = path(L);
if (p)
{
// pass everything on the stack except the entity pointer
int res = p->messageVariadic(L, lua_gettop(L) - 1);
if (res >= 0)
return res;
}
luaReturnNil();
}
luaFunc(entity_updateCurrents)
{
Entity *e = entity(L);
@ -8335,6 +8348,7 @@ static const struct {
luaRegister(entity_getMaxHealth),
luaRegister(entity_pushTarget),
luaRegister(entity_msg),
luaRegister(node_msg),
luaRegister(entity_updateMovement),
luaRegister(entity_updateCurrents),
luaRegister(entity_updateLocalWarpAreas),