1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
{ Load palette file made in ArtNazarov/colorpalette }
unit palette_loader;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, IniFiles, FileUtil, types_for_app;
procedure loadAllPalsFromDir(dir: String; var pal: sdict);
implementation
procedure loadAllPalsFromDir(dir: String; var pal: sdict);
var
files: TStringList;
ini: TIniFile;
sections: TStringList;
i, j: Integer;
sectionName: String;
colorAlias, colorValue: String;
begin
// Find all .pal files recursively
files := TStringList.Create;
try
FindAllFiles(files, dir, '*.pal', True); // True for recursive search
for i := 0 to files.Count - 1 do
begin
ini := TIniFile.Create(files[i]);
sections := TStringList.Create;
try
// Read all sections in the ini file
ini.ReadSections(sections);
for j := 0 to sections.Count - 1 do
begin
sectionName := sections[j];
// Skip the 'Grid' section which contains metadata
if sectionName = 'Grid' then
Continue;
// Read color alias (Col2) and color value (Col1)
colorAlias := ini.ReadString(sectionName, 'Col2', '');
colorValue := ini.ReadString(sectionName, 'Col1', '');
// If we have both alias and value, add to dictionary
if (colorAlias <> '') and (colorValue <> '') then
begin
// Add or overwrite existing key
if pal.IndexOf(colorAlias) >= 0 then
pal.KeyData[colorAlias] := colorValue
else
pal.Add(colorAlias, colorValue);
end;
end;
finally
sections.Free;
ini.Free;
end;
end;
finally
files.Free;
end;
end;
end.
|