-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLemNeoLevelPack.pas
2026 lines (1712 loc) · 54.6 KB
/
LemNeoLevelPack.pas
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit LemNeoLevelPack;
interface
uses
System.Generics.Collections, System.Generics.Defaults,
GR32, CRC32, PngInterface, LemLevel,
Windows, Dialogs, Classes, SysUtils, StrUtils, Contnrs, Controls, Forms, ComCtrls, StdCtrls,
LemTalisman,
LemStrings, LemTypes, LemNeoParser, LemNeoPieceManager, LemGadgets, LemGadgetsConstants, LemCore,
UMisc,
SharedGlobals;
type
TNeoLevelStatus = (lst_None, lst_Attempted, lst_Completed_Outdated, lst_Completed);
TNeoLevelLoadState = (lls_None, lls_BasicInfo, lls_Full);
const
STATUS_TEXTS: array[TNeoLevelStatus] of String = ('none', 'attempted', 'outdated', 'completed');
type
TNeoLevelEntry = class;
TNeoLevelEntries = class;
TNeoLevelGroup = class;
TNeoLevelGroups = class;
TPostviewCondition = (pvc_Zero, pvc_Absolute, pvc_Relative, pvc_Percent, pvc_RelativePercent);
TPostviewText = class // Class rather than record so it plays nicely with a TObjectList and can create / destroy a TStringList
private
fText: TStringList;
procedure LoadLine(aLine: TParserLine; const aIteration: Integer);
procedure InterpretCondition(aConditionString: String);
public
ConditionType: TPostviewCondition;
ConditionValue: Integer;
property Text: TStringList read fText;
constructor Create;
destructor Destroy; override;
end;
TPostviewTexts = class(TObjectList)
private
function GetItem(Index: Integer): TPostviewText;
public
constructor Create;
function Add: TPostviewText;
property Items[Index: Integer]: TPostviewText read GetItem; default;
property List;
end;
TLevelRecordEntry = record
Value: Integer;
User: String;
end;
TLevelRecords = record
LemmingsRescued: TLevelRecordEntry;
TimeTaken: TLevelRecordEntry;
CollectiblesGathered: TLevelRecordEntry;
TotalSkills: TLevelRecordEntry;
SkillTypes: TLevelRecordEntry;
SkillCount: array[Low(TSkillPanelButton)..LAST_SKILL_BUTTON] of TLevelRecordEntry;
procedure Wipe;
procedure SetNameOnAll(aName: String);
end;
TNeoLevelEntry = class // This is an entry in a level pack's list, and does NOT contain the level itself
private
fGroup: TNeoLevelGroup;
fLoadState: TNeoLevelLoadState;
fTitle: String;
fAuthor: String;
fFilename: String;
fTalismans: TObjectList<TTalisman>;
fLevelID: Int64;
fStatus: TNeoLevelStatus;
fUnlockedTalismanList: TList<LongWord>;
fCRC32: Cardinal;
fCalculatedCRC: Boolean;
procedure LoadLevelFileData(aExtent: TNeoLevelLoadState);
function GetFullPath: String;
function GetRelativePath: String;
function GetTitle: String;
function GetAuthor: String;
function GetLevelID: Int64;
function GetGroupIndex: Integer;
function GetMusicRotationIndex: Integer;
function GetTalismans: TObjectList<TTalisman>;
function GetCRC32: Cardinal;
procedure SetTalismanStatus(aIndex: LongWord; aStatus: Boolean);
function GetTalismanStatus(aIndex: LongWord): Boolean;
procedure ValidateTalismans;
public
UserRecords: TLevelRecords;
WorldRecords: TLevelRecords;
constructor Create(aGroup: TNeoLevelGroup);
destructor Destroy; override;
procedure WriteNewRecords(aRecords: TLevelRecords; aUserRecords: Boolean);
procedure WipeRecords;
procedure ResetTalismans;
property Group: TNeoLevelGroup read fGroup;
property Title: String read GetTitle;
property Author: String read GetAuthor;
property Filename: String read fFilename write fFilename;
property LevelID: Int64 read GetLevelID;
property Path: String read GetFullPath;
property RelativePath: String read GetRelativePath;
property Status: TNeoLevelStatus read fStatus write fStatus;
property UnlockedTalismanList: TList<LongWord> read fUnlockedTalismanList;
property Talismans: TObjectList<TTalisman> read GetTalismans;
property TalismanStatus[Index: LongWord]: Boolean read GetTalismanStatus write SetTalismanStatus;
property GroupIndex: Integer read GetGroupIndex;
property MusicRotationIndex: Integer read GetMusicRotationIndex;
property CRC32: Cardinal read GetCRC32;
end;
TNeoLevelGroup = class
private
fDisableSaveProgress: Boolean;
fParentGroup: TNeoLevelGroup;
fChildGroups: TNeoLevelGroups;
fLevels: TNeoLevelEntries;
fEnableSave: Boolean;
fName: String;
fAuthor: String;
fFolder: String;
fIsBasePack: Boolean;
fIsOrdered: Boolean;
fTalismans: TObjectList<TTalisman>;
fPackTitle: String;
fPackAuthor: String;
fPackVersion: String;
fScrollerList: TStringList;
fHasOwnScrollerList: Boolean;
fMusicList: TStringList;
fHasOwnMusicList: Boolean;
fPostviewTexts: TPostviewTexts;
fHasOwnPostviewTexts: Boolean;
fRandomMusicTemp: String;
function GetFullPath: String;
function GetAuthor: String;
procedure LoadFromMetaInfo(aPath: String = '');
procedure LoadFromSearchRec;
procedure LoadLevel(aLine: TParserLine; const aIteration: Integer);
procedure LoadSubGroup(aSection: TParserSection; const aIteration: Integer);
procedure Load;
procedure SetDefaultData;
procedure LoadScrollerData;
procedure LoadScrollerDataDefault;
procedure LoadScrollerSection(aSection: TParserSection; const aIteration: Integer);
procedure LoadMusicData;
procedure LoadRandomMusicLine(aLine: TParserLine; const aIteration: Integer);
procedure LoadMusicLine(aLine: TParserLine; const aIteration: Integer);
procedure LoadPostviewData;
procedure LoadPostviewSection(aSection: TParserSection; const aIteration: Integer);
function GetRecursiveLevelCount: Integer;
function GetLevelIndex(aLevel: TNeoLevelEntry): Integer;
function GetGroupIndex(aGroup: TNeoLevelGroup): Integer;
function GetParentGroupIndex: Integer;
function GetFirstUnbeatenLevel: TNeoLevelEntry;
function GetFirstUnbeatenLevelRecursive: TNeoLevelEntry;
function GetFirstLevelRecursive: TNeoLevelEntry;
function GetNextGroup: TNeoLevelGroup;
function GetPrevGroup: TNeoLevelGroup;
function GetLowestGroup: TNeoLevelGroup;
function GetHighestGroup: TNeoLevelGroup;
function GetStatus: TNeoLevelStatus;
function GetTalismans: TObjectList<TTalisman>;
function GetCompleteTalismanCount: Integer;
function GetParentBasePack: TNeoLevelGroup;
{$ifdef exp}
procedure InternalDumpSuperLemmixWebsiteMetaInfo(Titles: TStringList; Stats: TStringList);
{$endif}
public
constructor Create(aParentGroup: TNeoLevelGroup; aPath: String);
destructor Destroy; override;
procedure LoadUserData;
procedure SaveUserData;
function FindFile(aName: String): String;
procedure DumpImages(aPath: String; aPrefix: String = '');
procedure CleanseLevels(aPath: String; aOutput: TStringList = nil; ProgressDialog: TForm = nil; ProgressBar: TProgressBar = nil; StatusLabel: TLabel = nil);
{$ifdef exp}
procedure DumpSuperLemmixWebsiteMetaInfo(aPath: String);
{$endif}
function GetLevelForTalisman(aTalisman: TTalisman): TNeoLevelEntry;
procedure WipeAllRecords;
property Parent: TNeoLevelGroup read fParentGroup;
property ParentBasePack: TNeoLevelGroup read GetParentBasePack;
property Children: TNeoLevelGroups read fChildGroups;
property Levels: TNeoLevelEntries read fLevels;
property LevelCount: Integer read GetRecursiveLevelCount;
property Status: TNeoLevelStatus read GetStatus;
property Name: String read fName write fName;
property Author: String read GetAuthor write fAuthor;
property IsBasePack: Boolean read fIsBasePack write fIsBasePack;
property IsOrdered: Boolean read fIsOrdered write fIsOrdered;
property Folder: String read fFolder write fFolder;
property Path: String read GetFullPath;
property PackTitle: String read fPackTitle;
property PackAuthor: String read fPackAuthor;
property PackVersion: String read fPackVersion;
property ScrollerList: TStringList read fScrollerList;
property MusicList: TStringList read fMusicList;
property PostviewTexts: TPostviewTexts read fPostviewTexts;
property Talismans: TObjectList<TTalisman> read GetTalismans;
property TalismansUnlocked: Integer read GetCompleteTalismanCount;
property LevelIndex[aLevel: TNeoLevelEntry]: Integer read GetLevelIndex;
property GroupIndex[aGroup: TNeoLevelGroup]: Integer read GetGroupIndex;
property ParentGroupIndex: Integer read GetParentGroupIndex;
property FirstUnbeatenLevel: TNeoLevelEntry read GetFirstUnbeatenLevel;
property FirstUnbeatenLevelRecursive: TNeoLevelEntry read GetFirstUnbeatenLevelRecursive;
property FirstLevelRecursive: TNeoLevelEntry read GetFirstLevelRecursive;
property PrevGroup: TNeoLevelGroup read GetPrevGroup;
property NextGroup: TNeoLevelGroup read GetNextGroup;
property LowestGroup: TNeoLevelGroup read GetLowestGroup;
property HighestGroup: TNeoLevelGroup read GetHighestGroup;
function IsLowestGroup: Boolean;
function IsHighestGroup: Boolean;
property EnableSave: Boolean read fEnableSave write fEnableSave;
end;
// Lists //
TNeoLevelEntries = class(TObjectList)
private
fOwner: TNeoLevelGroup;
function GetItem(Index: Integer): TNeoLevelEntry;
public
constructor Create(aOwner: TNeoLevelGroup);
function Add: TNeoLevelEntry;
property Items[Index: Integer]: TNeoLevelEntry read GetItem; default;
property List;
end;
TNeoLevelGroups = class(TObjectList)
private
fOwner: TNeoLevelGroup;
function GetItem(Index: Integer): TNeoLevelGroup;
public
constructor Create(aOwner: TNeoLevelGroup);
function Add(aFolder: String): TNeoLevelGroup;
property Items[Index: Integer]: TNeoLevelGroup read GetItem; default;
property List;
end;
function SortAlphabetical(Item1, Item2: Pointer): Integer;
var
DumpImagesFallbackFlag: Boolean;
implementation
uses
GameControl, Math, UITypes;
function SortAlphabetical(Item1, Item2: Pointer): Integer;
var
G1: TNeoLevelGroup;
G2: TNeoLevelGroup;
L1: TNeoLevelEntry;
L2: TNeoLevelEntry;
S1: String;
S2: String;
begin
Result := 0;
S1 := '';
S2 := '';
if (TObject(Item1) is TNeoLevelGroup) and (TObject(Item2) is TNeoLevelGroup) then
begin
G1 := TNeoLevelGroup(Item1);
G2 := TNeoLevelGroup(Item2);
Result := CompareStr(G1.Name, G2.Name);
end;
if (TObject(Item1) is TNeoLevelEntry) and (TObject(Item2) is TNeoLevelEntry) then
begin
L1 := TNeoLevelEntry(Item1);
L2 := TNeoLevelEntry(Item2);
Result := CompareStr(L1.Title, L2.Title);
end;
end;
function GetFileAge(FilePath: String): Integer;
var
DateTime: TDateTime;
begin
if not FileAge(FilePath, DateTime) then
DateTime := 32100; // Some time in 1987...
Result := DateTimeToFileDate(DateTime);
end;
{ TPostviewText }
constructor TPostviewText.Create;
begin
inherited;
fText := TStringList.Create;
end;
destructor TPostviewText.Destroy;
begin
fText.Free;
inherited;
end;
procedure TPostviewText.LoadLine(aLine: TParserLine; const aIteration: Integer);
begin
Text.Add(aLine.ValueTrimmed);
end;
procedure TPostviewText.InterpretCondition(aConditionString: String);
var
IsRelative: Boolean;
IsPercent: Boolean;
begin
IsRelative := False;
IsPercent := False;
if (LeftStr(aConditionString, 1) = '+') or (LeftStr(aConditionString, 1) = '-') then
IsRelative := True;
if RightStr(aConditionString, 1) = '%' then
begin
aConditionString := LeftStr(aConditionString, Length(aConditionString)-1);
IsPercent := True;
end;
ConditionValue := StrToIntDef(aConditionString, 0);
if IsRelative then
begin
if IsPercent then
ConditionType := pvc_RelativePercent
else
ConditionType := pvc_Relative;
end else begin
if IsPercent then
ConditionType := pvc_Percent
else
ConditionType := pvc_Absolute;
end;
end;
{ TNeoLevelEntry }
constructor TNeoLevelEntry.Create(aGroup: TNeoLevelGroup);
begin
inherited Create;
fGroup := aGroup;
fTalismans := TObjectList<TTalisman>.Create(True);
fUnlockedTalismanList := TList<LongWord>.Create;
WipeRecords;
end;
destructor TNeoLevelEntry.Destroy;
begin
fUnlockedTalismanList.Free;
fTalismans.Free;
inherited;
end;
function TNeoLevelEntry.GetTitle: String;
begin
LoadLevelFileData(lls_BasicInfo);
Result := fTitle;
end;
function TNeoLevelEntry.GetLevelID: Int64;
begin
LoadLevelFileData(lls_BasicInfo);
Result := fLevelID;
end;
function TNeoLevelEntry.GetMusicRotationIndex: Integer;
var
Pack: TNeoLevelGroup;
MusicIndex: Integer;
function CountRecursive(aPack: TNeoLevelGroup): Boolean;
var
P, LevelIndex: Integer;
begin
for P := 0 to aPack.Children.Count-1 do
if CountRecursive(aPack.Children[P]) then
Break;
LevelIndex := aPack.Levels.IndexOf(Self);
if LevelIndex < 0 then
begin
Result := False;
Inc(MusicIndex, aPack.Levels.Count)
end else begin
Result := True;
Inc(MusicIndex, LevelIndex);
end;
end;
begin
Pack := Group;
if Pack = nil then
begin
Result := 0;
Exit;
end;
while (not Pack.fHasOwnMusicList) and (Pack.Parent <> nil) and (Pack.Parent <> GameParams.BaseLevelPack) do
Pack := Pack.Parent;
MusicIndex := 0;
CountRecursive(Pack);
Result := MusicIndex;
end;
function TNeoLevelEntry.GetAuthor: String;
begin
LoadLevelFileData(lls_BasicInfo);
Result := fAuthor;
end;
function TNeoLevelEntry.GetCRC32: Cardinal;
begin
if not fCalculatedCRC then
fCRC32 := CalculateCRC32(Path);
Result := fCRC32;
end;
procedure TNeoLevelEntry.LoadLevelFileData(aExtent: TNeoLevelLoadState);
var
Parser: TParser;
i: Integer;
TalInfoLevel: TLevel;
CloneTal: TTalisman;
begin
if fLoadState >= aExtent then Exit;
if not FileExists(Path) then
begin
MessageDlg('No file at location: ' + Path, mtWarning, [mbOK], 0);
Exit;
end;
Parser := TParser.Create;
try
Parser.LoadFromFile(Path);
if aExtent >= lls_BasicInfo then
begin
fTitle := Parser.MainSection.LineTrimString['title'];
fAuthor := Parser.MainSection.LineTrimString['author'];
fLevelID := Parser.MainSection.LineNumeric['id'];
if Parser.MainSection.Section['talisman'] <> nil then
begin
if (aExtent = lls_Full) then
begin
fTalismans.Clear;
// Set talisman.Data to "Self"
TalInfoLevel := TLevel.Create;
try
try
TalInfoLevel.LoadFromFile(Path);
for i := 0 to TalInfoLevel.Talismans.Count-1 do
begin
CloneTal := TTalisman.Create;
CloneTal.Clone(TalInfoLevel.Talismans[i]);
fTalismans.Add(CloneTal);
end;
except
// Fail silently.
end;
finally
TalInfoLevel.Free;
end;
end;
end;
end;
fLoadState := aExtent;
finally
Parser.Free;
end;
end;
function TNeoLevelEntry.GetFullPath: String;
begin
if (fGroup = nil) or (Pos(':', fFilename) <> 0) then
Result := ''
else
Result := fGroup.Path;
Result := Result + fFilename;
end;
function TNeoLevelEntry.GetRelativePath: String;
begin
Result := Path;
if LeftStr(Result, Length(AppPath)) = AppPath then
Result := RightStr(Result, Length(Result) - Length(AppPath));
end;
function TNeoLevelEntry.GetGroupIndex: Integer;
begin
if fGroup = nil then
Result := -1
else
Result := fGroup.LevelIndex[Self];
end;
function TNeoLevelEntry.GetTalismans: TObjectList<TTalisman>;
begin
LoadLevelFileData(lls_Full);
Result := fTalismans;
end;
procedure TNeoLevelEntry.SetTalismanStatus(aIndex: Cardinal; aStatus: Boolean);
var
i: Integer;
begin
if aStatus then
begin
for i := 0 to fUnlockedTalismanList.Count-1 do
if fUnlockedTalismanList[i] = aIndex then Exit;
fUnlockedTalismanList.Add(aIndex);
end else begin
for i := fUnlockedTalismanList.Count-1 downto 0 do
if fUnlockedTalismanList[i] = aIndex then
fUnlockedTalismanList.Delete(i);
end;
end;
function TNeoLevelEntry.GetTalismanStatus(aIndex: Cardinal): Boolean;
var
i: Integer;
begin
Result := False;
ValidateTalismans;
for i := 0 to fUnlockedTalismanList.Count-1 do
if fUnlockedTalismanList[i] = aIndex then
begin
Result := True;
Exit;
end;
end;
procedure TNeoLevelEntry.ValidateTalismans;
var
i, i2: Integer;
begin
LoadLevelFileData(lls_Full);
for i := fUnlockedTalismanList.Count-1 downto 0 do
for i2 := 0 to fTalismans.Count do
if i2 = fTalismans.Count then
fUnlockedTalismanList.Delete(i)
else if fTalismans[i2].ID = fUnlockedTalismanList[i] then
Break;
end;
procedure TNeoLevelEntry.WipeRecords;
begin
UserRecords.Wipe;
WorldRecords.Wipe;
end;
procedure TNeoLevelEntry.ResetTalismans;
var
aIndex: Cardinal;
begin
for aIndex := 0 to fTalismans.Count do
SetTalismanStatus(aIndex, False);
end;
procedure TNeoLevelEntry.WriteNewRecords(aRecords: TLevelRecords; aUserRecords: Boolean);
procedure Apply(var Existing: TLevelRecordEntry; New: TLevelRecordEntry; aHigherIsBetter: Boolean);
begin
if New.Value >= 0 then
begin
if Existing.Value < 0 then
Existing := New
else if (New.Value = Existing.Value) and (Pos(New.User, Existing.User) = 0) then
begin
Existing.User := Existing.User + ' & ' + New.User;
if Length(Existing.User) > 64 then
Existing.User := 'Many users';
end else if (aHigherIsBetter and (New.Value > Existing.Value)) or
((not aHigherIsBetter) and (New.Value < Existing.Value)) then
Existing := New;
end;
end;
var
Skill: TSkillPanelButton;
begin
Apply(WorldRecords.LemmingsRescued, aRecords.LemmingsRescued, True);
Apply(WorldRecords.TimeTaken, aRecords.TimeTaken, False);
Apply(WorldRecords.CollectiblesGathered, aRecords.CollectiblesGathered, True);
Apply(WorldRecords.TotalSkills, aRecords.TotalSkills, False);
Apply(WorldRecords.SkillTypes, aRecords.SkillTypes, False);
if aUserRecords then
begin
Apply(UserRecords.LemmingsRescued, aRecords.LemmingsRescued, True);
Apply(UserRecords.TimeTaken, aRecords.TimeTaken, False);
Apply(UserRecords.CollectiblesGathered, aRecords.CollectiblesGathered, True);
Apply(UserRecords.TotalSkills, aRecords.TotalSkills, False);
Apply(UserRecords.SkillTypes, aRecords.SkillTypes, False);
end;
for Skill := Low(TSkillPanelButton) to LAST_SKILL_BUTTON do
begin
Apply(WorldRecords.SkillCount[Skill], aRecords.SkillCount[Skill], False);
if aUserRecords then
Apply(UserRecords.SkillCount[Skill], aRecords.SkillCount[Skill], False);
end;
end;
{ TNeoLevelGroup }
constructor TNeoLevelGroup.Create(aParentGroup: TNeoLevelGroup; aPath: String);
begin
inherited Create;
fFolder := aPath;
if RightStr(fFolder, 1) = '\' then
fFolder := LeftStr(fFolder, Length(fFolder)-1);
fName := ExtractFileName(fFolder);
fChildGroups := TNeoLevelGroups.Create(Self);
fLevels := TNeoLevelEntries.Create(Self);
fParentGroup := aParentGroup;
fEnableSave := fParentGroup = nil;
SetDefaultData;
Load;
end;
destructor TNeoLevelGroup.Destroy;
begin
fChildGroups.Free;
fLevels.Free;
if fHasOwnMusicList and (fMusicList <> nil) then
fMusicList.Free;
if fTalismans <> nil then
fTalismans.Free;
if fHasOwnScrollerList and (fScrollerList <> nil) then
fScrollerList.Free;
if fHasOwnPostviewTexts then
fPostViewTexts.Free;
inherited;
end;
procedure TNeoLevelGroup.CleanseLevels(aPath: String; aOutput: TStringList = nil; ProgressDialog: TForm = nil; ProgressBar: TProgressBar = nil; StatusLabel: TLabel = nil);
var
i: Integer;
L: TNeoLevelEntry;
SL: TStringList;
IsStartingPoint: Boolean;
CleansedLevels: Integer;
CurrentGroupLabel: TLabel;
procedure RecursiveCopy(aSubPath: String);
var
SearchRec: TSearchRec;
i: Integer;
begin
ForceDirectories(aPath + aSubPath);
if FindFirst(Path + aSubPath + '*', faDirectory, SearchRec) = 0 then
begin
repeat
if (SearchRec.Name = '.') or (SearchRec.Name = '..') then
Continue
else if (SearchRec.Attr and faDirectory) <> 0 then
RecursiveCopy(aSubPath + IncludeTrailingPathDelimiter(SearchRec.Name))
else if Lowercase(SearchRec.Name) = 'levels.nxmi' then
begin
SL := TStringList.Create;
try
SL.LoadFromFile(Path + aSubPath + SearchRec.Name);
for i := 0 to SL.Count-1 do
SL[i] := StringReplace(SL[i], '$RANK', '$GROUP', [rfIgnoreCase, rfReplaceAll]);
SL.SaveToFile(aPath + aSubPath + SearchRec.Name);
finally
SL.Free;
end;
end else
CopyFile(PWideChar(Path + aSubPath + SearchRec.Name), PWideChar(aPath + aSubPath + SearchRec.Name), False);
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
procedure CheckForWarnings;
var
Level: TLevel;
Ident: TLabelRecord;
WrittenAny: Boolean;
i, n, Cnt, CntGrp: Integer;
function IsPlaceholder(aIdent: TLabelRecord): Boolean;
begin
Result := (Ident.GS = SFDefaultStyle) and (Ident.Piece = 'fallback');
end;
procedure Write(aText: String);
begin
if not WrittenAny then
begin
if aOutput.Count > 0 then
aOutput.Add('');
aOutput.Add('WARNINGS for ' + L.Filename);
WrittenAny := True;
end;
aOutput.Add(' ' + aText);
end;
begin
WrittenAny := False;
Level := GameParams.Level;
Ident := SplitIdentifier(Level.Info.Background);
if IsPlaceholder(Ident) then Write('Background replaced with placeholder');
Cnt := 0;
for i := 0 to Level.InteractiveObjects.Count-1 do
if IsPlaceholder(SplitIdentifier(Level.InteractiveObjects[i].Identifier)) then
Inc(Cnt);
if Cnt > 0 then Write(IntToStr(Cnt) + ' gadgets replaced with placeholder');
Cnt := 0;
CntGrp := 0;
for i := 0 to Level.Terrains.Count-1 do
if IsPlaceholder(SplitIdentifier(Level.Terrains[i].Identifier)) then
Inc(Cnt);
for i := 0 to Level.TerrainGroups.Count-1 do
for n := 0 to Level.TerrainGroups[i].Terrains.Count-1 do
if IsPlaceholder(SplitIdentifier(Level.TerrainGroups[i].Terrains[n].Identifier)) then
begin
Inc(Cnt);
Inc(CntGrp);
end;
if Cnt > 0 then Write(IntToStr(Cnt) + ' terrains replaced with placeholder (' + IntToStr(CntGrp) + ' in terrain groups)');
end;
begin
CleansedLevels := 0;
if aOutput = nil then
begin
IsStartingPoint := True;
aOutput := TStringList.Create;
end else
IsStartingPoint := False;
if IsStartingPoint then
RecursiveCopy('');
aPath := IncludeTrailingPathDelimiter(aPath);
if IsStartingPoint then
begin
ProgressDialog := TForm.Create(nil);
try
ProgressDialog.Caption := 'Cleansing Levels...';
ProgressDialog.Position := poScreenCenter;
ProgressDialog.BorderStyle := bsDialog;
ProgressDialog.Width := 400;
ProgressDialog.Height := 150;
CurrentGroupLabel := TLabel.Create(ProgressDialog);
CurrentGroupLabel.Parent := ProgressDialog;
CurrentGroupLabel.AutoSize := True;
CurrentGroupLabel.Caption := '';
CurrentGroupLabel.Top := 10;
CurrentGroupLabel.Left := 10;
ProgressBar := TProgressBar.Create(ProgressDialog);
ProgressBar.Parent := ProgressDialog;
ProgressBar.Align := alBottom;
ProgressBar.Min := 0;
ProgressBar.Max := 1; // Initialize to 1, will be updated later
ProgressBar.Position := 0;
ProgressDialog.Show;
except
ProgressDialog.Free;
raise;
end;
end else if Assigned(StatusLabel) then
CurrentGroupLabel := StatusLabel
else
CurrentGroupLabel := nil;
try
for i := 0 to Children.Count -1 do
begin
CurrentGroupLabel.Caption := 'Cleansing levels for group: ' + Children[i].Name;
ProgressBar.Max := Children[i].Levels.Count;
Children[i].CleanseLevels(aPath + Children[i].Folder, aOutput, ProgressDialog, ProgressBar, CurrentGroupLabel);
Inc(CleansedLevels, ProgressBar.Max);
end;
for i := 0 to Levels.Count -1 do
begin
L := Levels[i];
try
GameParams.SetLevel(L);
GameParams.LoadCurrentLevel(True);
CheckForWarnings;
GameParams.Level.Info.LevelVersion := GameParams.Level.Info.LevelVersion +1;
GameParams.Level.SaveToFile(aPath + ChangeFileExt(L.Filename, '.nxlv'));
GameParams.Level.Info.LevelVersion := GameParams.Level.Info.LevelVersion -1; // Just in case
CurrentGroupLabel.Caption := 'Cleansing level: ' + Levels.GetItem(i).Title;
ProgressBar.Max := Levels.Count;
ProgressBar.Position := CleansedLevels;
Inc(CleansedLevels);
Application.ProcessMessages; // Allow UI updates
except
if aOutput.Count > 0 then
aOutput.Add('');
aOutput.Add('ERROR cleansing "' + L.Title + '". This level will be copied unmodified.');
end;
end;
if IsStartingPoint then
ProgressDialog.Close;
finally
if IsStartingPoint then
ProgressDialog.Free;
end;
if IsStartingPoint then
begin
if aOutput.Count > 0 then
begin
ShowMessage('Cleanse complete. Some warnings or errors occurred during cleansing. See ' + MakeSafeForFilename(Name) + ' Cleanse Report.txt for more information.');
aOutput.SaveToFile(AppPath + MakeSafeForFilename(Name) + ' Cleanse Report.txt');
end else
ShowMessage('Cleanse complete. No errors or warnings reported.');
aOutput.Free;
end;
end;
procedure TNeoLevelGroup.DumpImages(aPath: String; aPrefix: String = '');
var
i: Integer;
Output: TBitmap32;
begin
aPath := IncludeTrailingPathDelimiter(aPath);
ForceDirectories(aPath);
for i := 0 to Children.Count-1 do
Children[i].DumpImages(aPath, LeadZeroStr(i+1, 2));
if (Children.Count > 0) or IsBasePack then
aPrefix := '00' + aPrefix;
Output := TBitmap32.Create;
try
for i := 0 to Levels.Count-1 do
begin
GameParams.SetLevel(Levels[i]);
GameParams.LoadCurrentLevel;
if GameParams.Level.HasAnyFallbacks then
DumpImagesFallbackFlag := True;
Output.SetSize(GameParams.Level.Info.Width, GameParams.Level.Info.Height);
GameParams.Renderer.RenderWorld(Output, True);
TPngInterface.SavePngFile(aPath + aPrefix + LeadZeroStr(i+1, 2) + '.png', Output);
end;
finally
Output.Free;
end;
end;
{$ifdef exp}
procedure TNeoLevelGroup.DumpSuperLemmixWebsiteMetaInfo(aPath: String);
var
Ranks: TStringList;
Titles: TStringList;
Stats: TStringList;
procedure AddGroup(Group: TNeoLevelGroup; Prefix: String);
var
i: Integer;
begin
if not Group.IsBasePack then
begin
if Prefix <> '' then
Prefix := Prefix + ':';
Prefix := Prefix + Group.Name;
end;
for i := 0 to Group.Children.Count-1 do
AddGroup(Group.Children[i], Prefix);
if Group.Levels.Count > 0 then
Ranks.Add(Prefix + '>' + IntToStr(Group.Levels.Count));
end;
begin
aPath := IncludeTrailingPathDelimiter(aPath);
ForceDirectories(aPath);
Ranks := TStringList.Create;
Titles := TStringList.Create;
Stats := TStringList.Create;
try
AddGroup(Self, '');
InternalDumpSuperLemmixWebsiteMetaInfo(Titles, Stats);
Ranks.SaveToFile(aPath + 'ranks.txt');
Titles.SaveToFile(aPath + 'titles.txt');
Stats.SaveToFile(aPath + 'stats.txt');
finally
Ranks.Free;
Titles.Free;
Stats.Free;
end;
end;
procedure TNeoLevelGroup.InternalDumpSuperLemmixWebsiteMetaInfo(Titles: TStringList; Stats: TStringList);
var
i: Integer;
Level: TLevel;
function LemmingCountString: String;
var
i: Integer;
PreplacedZombieCount: Integer;
begin
PreplacedZombieCount := 0;
for i := 0 to Level.PreplacedLemmings.Count-1 do
if Level.PreplacedLemmings[i].IsZombie then
Inc(PreplacedZombieCount);
Result := IntToStr(Level.Info.LemmingsCount) + '|' +
IntToStr(Level.Info.ZombieCount) + '|' +
IntToStr(Level.PreplacedLemmings.Count) + '|' +