diff --git a/jail_audio.cpp b/jail_audio.cpp index c537192..7f8c784 100644 --- a/jail_audio.cpp +++ b/jail_audio.cpp @@ -308,6 +308,10 @@ void JA_EnableMusic(const bool value) JA_musicEnabled = value; } +const bool JA_IsMusicEnabled() +{ + return JA_musicEnabled; +} @@ -488,6 +492,11 @@ void JA_EnableSound(const bool value) JA_soundEnabled = value; } +const bool JA_IsSoundEnabled() +{ + return JA_soundEnabled; +} + float JA_SetVolume(float volume) { JA_SetSoundVolume(JA_SetMusicVolume(volume) / 2.0f); diff --git a/jail_audio.h b/jail_audio.h index 53e1a0f..e145161 100644 --- a/jail_audio.h +++ b/jail_audio.h @@ -23,6 +23,7 @@ float JA_SetMusicVolume(float volume); void JA_SetMusicPosition(float value); float JA_GetMusicPosition(); void JA_EnableMusic(const bool value); +const bool JA_IsMusicEnabled(); JA_Sound_t *JA_NewSound(Uint8* buffer, Uint32 length); JA_Sound_t *JA_LoadSound(Uint8* buffer, Uint32 length); @@ -36,5 +37,6 @@ JA_Channel_state JA_GetChannelState(const int channel); void JA_DeleteSound(JA_Sound_t *sound); float JA_SetSoundVolume(float volume); void JA_EnableSound(const bool value); +const bool JA_IsSoundEnabled(); float JA_SetVolume(float volume); diff --git a/lua.cpp b/lua.cpp index d091504..d255cba 100644 --- a/lua.cpp +++ b/lua.cpp @@ -584,6 +584,16 @@ extern "C" { } } + static int cpp_music_enable(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, ismusicenabled()); + return 1; + } else { + enablemusic(lua_toboolean(L, 1)); + return 0; + } + } + // sound // =============================================== @@ -613,6 +623,16 @@ extern "C" { return 0; } + static int cpp_sound_enable(lua_State *L) { + if (lua_gettop(L) == 0) { + lua_pushboolean(L, issoundenabled()); + return 1; + } else { + enablesound(lua_toboolean(L, 1)); + return 0; + } + } + // sys // =============================================== @@ -913,6 +933,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_music_resume); lua_setfield(L, -2, "resume"); lua_pushcfunction(L,cpp_music_stop); lua_setfield(L, -2, "stop"); lua_pushcfunction(L,cpp_music_pos); lua_setfield(L, -2, "pos"); + lua_pushcfunction(L,cpp_music_enable); lua_setfield(L, -2, "enabled"); lua_setglobal(L, "music"); lua_newtable(L); @@ -920,6 +941,7 @@ void push_lua_funcs() { lua_pushcfunction(L,cpp_sound_free); lua_setfield(L, -2, "free"); lua_pushcfunction(L,cpp_sound_play); lua_setfield(L, -2, "play"); lua_pushcfunction(L,cpp_sound_stop); lua_setfield(L, -2, "stop"); + lua_pushcfunction(L,cpp_sound_enable); lua_setfield(L, -2, "enabled"); lua_setglobal(L, "sound"); lua_newtable(L); diff --git a/mini.cpp b/mini.cpp index f716870..cb50939 100644 --- a/mini.cpp +++ b/mini.cpp @@ -410,6 +410,10 @@ int main(int argc,char*argv[]){ if (fullscreen) screen_fullscreen=strcmp(fullscreen, "true")==0?true:false; const char *cursor = file_getconfigvalue("cursor"); if (cursor) screen_cursor=strcmp(cursor, "true")?true:false; + const char *music_enabled = file_getconfigvalue("music"); + if (music_enabled) JA_EnableMusic(strcmp(music_enabled, "true")==0?true:false); + const char *sound_enabled = file_getconfigvalue("sound"); + if (sound_enabled) JA_EnableSound(strcmp(sound_enabled, "true")==0?true:false); } setdest(newsurf(screen_width, screen_height)); @@ -1255,6 +1259,18 @@ float musicpos() return JA_GetMusicPosition(); } +void enablemusic(const bool value) +{ + JA_EnableMusic(value); + file_setconfigvalue("music", value?"true":"false"); +} + +const bool ismusicenabled() +{ + return JA_IsMusicEnabled(); +} + + int loadsound(const char *filename) { int size; char *buffer = file_getfilebuffer(filename, size); @@ -1282,6 +1298,17 @@ void stopsound(int soundchannel) { //Mix_HaltChannel(soundchannel); } +void enablesound(const bool value) +{ + JA_EnableSound(value); + file_setconfigvalue("sound", value?"true":"false"); +} + +const bool issoundenabled() +{ + return JA_IsSoundEnabled(); +} + int getzoom() { return screen_zoom; } diff --git a/mini.h b/mini.h index 4a15927..5db27ea 100644 --- a/mini.h +++ b/mini.h @@ -235,11 +235,15 @@ void resumemusic(); void stopmusic(const int t=1000); void musicpos(float value); float musicpos(); +void enablemusic(const bool value); +const bool ismusicenabled(); int loadsound(const char *filename); void freesound(int soundfile); int playsound(int soundfile, const int volume=-1); void stopsound(int soundchannel); +void enablesound(const bool value); +const bool issoundenabled(); int getzoom(); void setzoom(const int value); diff --git a/version.h b/version.h index 24fb37a..69f02a7 100644 --- a/version.h +++ b/version.h @@ -1,3 +1,3 @@ #pragma once -#define MINI_VERSION "1.3.6" +#define MINI_VERSION "1.3.7" diff --git a/vscode/library.lua b/vscode/library.lua index ddddd43..a6a7fd3 100644 --- a/vscode/library.lua +++ b/vscode/library.lua @@ -325,6 +325,15 @@ function music.pos() end ---Set the playing position of the currently loaded song function music.pos(pos) end +---@return boolean value +---Get if music is enabled +function music.enabled() end + +---@param value boolean +---Set if music is enabled or not +function music.enabled(value) end + + ---@class sound sound = {} @@ -352,6 +361,14 @@ function sound.play(snd, loop) end ---Stop the channel specified function sound.stop(chl) end +---@return boolean value +---Get if sound is enabled +function sound.enabled() end + +---@param value boolean +---Set if sound is enabled or not +function sound.enabled(value) end + ---@class sys sys = {}