Changeset 276 for trunk/UGameSystem.pas
- Timestamp:
- Feb 3, 2019, 11:55:30 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGameSystem.pas
r275 r276 6 6 7 7 uses 8 Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf; 8 Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf, 9 FileUtil; 9 10 10 11 type … … 14 15 15 16 TGameSystem = class 16 Name: string;17 FileName: string; 17 18 MaxPlayerCount: Integer; 18 19 UnitKinds: TUnitKinds; … … 20 21 EmptyCellsNeutral: Boolean; 21 22 UnitsMoveImmediately: Boolean; 22 FileName: string;23 23 constructor Create; 24 24 destructor Destroy; override; 25 25 procedure Clear; 26 function GetName: string; 26 27 procedure Assign(Source: TGameSystem); 27 28 procedure LoadFromNode(Node: TDOMNode); … … 40 41 end; 41 42 43 const 44 GameSystemExt = '.xts'; 45 42 46 43 47 implementation … … 51 55 begin 52 56 Result := TGameSystem.Create; 53 Result. Name := Name;57 Result.FileName := Name; 54 58 Add(Result); 55 59 end; … … 60 64 begin 61 65 I := 0; 62 while (I < Count) and ( Items[I].Name <> Name) do Inc(I);66 while (I < Count) and (TGameSystem(Items[I]).GetName <> Name) do Inc(I); 63 67 if I < Count then Result := Items[I] 64 68 else Result := nil; … … 83 87 end; 84 88 89 function TGameSystem.GetName: string; 90 begin 91 Result := ExtractFileNameWithoutExt(ExtractFileName(FileName)); 92 end; 93 85 94 procedure TGameSystem.Assign(Source: TGameSystem); 86 95 begin 87 Name := Source.Name;96 FileName := Source.FileName; 88 97 UnitsMoveImmediately := Source.UnitsMoveImmediately; 89 98 MaxPlayerCount := Source.MaxPlayerCount; … … 96 105 NewNode: TDOMNode; 97 106 begin 98 Name := ReadString(Node, 'Name', '');99 107 UnitsSplitMerge := ReadBoolean(Node, 'UnitsSplitMerge', False); 100 108 EmptyCellsNeutral := ReadBoolean(Node, 'EmptyCellsNeutral', False); … … 110 118 NewNode: TDOMNode; 111 119 begin 112 WriteString(Node, 'Name', Name);113 120 WriteBoolean(Node, 'UnitsSplitMerge', UnitsSplitMerge); 114 121 WriteBoolean(Node, 'EmptyCellsNeutral', EmptyCellsNeutral); … … 129 136 Clear; 130 137 with Doc do try 131 if Doc.DocumentElement.NodeName <> 'Xtactics Rules' then138 if Doc.DocumentElement.NodeName <> 'XtacticsGameSystem' then 132 139 raise Exception.Create(SWrongFileFormat); 133 140 RootNode := Doc.DocumentElement; … … 146 153 Doc := TXMLDocument.Create; 147 154 with Doc do try 148 RootNode := CreateElement('Xtactics Rules');155 RootNode := CreateElement('XtacticsGameSystem'); 149 156 AppendChild(RootNode); 150 157 SaveToNode(RootNode); … … 160 167 begin 161 168 with Config do begin 162 Self.Name := string(GetValue(DOMString(Path + '/Name'), DOMString('')));163 169 UnitsSplitMerge := GetValue(DOMString(Path + '/UnitsSplitMerge'), True); 164 170 EmptyCellsNeutral := GetValue(DOMString(Path + '/EmptyCellsNeutral'), False); … … 170 176 begin 171 177 with Config do begin 172 SetValue(DOMString(Path + '/Name'), DOMString(Self.Name));173 178 SetValue(DOMString(Path + '/UnitsSplitMerge'), UnitsSplitMerge); 174 179 SetValue(DOMString(Path + '/EmptyCellsNeutral'), EmptyCellsNeutral);
Note:
See TracChangeset
for help on using the changeset viewer.