Changeset 276 for trunk/UGameSystem.pas


Ignore:
Timestamp:
Feb 3, 2019, 11:55:30 PM (6 years ago)
Author:
chronos
Message:
  • Fixed: Load/save game syste name correctly from/to file.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGameSystem.pas

    r275 r276  
    66
    77uses
    8   Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf;
     8  Classes, SysUtils, fgl, UUnit, DOM, XMLRead, XMLWrite, UXMLUtils, XMLConf,
     9  FileUtil;
    910
    1011type
     
    1415
    1516  TGameSystem = class
    16     Name: string;
     17    FileName: string;
    1718    MaxPlayerCount: Integer;
    1819    UnitKinds: TUnitKinds;
     
    2021    EmptyCellsNeutral: Boolean;
    2122    UnitsMoveImmediately: Boolean;
    22     FileName: string;
    2323    constructor Create;
    2424    destructor Destroy; override;
    2525    procedure Clear;
     26    function GetName: string;
    2627    procedure Assign(Source: TGameSystem);
    2728    procedure LoadFromNode(Node: TDOMNode);
     
    4041  end;
    4142
     43const
     44  GameSystemExt = '.xts';
     45
    4246
    4347implementation
     
    5155begin
    5256  Result := TGameSystem.Create;
    53   Result.Name := Name;
     57  Result.FileName := Name;
    5458  Add(Result);
    5559end;
     
    6064begin
    6165  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);
    6367  if I < Count then Result := Items[I]
    6468    else Result := nil;
     
    8387end;
    8488
     89function TGameSystem.GetName: string;
     90begin
     91  Result := ExtractFileNameWithoutExt(ExtractFileName(FileName));
     92end;
     93
    8594procedure TGameSystem.Assign(Source: TGameSystem);
    8695begin
    87   Name := Source.Name;
     96  FileName := Source.FileName;
    8897  UnitsMoveImmediately := Source.UnitsMoveImmediately;
    8998  MaxPlayerCount := Source.MaxPlayerCount;
     
    96105  NewNode: TDOMNode;
    97106begin
    98   Name := ReadString(Node, 'Name', '');
    99107  UnitsSplitMerge := ReadBoolean(Node, 'UnitsSplitMerge', False);
    100108  EmptyCellsNeutral := ReadBoolean(Node, 'EmptyCellsNeutral', False);
     
    110118  NewNode: TDOMNode;
    111119begin
    112   WriteString(Node, 'Name', Name);
    113120  WriteBoolean(Node, 'UnitsSplitMerge', UnitsSplitMerge);
    114121  WriteBoolean(Node, 'EmptyCellsNeutral', EmptyCellsNeutral);
     
    129136  Clear;
    130137  with Doc do try
    131     if Doc.DocumentElement.NodeName <> 'XtacticsRules' then
     138    if Doc.DocumentElement.NodeName <> 'XtacticsGameSystem' then
    132139      raise Exception.Create(SWrongFileFormat);
    133140    RootNode := Doc.DocumentElement;
     
    146153  Doc := TXMLDocument.Create;
    147154  with Doc do try
    148     RootNode := CreateElement('XtacticsRules');
     155    RootNode := CreateElement('XtacticsGameSystem');
    149156    AppendChild(RootNode);
    150157    SaveToNode(RootNode);
     
    160167begin
    161168  with Config do begin
    162     Self.Name := string(GetValue(DOMString(Path + '/Name'), DOMString('')));
    163169    UnitsSplitMerge := GetValue(DOMString(Path + '/UnitsSplitMerge'), True);
    164170    EmptyCellsNeutral := GetValue(DOMString(Path + '/EmptyCellsNeutral'), False);
     
    170176begin
    171177  with Config do begin
    172     SetValue(DOMString(Path + '/Name'), DOMString(Self.Name));
    173178    SetValue(DOMString(Path + '/UnitsSplitMerge'), UnitsSplitMerge);
    174179    SetValue(DOMString(Path + '/EmptyCellsNeutral'), EmptyCellsNeutral);
Note: See TracChangeset for help on using the changeset viewer.