Changeset 354 for trunk/Core.pas


Ignore:
Timestamp:
Dec 29, 2024, 1:35:37 PM (6 days ago)
Author:
chronos
Message:
  • Modified: Automatically save running game on application exit and reopen it on next start.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Core.pas

    r352 r354  
    8383    procedure Delay(Time: Integer);
    8484    procedure GameNewTurnExecute(Sender: TObject);
    85     procedure AutoSave;
    8685    procedure CommandLineParams;
    8786    procedure SelectClient;
     
    8988    procedure FormClientActions;
    9089    procedure LoadGameSystems;
     90    function GetAutoSaveFileName: string;
    9191  public
    9292    Game: TGame;
     
    9898    CellGridVisible: Boolean;
    9999    UnitShapeVisible: Boolean;
    100     AutoSaveEnabled: Boolean;
    101     ReopenLastFile: Boolean;
    102100    FormClients: TFormClients;
    103101    LocalClients: TClients;
     
    105103    GameSystems: TGameSystems;
    106104    FormMain: TFormMain;
     105    procedure AutoSave;
    107106    procedure ReopenGameOnInit;
    108107    procedure LoadConfig;
     
    145144  SRestartGameQuestion = 'Do you want to restart current game?';
    146145  SPlayersNotInitialized = 'Not all players were initialized with start cell. Needed %d, initialized %d. Change map parameters to have more terrain cells.';
    147   SFileDialogFilter = 'xTactics games (.xtg)|*.xtg|All files|*.*';
     146  SFileDialogFilter = 'xTactics games (' + GameFileExt + ')|*' + GameFileExt + '|All files|*.*';
    148147  SMissingServerClientForPlayer = 'Server client for current player not found.';
    149148
     
    188187procedure TCore.GameNewTurnExecute(Sender: TObject);
    189188begin
    190   if AutoSaveEnabled then AutoSave;
     189  AutoSave;
    191190end;
    192191
     
    196195begin
    197196  OldFileName := Game.FileName;
    198   Game.SaveToFile(GetAppConfigDir(False) + 'AutoSave.xtg');
     197  Game.SaveToFile(GetAutoSaveFileName);
    199198  Game.FileName := OldFileName;
    200199end;
     
    210209  DevelMode := XMLConfig1.GetValue('DevelMode', false);
    211210  AnimationSpeed := XMLConfig1.GetValue('AnimationSpeed', 50);
    212   AutoSaveEnabled := XMLConfig1.GetValue('AutoSave', True);
    213   ReopenLastFile := XMLConfig1.GetValue('ReopenLastFile', True);
    214211  Translator1.Language := Translator1.Languages.SearchByCode(String(XMLConfig1.GetValue('Language', '')));
    215212  ScaleDPI1.DPI := Point(XMLConfig1.GetValue('DPIX', 96), XMLConfig1.GetValue('DPIY', 96));
     
    227224  XMLConfig1.SetValue('DevelMode', DevelMode);
    228225  XMLConfig1.SetValue('AnimationSpeed', AnimationSpeed);
    229   XMLConfig1.SetValue('AutoSave', AutoSaveEnabled);
    230   XMLConfig1.SetValue('ReopenLastFile', ReopenLastFile);
    231226  XMLConfig1.SetValue('DPIX', ScaleDPI1.DPI.X);
    232227  XMLConfig1.SetValue('DPIY', ScaleDPI1.DPI.Y);
     
    695690end;
    696691
     692function TCore.GetAutoSaveFileName: string;
     693begin
     694  Result := GetAppConfigDir(False) + 'AutoSave' + GameFileExt;
     695end;
     696
    697697procedure TCore.ReopenGameOnInit;
     698var
     699  OldFileName: string;
    698700begin
    699701  CommandLineParams;
    700   if not GameLoaded and ReopenLastFile and (LastOpenedList1.Items.Count > 0) and
     702  if not GameLoaded and (LastOpenedList1.Items.Count > 0) and
    701703    FileExists(LastOpenedList1.Items[0]) then
    702     LoadGame(LastOpenedList1.Items[0]);
     704    Game.FileName := LastOpenedList1.Items[0];
     705
     706  if not GameLoaded and FileExists(GetAutoSaveFileName) then begin
     707    OldFileName := Game.FileName;
     708    LoadGame(GetAutoSaveFileName);
     709    LastOpenedList1.Items.Delete(0);
     710    Game.FileName := OldFileName;
     711  end;
    703712
    704713  if Game.FileName = '' then begin
Note: See TracChangeset for help on using the changeset viewer.