Add theme fallback music settings
theme.cfg:
* fallback-music
* fallback-sd-music
--- a/ChangeLog.txt Wed Feb 07 05:36:32 2018 +0100
+++ b/ChangeLog.txt Wed Feb 07 07:38:37 2018 +0100
@@ -14,6 +14,9 @@
+ Mission 3: Display number of turns left at timed parcours
* Fix incorrect storytelling in mission descriptions
+Theme customization:
+ + Add fallback music with fallback-music and fallback-sd-music
+
Lua API:
+ New call: WriteLnToChat(string): Add a line in the chat
* Fix call: SetWeapon(amNothing) now unselects weapon
--- a/hedgewars/uLandObjects.pas Wed Feb 07 05:36:32 2018 +0100
+++ b/hedgewars/uLandObjects.pas Wed Feb 07 07:38:37 2018 +0100
@@ -672,6 +672,10 @@
MusicFN:= Trim(s)
else if key = 'sd-music' then
SDMusicFN:= Trim(s)
+ else if key = 'fallback-music' then
+ FallbackMusicFN:= Trim(s)
+ else if key = 'fallback-sd-music' then
+ FallbackSDMusicFN:= Trim(s)
else if key = 'clouds' then
begin
cCloudsNumber:= Word(StrToInt(Trim(s))) * cScreenSpace div 4096;
--- a/hedgewars/uSound.pas Wed Feb 07 05:36:32 2018 +0100
+++ b/hedgewars/uSound.pas Wed Feb 07 07:38:37 2018 +0100
@@ -106,6 +106,8 @@
var MusicFN: shortstring; // music file name
SDMusicFN: shortstring; // SD music file name
+ FallbackMusicFN: shortstring; // fallback music file name
+ FallbackSDMusicFN: shortstring; // fallback SD music fille name
var Volume: LongInt;
SoundTimerTicks: Longword;
@@ -632,9 +634,35 @@
else s:= '/Music/' + MusicFN;
WriteToConsole(msgLoading + s + ' ');
+ // Load normal music
Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
SDLCheck(Mus <> nil, 'Mix_LoadMUS_RW', false);
- WriteLnToConsole(msgOK);
+ if Mus <> nil then
+ WriteLnToConsole(msgOK);
+
+ // If normal music failed, try to get fallback music
+ if Mus = nil then
+ begin
+ WriteLnToConsole('Music not found. Trying fallback music.');
+ if SuddenDeath and (FallbackSDMusicFN <> '') then
+ s:= '/Music/' + FallbackSDMusicFN
+ else if (not SuddenDeath) and (FallbackMusicFN <> '') then
+ s:= '/Music/' + FallbackMusicFN
+ else
+ begin
+ WriteLnToConsole('No fallback music configured!');
+ s:= ''
+ end;
+
+ if (s <> '') then
+ begin
+ WriteLnToConsole(msgLoading + s + ' ');
+ Mus:= Mix_LoadMUS_RW(rwopsOpenRead(s));
+ SDLCheck(Mus <> nil, 'Mix_LoadMUS_RW', false);
+ if Mus <> nil then
+ WriteLnToConsole(msgOK)
+ end;
+ end;
SDLCheck(Mix_FadeInMusic(Mus, -1, 3000) <> -1, 'Mix_FadeInMusic', false)
end;