Fix Lua errors when failing to set a music track on an empty playlist

Closes #3194.

(cherry-picked from commit 5871557dbf)
This commit is contained in:
Iris Morelle 2018-06-09 18:53:18 -04:00
parent 90cc4569a7
commit e68bdd1b5f
2 changed files with 11 additions and 2 deletions

View file

@ -245,6 +245,9 @@
be initially selected in the Unit Attack dialog. This bug also had the
potential to cause units to the wrong attack when engaging or viewing
damage calculations.
* Fixed Lua errors when setting a music track that cannot be found when the
playlist is already empty, e.g. if there's no music installed for the
game (issue #3194).
## Version 1.13.12
### Security fixes

View file

@ -277,17 +277,23 @@ function wml_actions.music(cfg)
wesnoth.music_list.play(cfg.name)
else
if not cfg.append then
if cfg.immediate then
if cfg.immediate and wesnoth.music_list.current_i then
wesnoth.music_list.current.once = true
end
wesnoth.music_list.clear()
end
local m = #wesnoth.music_list
wesnoth.music_list.add(cfg.name, not not cfg.immediate, cfg.ms_before or 0, cfg.ms_after or 0)
local n = #wesnoth.music_list
if n == 0 then
return
end
if cfg.shuffle == false then
wesnoth.music_list[n].shuffle = false
end
if cfg.title ~= nil then
-- Always overwrite shuffle even if the new track couldn't be added,
-- but title shouldn't be overwritten.
if cfg.title ~= nil and m ~= n then
wesnoth.music_list[n].title = cfg.title
end
end