aggregate music credits into a single file (individual files can still be used to override. useful for .hwp etc.)
authorsheepluva
Fri, 29 Apr 2016 18:18:32 +0200
changeset 11775 ee85798d6974
parent 11774 04d7aa06ede2
child 11776 f2031643fe98
aggregate music credits into a single file (individual files can still be used to override. useful for .hwp etc.)
hedgewars/uSound.pas
hedgewars/uUtils.pas
share/hedgewars/Data/Music/CMakeLists.txt
share/hedgewars/Data/Music/City.ogg_credits.txt
share/hedgewars/Data/Music/Compost.ogg_credits.txt
share/hedgewars/Data/Music/EarthRise.ogg_credits.txt
share/hedgewars/Data/Music/Rock.ogg_credits.txt
share/hedgewars/Data/Music/credits.txt
share/hedgewars/Data/Music/oriental.ogg_credits.txt
share/hedgewars/Data/Music/sdmusic.ogg_credits.txt
share/hedgewars/Data/Music/snow.ogg_credits.txt
--- a/hedgewars/uSound.pas	Fri Apr 29 15:10:27 2016 +0200
+++ b/hedgewars/uSound.pas	Fri Apr 29 18:18:32 2016 +0200
@@ -582,7 +582,16 @@
     WriteLnToConsole(msgOK);
 
     // display music credits
-    s:= read1stLn(s + '_credits.txt');
+    s:= s + '_credits.txt';
+
+    // if per-file credits not found check general music credits file
+    if pfsExists(s) then
+        s:= read1stLn(s)
+    else if SuddenDeath and (SDMusicFN <> '') then
+        s:= readValueFromINI(SDMusicFN, '/Music/credits.txt')
+    else
+        s:= readValueFromINI(MusicFN, '/Music/credits.txt');
+
     if Length(s) > 0 then
         AddChatString(char(2) + '© Music: ' + s);
 
--- a/hedgewars/uUtils.pas	Fri Apr 29 15:10:27 2016 +0200
+++ b/hedgewars/uUtils.pas	Fri Apr 29 18:18:32 2016 +0200
@@ -71,6 +71,7 @@
 function  GetLaunchY(at: TAmmoType; angle: LongInt): LongInt;
 
 function read1stLn(filePath: shortstring): shortstring;
+function readValueFromINI(key, filePath: shortstring): shortstring;
 
 {$IFNDEF PAS2C}
 procedure Write(var f: textfile; s: shortstring);
@@ -527,6 +528,37 @@
         end;
 end;
 
+function readValueFromINI(key, filePath: shortstring): shortstring;
+var f: pfsFile;
+	s: shortstring;
+	i: LongInt;
+begin
+    s:= '';
+	readValueFromINI:= '';
+
+    if pfsExists(filePath) then
+        begin
+        f:= pfsOpenRead(filePath);
+
+        while (not pfsEOF(f)) and allOK do
+			begin pfsReadLn(f, s);
+			if Length(s) = 0 then
+				continue;
+			if s[1] = ';' then
+				continue;
+
+			i:= Pos('=', s);
+			if Trim(Copy(s, 1, Pred(i))) = key then
+				begin
+				Delete(s, 1, i);
+				readValueFromINI:= s;
+				end;
+			end;
+        pfsClose(f);
+        f:= nil;
+        end;
+end;
+
 procedure initModule(isNotPreview: boolean);
 {$IFDEF DEBUGFILE}
 var logfileBase: shortstring;
--- a/share/hedgewars/Data/Music/CMakeLists.txt	Fri Apr 29 15:10:27 2016 +0200
+++ b/share/hedgewars/Data/Music/CMakeLists.txt	Fri Apr 29 18:18:32 2016 +0200
@@ -1,7 +1,7 @@
 file(GLOB BaseMusic *.ogg)
-file(GLOB MusicCredits *_credits.txt)
 
 install(FILES
     ${BaseMusic}
     ${MusicCredits}
+    credits.txt
     DESTINATION ${SHAREPATH}Data/Music)
--- a/share/hedgewars/Data/Music/City.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-HSR ( http://elhombresinremedio.com )
\ No newline at end of file
--- a/share/hedgewars/Data/Music/Compost.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-HG
\ No newline at end of file
--- a/share/hedgewars/Data/Music/EarthRise.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Jonatan Nilsson
\ No newline at end of file
--- a/share/hedgewars/Data/Music/Rock.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-HSR ( http://elhombresinremedio.com )
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/share/hedgewars/Data/Music/credits.txt	Fri Apr 29 18:18:32 2016 +0200
@@ -0,0 +1,7 @@
+City.ogg=HSR ( http://elhombresinremedio.com )
+Compost.ogg=HG
+EarthRise.ogg=Jonatan Nilsson
+oriental.ogg=Jonatan Nilsson
+Rock.ogg=HSR ( http://elhombresinremedio.com )
+sdmusic.ogg=Kevin MacLeod - "Hitman" [sheepluva edit]
+snow.ogg=Jonatan Nilsson
--- a/share/hedgewars/Data/Music/oriental.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Jonatan Nilsson
\ No newline at end of file
--- a/share/hedgewars/Data/Music/sdmusic.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Kevin MacLeod - "Hitman" [sheepluva edit]
\ No newline at end of file
--- a/share/hedgewars/Data/Music/snow.ogg_credits.txt	Fri Apr 29 15:10:27 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-Jonatan Nilsson
\ No newline at end of file