mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-06 01:57:14 +00:00
Support mflags and looping in MusicChange hook
# Conflicts: # src/lua_hook.h
This commit is contained in:
parent
d14eedd700
commit
34ea90600a
3 changed files with 19 additions and 8 deletions
|
@ -88,6 +88,6 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8
|
|||
#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // Hook for P_XYMovement (when movement is blocked)
|
||||
boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing); // Hook for P_SpawnMapThing by mobj type
|
||||
boolean LUAh_FollowMobj(player_t *player, mobj_t *mo); // Hook for P_PlayerAfterThink Smiles mobj-following
|
||||
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic); // Hook for music changes
|
||||
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping); // Hook for music changes
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1193,7 +1193,7 @@ boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
|
|||
return hooked;
|
||||
}
|
||||
// Hook for music changes
|
||||
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic) // UINT16 mflags, boolean looping)
|
||||
boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusic, UINT16 *mflags, boolean *looping)
|
||||
{
|
||||
hook_p hookp;
|
||||
boolean hooked = false;
|
||||
|
@ -1212,16 +1212,27 @@ boolean LUAh_MusicChange(const char *oldname, const char *newname, char *newmusi
|
|||
lua_gettable(gL, LUA_REGISTRYINDEX);
|
||||
lua_pushstring(gL, oldname);
|
||||
lua_pushstring(gL, newname);
|
||||
if (lua_pcall(gL, 2, 1, 0)) {
|
||||
lua_pushinteger(gL, *mflags);
|
||||
lua_pushboolean(gL, *looping);
|
||||
if (lua_pcall(gL, 4, 3, 0)) {
|
||||
CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL,-1));
|
||||
lua_pop(gL, 1);
|
||||
continue;
|
||||
}
|
||||
if (lua_isboolean(gL, -1) && lua_toboolean(gL, -1))
|
||||
|
||||
// output 1: true, false, or string musicname override
|
||||
if (lua_isboolean(gL, -3) && lua_toboolean(gL, -3))
|
||||
hooked = true;
|
||||
else if (lua_isstring(gL, -1))
|
||||
strncpy(newmusic, lua_tostring(gL, -1), 7);
|
||||
lua_pop(gL, 1);
|
||||
else if (lua_isstring(gL, -3))
|
||||
strncpy(newmusic, lua_tostring(gL, -3), 7);
|
||||
// output 2: hook override
|
||||
if (lua_isnumber(gL, -2))
|
||||
*mflags = lua_tonumber(gL, -2);
|
||||
// output 3: looping override
|
||||
if (lua_isboolean(gL, -1))
|
||||
*looping = lua_toboolean(gL, -1);
|
||||
|
||||
lua_pop(gL, 3);
|
||||
}
|
||||
|
||||
lua_settop(gL, 0);
|
||||
|
|
|
@ -1386,7 +1386,7 @@ void S_ChangeMusic(const char *mmusic, UINT16 mflags, boolean looping)
|
|||
|
||||
char newmusic[7];
|
||||
#ifdef HAVE_BLUA
|
||||
if(LUAh_MusicChange(music_name, mmusic, newmusic)) // todo: mflags and looping?
|
||||
if(LUAh_MusicChange(music_name, mmusic, newmusic, &mflags, &looping))
|
||||
return;
|
||||
#else
|
||||
strncpy(newmusic, mmusic, 7);
|
||||
|
|
Loading…
Reference in a new issue