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
2 changed files with 27 additions and 14 deletions

View File

@@ -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