1 | unit TurnStats;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, DOM, XML, Generics.Collections;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
29 | implementation
|
---|
30 |
|
---|
31 | { TGameTurnStat }
|
---|
32 |
|
---|
33 | procedure TGameTurnStat.LoadFromNode(Node: TDOMNode);
|
---|
34 | begin
|
---|
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);
|
---|
40 | end;
|
---|
41 |
|
---|
42 | procedure TGameTurnStat.SaveToNode(Node: TDOMNode);
|
---|
43 | begin
|
---|
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);
|
---|
49 | end;
|
---|
50 |
|
---|
51 | { TGameTurnStats }
|
---|
52 |
|
---|
53 | procedure TGameTurnStats.LoadFromNode(Node: TDOMNode);
|
---|
54 | var
|
---|
55 | Node2: TDOMNode;
|
---|
56 | NewTurnStat: TGameTurnStat;
|
---|
57 | begin
|
---|
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;
|
---|
66 | end;
|
---|
67 |
|
---|
68 | procedure TGameTurnStats.SaveToNode(Node: TDOMNode);
|
---|
69 | var
|
---|
70 | I: Integer;
|
---|
71 | NewNode: TDOMNode;
|
---|
72 | begin
|
---|
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;
|
---|
78 | end;
|
---|
79 |
|
---|
80 | end.
|
---|
81 |
|
---|