mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-04-04 08:52:00 +00:00
S_MusicName, S_MusicExists, S_PauseMusic lua, S_ResumeMusic lua
# Conflicts: # src/lua_baselib.c
This commit is contained in:
parent
eb52a14433
commit
662c366830
3 changed files with 101 additions and 0 deletions
|
@ -2275,10 +2275,41 @@ static int lib_sPositionMusic(lua_State *L)
|
|||
|
||||
static int lib_sGetPositionMusic(lua_State *L)
|
||||
{
|
||||
NOHUD
|
||||
lua_pushinteger(L, (UINT32)S_GetPositionMusic());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sPauseMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
S_PauseAudio();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sResumeMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
NOHUD
|
||||
if (!lua_isnone(L, 1) && lua_isuserdata(L, 1))
|
||||
{
|
||||
player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER));
|
||||
if (!player)
|
||||
return LUA_ErrInvalid(L, "player_t");
|
||||
}
|
||||
if (!player || P_IsLocalPlayer(player))
|
||||
S_ResumeAudio();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sStopMusic(lua_State *L)
|
||||
{
|
||||
player_t *player = NULL;
|
||||
|
@ -2339,6 +2370,49 @@ static int lib_sMusicPaused(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicName(lua_State *L)
|
||||
{
|
||||
NOHUD
|
||||
lua_pushstring(L, S_MusicName());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sMusicExists(lua_State *L)
|
||||
{
|
||||
#ifdef MUSICSLOT_COMPATIBILITY
|
||||
const char *music_name;
|
||||
UINT32 music_num;
|
||||
char music_compat_name[7];
|
||||
UINT16 music_flags = 0;
|
||||
NOHUD
|
||||
if (lua_isnumber(L, 1))
|
||||
{
|
||||
music_num = (UINT32)luaL_checkinteger(L, 1);
|
||||
music_flags = (UINT16)(music_num & 0x0000FFFF);
|
||||
if (music_flags && music_flags <= 1035)
|
||||
snprintf(music_compat_name, 7, "%sM", G_BuildMapName((INT32)music_flags));
|
||||
else if (music_flags && music_flags <= 1050)
|
||||
strncpy(music_compat_name, compat_special_music_slots[music_flags - 1036], 7);
|
||||
else
|
||||
music_compat_name[0] = 0; // becomes empty string
|
||||
music_compat_name[6] = 0;
|
||||
music_name = (const char *)&music_compat_name;
|
||||
}
|
||||
else
|
||||
{
|
||||
music_num = 0;
|
||||
music_name = luaL_checkstring(L, 1);
|
||||
}
|
||||
#else
|
||||
const char *music_name = luaL_checkstring(L, 1);
|
||||
#endif
|
||||
boolean checkMIDI = lua_opttrueboolean(L, 2);
|
||||
boolean checkDigi = lua_opttrueboolean(L, 3);
|
||||
NOHUD
|
||||
lua_pushboolean(L, S_MusicExists(music_name, checkMIDI, checkDigi));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int lib_sOriginPlaying(lua_State *L)
|
||||
{
|
||||
void *origin = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
|
||||
|
@ -2718,10 +2792,14 @@ static luaL_Reg lib[] = {
|
|||
{"S_SpeedMusic",lib_sSpeedMusic},
|
||||
{"S_PositionMusic",lib_sPositionMusic},
|
||||
{"S_GetPositionMusic",lib_sGetPositionMusic},
|
||||
{"S_PauseMusic",lib_sPauseMusic},
|
||||
{"S_ResumeMusic",lib_sResumeMusic},
|
||||
{"S_StopMusic",lib_sStopMusic},
|
||||
{"S_MidiPlaying",lib_sMidiPlaying},
|
||||
{"S_MusicPlaying",lib_sMusicPlaying},
|
||||
{"S_MusicPaused",lib_sMusicPaused},
|
||||
{"S_MusicName",lib_sMusicName},
|
||||
{"S_MusicExists",lib_sMusicExists},
|
||||
{"S_OriginPlaying",lib_sOriginPlaying},
|
||||
{"S_IdPlaying",lib_sIdPlaying},
|
||||
{"S_SoundPlaying",lib_sSoundPlaying},
|
||||
|
|
|
@ -1590,3 +1590,20 @@ boolean S_MusicPaused(void)
|
|||
{
|
||||
return I_MusicPaused();
|
||||
}
|
||||
|
||||
const char *S_MusicName(void)
|
||||
{
|
||||
// char *result[7];
|
||||
// strncpy(result, music_name, 7);
|
||||
// result[6] = 0;
|
||||
// return (const char *)&result;
|
||||
return music_name;
|
||||
}
|
||||
|
||||
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi)
|
||||
{
|
||||
return (
|
||||
(checkDigi ? W_CheckNumForName(va("O_%s", mname)) != LUMPERROR : false)
|
||||
|| (checkMIDI ? W_CheckNumForName(va("D_%s", mname)) != LUMPERROR : false)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -157,6 +157,12 @@ boolean S_MusicPlaying(void);
|
|||
// Gets music pause status
|
||||
boolean S_MusicPaused(void);
|
||||
|
||||
// Gets currently playing music name
|
||||
const char *S_MusicName(void);
|
||||
|
||||
// Checks if music name exists
|
||||
boolean S_MusicExists(const char *mname, boolean checkMIDI, boolean checkDigi);
|
||||
|
||||
//
|
||||
// Updates music & sounds
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue