Load default clan colors from settings file
authorWuzzy <Wuzzy2@mail.ru>
Wed, 01 Aug 2018 21:30:33 +0200
changeset 13586 41e0446fb254
parent 13585 72515cd20984
child 13587 818134c33f54
Load default clan colors from settings file
ChangeLog.txt
hedgewars/hwengine.pas
hedgewars/uStore.pas
--- a/ChangeLog.txt	Wed Aug 01 18:17:10 2018 +0200
+++ b/ChangeLog.txt	Wed Aug 01 21:30:33 2018 +0200
@@ -7,6 +7,7 @@
  + Add default controls for controller (see README.md)
  + Add chat command “/help”, displays help for chat commands
  + Increase hedgehog limit to 64
+ + Campaigns and missions now use the user's chosen custom clan colors
  * Functionality of controllers restored
  * Fix crash when 2 or more controllers were connected
  * Fix hammer and pickhammer not digging correctly at wrap world edge
--- a/hedgewars/hwengine.pas	Wed Aug 01 18:17:10 2018 +0200
+++ b/hedgewars/hwengine.pas	Wed Aug 01 21:30:33 2018 +0200
@@ -411,6 +411,7 @@
 
     LoadFonts();
     AddProgress();
+    LoadDefaultClanColors(cPathz[ptConfig] + '/settings.ini');
 
     if cTestLua then
         begin
--- a/hedgewars/uStore.pas	Wed Aug 01 18:17:10 2018 +0200
+++ b/hedgewars/uStore.pas	Wed Aug 01 21:30:33 2018 +0200
@@ -45,6 +45,8 @@
 procedure LoadHedgehogHat(var HH: THedgehog; newHat: shortstring);
 procedure LoadHedgehogHat2(var HH: THedgehog; newHat: shortstring; allowSurfReuse: boolean);
 
+procedure LoadDefaultClanColors(s: shortstring);
+
 procedure InitZoom(zoom: real);
 
 procedure SetupOpenGL;
@@ -765,6 +767,78 @@
         end;
 end;
 
+// Load default clan colors from config fiile
+procedure LoadDefaultClanColors(s: shortstring);
+var i: LongInt;
+    f: PFSFile;
+    key, value, l, temp: shortstring;
+    color: Longword;
+    c: byte;
+begin
+    if cOnlyStats then exit;
+
+    WriteLnToConsole('Loading default clan colors from: ' + s);
+
+    l:= '';
+    if pfsExists(s) then
+        begin
+        f:= pfsOpenRead(s);
+        while (not pfsEOF(f)) and (l <> '[colors]') do
+            pfsReadLn(f, l);
+
+        while (not pfsEOF(f)) and (l <> '') do
+            begin
+            pfsReadLn(f, l);
+
+            key:= '';
+            i:= 1;
+            while (i <= length(l)) and (l[i] <> '=') do
+                begin
+                key:= key + l[i];
+                inc(i)
+                end;
+            temp:= copy(key, 1, 5);
+            if temp = 'color' then
+                begin
+                temp:= copy(key, 6, length(key) - 5);
+                try
+                    c:= StrToInt(temp);
+                except
+                    on E : EConvertError do continue;
+                end;
+                end
+            else
+                continue;
+
+            if i < length(l) then
+                begin
+                value:= copy(l, i + 1, length(l) - i);
+                if (length(value) = 2) and (value[1] = '\') then
+                    value:= value[1] + ''
+                else if (value[1] = '"') and (value[length(value)] = '"') then
+                    value:= copy(value, 2, length(value) - 2);
+                if value[1] <> '#' then
+                    continue;
+                temp:= copy(value, 2, length(value) - 1);
+                try
+                    color:= StrToInt('0x'+temp);
+                except
+                    on E : EConvertError do continue;
+                end;
+                end;
+
+            if c <= cClanColors then
+                ClanColorArray[c]:= color;
+
+            end;
+
+        pfsClose(f)
+        end
+        else
+            WriteLnToConsole('Settings file not found');
+end;
+
+
 procedure SetupOpenGLAttributes;
 begin
 {$IFDEF IPHONEOS}