Fix Lua errors when the client is built without the sound framework (#1142)

This commit is contained in:
vfjpl 2021-04-02 21:35:34 +02:00 committed by GitHub
parent b37623cd86
commit 3600a9b40b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 14 deletions

View File

@ -1,5 +1,8 @@
local musicFilename = "/sounds/startup" local musicFilename = "/sounds/startup"
local musicChannel = g_sounds.getChannel(1) local musicChannel = nil
if g_sounds then
musicChannel = g_sounds.getChannel(SoundChannels.Music)
end
function setMusic(filename) function setMusic(filename)
musicFilename = filename musicFilename = filename
@ -27,12 +30,14 @@ end
function startup() function startup()
-- Play startup music (The Silver Tree, by Mattias Westlund) -- Play startup music (The Silver Tree, by Mattias Westlund)
musicChannel:enqueue(musicFilename, 3) if musicChannel then
connect(g_game, { onGameStart = function() musicChannel:stop(3) end }) musicChannel:enqueue(musicFilename, 3)
connect(g_game, { onGameEnd = function() connect(g_game, { onGameStart = function() musicChannel:stop(3) end })
g_sounds.stopAll() connect(g_game, { onGameEnd = function()
musicChannel:enqueue(musicFilename, 3) g_sounds.stopAll()
end }) musicChannel:enqueue(musicFilename, 3)
end })
end
-- Check for startup errors -- Check for startup errors
local errtitle = nil local errtitle = nil
@ -57,7 +62,9 @@ function init()
onExit = exit }) onExit = exit })
g_window.setMinimumSize({ width = 600, height = 480 }) g_window.setMinimumSize({ width = 600, height = 480 })
g_sounds.preload(musicFilename) if musicChannel then
g_sounds.preload(musicFilename)
end
-- initialize in fullscreen mode on mobile devices -- initialize in fullscreen mode on mobile devices
if g_window.getPlatformType() == "X11-EGL" then if g_window.getPlatformType() == "X11-EGL" then

View File

@ -109,8 +109,8 @@ function init()
graphicsPanel = g_ui.loadUI('graphics') graphicsPanel = g_ui.loadUI('graphics')
optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics') optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics')
audioPanel = g_ui.loadUI('audio') soundPanel = g_ui.loadUI('audio')
optionsTabBar:addTab(tr('Audio'), audioPanel, '/images/optionstab/audio') optionsTabBar:addTab(tr('Audio'), soundPanel, '/images/optionstab/audio')
optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle) optionsButton = modules.client_topmenu.addLeftButton('optionsButton', tr('Options'), '/images/topbuttons/options', toggle)
audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end) audioButton = modules.client_topmenu.addLeftButton('audioButton', tr('Audio'), '/images/topbuttons/audio', function() toggleOption('enableAudio') end)
@ -190,17 +190,23 @@ function setOption(key, value, force)
elseif key == 'fullscreen' then elseif key == 'fullscreen' then
g_window.setFullscreen(value) g_window.setFullscreen(value)
elseif key == 'enableAudio' then elseif key == 'enableAudio' then
g_sounds.setAudioEnabled(value) if g_sounds then
g_sounds.setAudioEnabled(value)
end
if value then if value then
audioButton:setIcon('/images/topbuttons/audio') audioButton:setIcon('/images/topbuttons/audio')
else else
audioButton:setIcon('/images/topbuttons/audio_mute') audioButton:setIcon('/images/topbuttons/audio_mute')
end end
elseif key == 'enableMusicSound' then elseif key == 'enableMusicSound' then
g_sounds.getChannel(SoundChannels.Music):setEnabled(value) if g_sounds then
g_sounds.getChannel(SoundChannels.Music):setEnabled(value)
end
elseif key == 'musicSoundVolume' then elseif key == 'musicSoundVolume' then
g_sounds.getChannel(SoundChannels.Music):setGain(value/100) if g_sounds then
audioPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value)) g_sounds.getChannel(SoundChannels.Music):setGain(value/100)
end
soundPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
elseif key == 'showLeftPanel' then elseif key == 'showLeftPanel' then
modules.game_interface.getLeftPanel():setOn(value) modules.game_interface.getLeftPanel():setOn(value)
elseif key == 'backgroundFrameRate' then elseif key == 'backgroundFrameRate' then