Changeset 275 for trunk/UGameSystem.pas
- Timestamp:
- Feb 3, 2019, 11:28:03 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UGameSystem.pas
r274 r275 6 6 7 7 uses 8 Classes, SysUtils, fgl, UUnit, DOM, UXMLUtils, XMLConf;8 Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf; 9 9 10 10 type … … 20 20 EmptyCellsNeutral: Boolean; 21 21 UnitsMoveImmediately: Boolean; 22 FileName: string; 22 23 constructor Create; 23 24 destructor Destroy; override; 25 procedure Clear; 24 26 procedure Assign(Source: TGameSystem); 25 27 procedure LoadFromNode(Node: TDOMNode); … … 35 37 TGameSystems = class(TFPGObjectList<TGameSystem>) 36 38 function AddNew(Name: string): TGameSystem; 39 function SearchByName(Name: string): TGameSystem; 37 40 end; 38 41 42 39 43 implementation 44 45 resourcestring 46 SWrongFileFormat = 'Wrong file format'; 40 47 41 48 { TGameSystems } … … 46 53 Result.Name := Name; 47 54 Add(Result); 55 end; 56 57 function TGameSystems.SearchByName(Name: string): TGameSystem; 58 var 59 I: Integer; 60 begin 61 I := 0; 62 while (I < Count) and (Items[I].Name <> Name) do Inc(I); 63 if I < Count then Result := Items[I] 64 else Result := nil; 48 65 end; 49 66 … … 59 76 UnitKinds.Free; 60 77 inherited Destroy; 78 end; 79 80 procedure TGameSystem.Clear; 81 begin 82 UnitKinds.Clear; 61 83 end; 62 84 … … 99 121 100 122 procedure TGameSystem.LoadFromFile(FileName: string); 123 var 124 Doc: TXMLDocument; 125 RootNode: TDOMNode; 101 126 begin 102 127 ReadXMLFile(Doc, FileName); 128 Self.FileName := FileName; 129 Clear; 130 with Doc do try 131 if Doc.DocumentElement.NodeName <> 'XtacticsRules' then 132 raise Exception.Create(SWrongFileFormat); 133 RootNode := Doc.DocumentElement; 134 LoadFromNode(RootNode); 135 finally 136 FreeAndNil(Doc); 137 end; 103 138 end; 104 139 105 140 procedure TGameSystem.SaveToFile(FileName: string); 141 var 142 Doc: TXMLDocument; 143 RootNode: TDOMNode; 106 144 begin 107 145 Self.FileName := FileName; 146 Doc := TXMLDocument.Create; 147 with Doc do try 148 RootNode := CreateElement('XtacticsRules'); 149 AppendChild(RootNode); 150 SaveToNode(RootNode); 151 if ExtractFileDir(FileName) <> '' then 152 ForceDirectories(ExtractFileDir(FileName)); 153 WriteXMLFile(Doc, FileName); 154 finally 155 FreeAndNil(Doc); 156 end; 108 157 end; 109 158
Note:
See TracChangeset
for help on using the changeset viewer.