Changeset 375 for trunk/Core.pas


Ignore:
Timestamp:
Jan 3, 2025, 2:43:39 PM (5 days ago)
Author:
chronos
Message:
  • Fixed: Default generated game system was not playable as units were not able to move.
  • Fixed: Wrong game data directories detection.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Core.pas

    r372 r375  
    7474    GameLoaded: Boolean;
    7575    FormNewTabIndex: Integer;
    76     BaseDir: string;
     76    MapImagesDir: string;
     77    GameSystemsDir: string;
    7778    procedure LoadRecentExecute(Sender: TObject);
    7879    procedure StartNewGame;
     
    135136const
    136137  DefaultRegKey = '\Software\Chronosoft\xTactics';
     138  AutoSaveFileName = 'AutoSave' + GameFileExt;
     139  GameSystemsDirName = 'Systems';
     140  LanguagesDirName = 'Languages';
     141  MapImagesDirName = 'Images' + DirectorySeparator + 'Maps';
     142  DefaultGameSystemName = 'Default';
    137143
    138144resourcestring
     
    293299  AGameEnd.Enabled := Game.Running;
    294300  AFullscreen.Checked := FormMain.FullScreen;
    295   {$ifdef DEBUG}
     301  {$IFDEF DEBUG}
    296302  ATests.Visible := True;
    297303  ATests.Enabled := True;
    298   {$else}
     304  {$ELSE}
    299305  ATests.Visible := False;
    300306  ATests.Enabled := False;
    301   {$endif}
     307  {$ENDIF}
    302308end;
    303309
     
    518524
    519525procedure TCore.DataModuleCreate(Sender: TObject);
     526var
     527  BaseDir: string;
    520528{$IFDEF UNIX}
    521529const
    522   LanguagesDir = 'Languages';
    523   LinuxBaseDir = '/usr/share/xtactics';
    524   LinuxLanguagesDir = LinuxBaseDir + DirectorySeparator + LanguagesDir;
    525   LinuxBaseDir2 = '/app/share/xtactics';
    526   LinuxLanguagesDir2 = LinuxBaseDir2 + DirectorySeparator + LanguagesDir;
     530  LinuxRelativeDir = '../share/xtactics';
     531var
     532  NewDir: string;
    527533{$ENDIF}
    528534begin
    529   BaseDir := ExtractFilePath(ParamStr(0));
    530   Translator1.POFilesFolder := BaseDir + DirectorySeparator + LanguagesDir;
     535  BaseDir := ExcludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0)));
     536  GameSystemsDir := CombinePaths(BaseDir, GameSystemsDirName);
     537  MapImagesDir := CombinePaths(BaseDir, MapImagesDirName);
     538  Translator1.POFilesFolder := CombinePaths(BaseDir, LanguagesDirName);
    531539
    532540  {$IFDEF UNIX}
    533   // If installed in Linux system then use installation shared game directory for data files
    534   if not DirectoryExists(BaseDir) and DirectoryExists(LinuxBaseDir) then
    535     BaseDir := LinuxBaseDir;
    536 
    537   if not DirectoryExists(BaseDir) and DirectoryExists(LinuxBaseDir2) then
    538     BaseDir := LinuxBaseDir2;
     541  // If installed in Linux system then use installation shared game directory for game systems
     542  if not DirectoryExists(GameSystemsDir) then begin
     543    NewDir := ExpandFileName(BaseDir + DirectorySeparator + LinuxRelativeDir +
     544      DirectorySeparator + GameSystemsDirName);
     545    if DirectoryExists(NewDir) then GameSystemsDir := NewDir;
     546  end;
     547
     548  // If installed in Linux system then use installation shared game directory for map images
     549  if not DirectoryExists(GameSystemsDir) then begin
     550    NewDir := ExpandFileName(BaseDir + DirectorySeparator + LinuxRelativeDir +
     551      DirectorySeparator + MapImagesDirName);
     552    if DirectoryExists(NewDir) then MapImagesDir := NewDir;
     553  end;
    539554
    540555  // If installed in Linux system then use installation directory for po files
    541   if not DirectoryExists(Translator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then
    542     Translator1.POFilesFolder := LinuxLanguagesDir;
    543   if not DirectoryExists(Translator1.POFilesFolder) and DirectoryExists(LinuxLanguagesDir2) then
    544     Translator1.POFilesFolder := LinuxLanguagesDir2;
     556  if not DirectoryExists(Translator1.POFilesFolder) then begin
     557    NewDir := ExpandFileName(BaseDir + DirectorySeparator + LinuxRelativeDir +
     558      DirectorySeparator + LanguagesDirName);
     559    if DirectoryExists(NewDir) then Translator1.POFilesFolder := NewDir;
     560  end;
    545561  {$ENDIF}
    546562
     
    555571  Game.OnNewTurn := GameNewTurnExecute;
    556572  Game.OnPlayerChange := DoPlayerChange;
    557   Game.MapImageFileName := CombinePaths(BaseDir, 'Images' + DirectorySeparator + 'Maps' + DirectorySeparator + 'WorldMap.png');
     573  Game.MapImageFileName := MapImagesDir + DirectorySeparator + 'WorldMap.png';
    558574  Server.Game := Game;
    559575  LocalClients.Game := Game;
     
    680696  NewGameSystem: TGameSystem;
    681697  NewUnitKind: TUnitKind;
    682   SystemsDir: string;
    683 const
    684   GameSystemsDirName = 'Systems';
    685   DefaultGameSystemName = 'Default';
    686 begin
    687   if BaseDir <> '' then
    688     SystemsDir := BaseDir + DirectorySeparator + GameSystemsDirName
    689     else SystemsDir := ExpandFileName(GameSystemsDirName);
    690   if DirectoryExists(SystemsDir) then begin
    691     GameSystems.LoadFromDir(SystemsDir);
     698begin
     699  if DirectoryExists(GameSystemsDir) then begin
     700    GameSystems.LoadFromDir(GameSystemsDir);
    692701  end else begin
    693702    // Create default game system if the directory with definitions was not found
     
    696705    NewUnitKind := TUnitKind.Create;
    697706    NewUnitKind.Name := 'Unit';
     707    NewUnitKind.Moves := 1;
     708    NewUnitKind.Power := 99;
    698709    NewGameSystem.UnitKinds.Add(NewUnitKind);
    699710    GameSystems.Add(NewGameSystem);
     
    707718function TCore.GetAutoSaveFileName: string;
    708719begin
    709   Result := GetAppConfigDir(False) + 'AutoSave' + GameFileExt;
     720  Result := GetAppConfigDir(False) + AutoSaveFileName;
    710721end;
    711722
Note: See TracChangeset for help on using the changeset viewer.