mirror of
https://github.com/edubart/otclient.git
synced 2025-04-29 17:19:20 +02:00
Fix Lua errors when the client is built without the sound framework (#1142)
This commit is contained in:
parent
b37623cd86
commit
3600a9b40b
@ -1,5 +1,8 @@
|
||||
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)
|
||||
musicFilename = filename
|
||||
@ -27,12 +30,14 @@ end
|
||||
|
||||
function startup()
|
||||
-- Play startup music (The Silver Tree, by Mattias Westlund)
|
||||
musicChannel:enqueue(musicFilename, 3)
|
||||
connect(g_game, { onGameStart = function() musicChannel:stop(3) end })
|
||||
connect(g_game, { onGameEnd = function()
|
||||
g_sounds.stopAll()
|
||||
musicChannel:enqueue(musicFilename, 3)
|
||||
end })
|
||||
if musicChannel then
|
||||
musicChannel:enqueue(musicFilename, 3)
|
||||
connect(g_game, { onGameStart = function() musicChannel:stop(3) end })
|
||||
connect(g_game, { onGameEnd = function()
|
||||
g_sounds.stopAll()
|
||||
musicChannel:enqueue(musicFilename, 3)
|
||||
end })
|
||||
end
|
||||
|
||||
-- Check for startup errors
|
||||
local errtitle = nil
|
||||
@ -57,7 +62,9 @@ function init()
|
||||
onExit = exit })
|
||||
|
||||
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
|
||||
if g_window.getPlatformType() == "X11-EGL" then
|
||||
|
@ -109,8 +109,8 @@ function init()
|
||||
graphicsPanel = g_ui.loadUI('graphics')
|
||||
optionsTabBar:addTab(tr('Graphics'), graphicsPanel, '/images/optionstab/graphics')
|
||||
|
||||
audioPanel = g_ui.loadUI('audio')
|
||||
optionsTabBar:addTab(tr('Audio'), audioPanel, '/images/optionstab/audio')
|
||||
soundPanel = g_ui.loadUI('audio')
|
||||
optionsTabBar:addTab(tr('Audio'), soundPanel, '/images/optionstab/audio')
|
||||
|
||||
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)
|
||||
@ -190,17 +190,23 @@ function setOption(key, value, force)
|
||||
elseif key == 'fullscreen' then
|
||||
g_window.setFullscreen(value)
|
||||
elseif key == 'enableAudio' then
|
||||
g_sounds.setAudioEnabled(value)
|
||||
if g_sounds then
|
||||
g_sounds.setAudioEnabled(value)
|
||||
end
|
||||
if value then
|
||||
audioButton:setIcon('/images/topbuttons/audio')
|
||||
else
|
||||
audioButton:setIcon('/images/topbuttons/audio_mute')
|
||||
end
|
||||
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
|
||||
g_sounds.getChannel(SoundChannels.Music):setGain(value/100)
|
||||
audioPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
|
||||
if g_sounds then
|
||||
g_sounds.getChannel(SoundChannels.Music):setGain(value/100)
|
||||
end
|
||||
soundPanel:getChildById('musicSoundVolumeLabel'):setText(tr('Music volume: %d', value))
|
||||
elseif key == 'showLeftPanel' then
|
||||
modules.game_interface.getLeftPanel():setOn(value)
|
||||
elseif key == 'backgroundFrameRate' then
|
||||
|
Loading…
x
Reference in New Issue
Block a user