source: trunk/TurnStats.pas

Last change on this file was 337, checked in by chronos, 3 months ago
  • Added: Game systems action in Tools menu.
  • Modified: TurnStats moved to separate unit.
File size: 1.8 KB
Line 
1unit TurnStats;
2
3interface
4
5uses
6 Classes, SysUtils, DOM, XML, Generics.Collections;
7
8type
9 { TGameTurnStat }
10
11 TGameTurnStat = class
12 OccupiedCells: Integer;
13 Units: Integer;
14 DiscoveredCells: Integer;
15 Cities: Integer;
16 WinObjectiveCells: Integer;
17 procedure LoadFromNode(Node: TDOMNode);
18 procedure SaveToNode(Node: TDOMNode);
19 end;
20
21 { TGameTurnStats }
22
23 TGameTurnStats = class(TObjectList<TGameTurnStat>)
24 procedure LoadFromNode(Node: TDOMNode);
25 procedure SaveToNode(Node: TDOMNode);
26 end;
27
28
29implementation
30
31{ TGameTurnStat }
32
33procedure TGameTurnStat.LoadFromNode(Node: TDOMNode);
34begin
35 OccupiedCells := ReadInteger(Node, 'OccupiedCells', 0);
36 Units := ReadInteger(Node, 'Units', 0);
37 DiscoveredCells := ReadInteger(Node, 'DiscoveredCells', 0);
38 Cities := ReadInteger(Node, 'Cities', 0);
39 WinObjectiveCells := ReadInteger(Node, 'WinObjectiveCells', 0);
40end;
41
42procedure TGameTurnStat.SaveToNode(Node: TDOMNode);
43begin
44 WriteInteger(Node, 'OccupiedCells', OccupiedCells);
45 WriteInteger(Node, 'Units', Units);
46 WriteInteger(Node, 'DiscoveredCells', DiscoveredCells);
47 WriteInteger(Node, 'Cities', Cities);
48 WriteInteger(Node, 'WinObjectiveCells', WinObjectiveCells);
49end;
50
51{ TGameTurnStats }
52
53procedure TGameTurnStats.LoadFromNode(Node: TDOMNode);
54var
55 Node2: TDOMNode;
56 NewTurnStat: TGameTurnStat;
57begin
58 Count := 0;
59 Node2 := Node.FirstChild;
60 while Assigned(Node2) and (Node2.NodeName = 'TurnStat') do begin
61 NewTurnStat := TGameTurnStat.Create;
62 NewTurnStat.LoadFromNode(Node2);
63 Add(NewTurnStat);
64 Node2 := Node2.NextSibling;
65 end;
66end;
67
68procedure TGameTurnStats.SaveToNode(Node: TDOMNode);
69var
70 I: Integer;
71 NewNode: TDOMNode;
72begin
73 for I := 0 to Count - 1 do begin;
74 NewNode := Node.OwnerDocument.CreateElement('TurnStat');
75 Node.AppendChild(NewNode);
76 Items[I].SaveToNode(NewNode);
77 end;
78end;
79
80end.
81
Note: See TracBrowser for help on using the repository browser.