From e690f64cb058dcbf515f791edc3f1fe56817bead Mon Sep 17 00:00:00 2001 From: Tom Date: Sun, 15 Jun 2025 08:41:10 -0500 Subject: [PATCH] Use `user://` and `res://` paths for the static/generated saves I think this should fix the issue of local files not being found on macs. I used this reference: https://docs.godotengine.org/en/latest/tutorials/io/data_paths.html --- C7/Game.cs | 2 +- C7/GlobalSingleton.cs | 6 +++--- C7/UIElements/NewGame/PlayerSetup.cs | 13 +++---------- C7/UIElements/NewGame/WorldSetup.cs | 2 +- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/C7/Game.cs b/C7/Game.cs index 735a92a4..e77ae0fe 100644 --- a/C7/Game.cs +++ b/C7/Game.cs @@ -106,7 +106,7 @@ public override void _Ready() { civ3AnimData = new AnimationManager(animSoundPlayer); animTracker = new AnimationTracker(civ3AnimData); - controller = CreateGame.createGame(Global.LoadGamePath, Global.DefaultBicPath, (scenarioSearchPath) => { + controller = CreateGame.createGame(Global.LoadGamePath, GlobalSingleton.DefaultBicPath, (scenarioSearchPath) => { // WHen the game loading logic tries to load the PediaIcons file, set the // scenario search path and then use our Civ3MediaPath searching logic to // find the correct version of the file. diff --git a/C7/GlobalSingleton.cs b/C7/GlobalSingleton.cs index 934db3e9..932d8121 100644 --- a/C7/GlobalSingleton.cs +++ b/C7/GlobalSingleton.cs @@ -13,15 +13,15 @@ public partial class GlobalSingleton : Node { // and back to game public string LoadGamePath; // For now this needs to get passed to QueryCiv3 when importing. - public string DefaultBicPath { get => Util.GetCiv3Path() + @"/Conquests/conquests.biq"; } + public static string DefaultBicPath { get => Util.GetCiv3Path() + @"/Conquests/conquests.biq"; } // This is the 'static map' used in lieu of terrain generation - public string DefaultGamePath { get => @"./Text/c7-static-map-save.json"; } + public static string DefaultGamePath { get => ProjectSettings.GlobalizePath(@"res://Text/c7-static-map-save.json"); } // The file where a generated map is saved, until we get more advanced ways // to generate new games. // TODO: improve this. - public string DefaultGeneratedGamePath { get => @"./Text/c7-autosave-turn-0.json"; } + public static string DefaultGeneratedGamePath { get => ProjectSettings.GlobalizePath(@"user://generated-game.json"); } public void ResetLoadGamePath() { LoadGamePath = DefaultGamePath; diff --git a/C7/UIElements/NewGame/PlayerSetup.cs b/C7/UIElements/NewGame/PlayerSetup.cs index 7f90fdf7..367f66b7 100644 --- a/C7/UIElements/NewGame/PlayerSetup.cs +++ b/C7/UIElements/NewGame/PlayerSetup.cs @@ -204,14 +204,7 @@ private void DisplaySelectedLeader() { } private SaveGame GetSave() { - if (!Engine.IsEditorHint()) { - GlobalSingleton Global = GetNode("/root/GlobalSingleton"); - return SaveManager.LoadSave(Global.DefaultGamePath, Global.DefaultBicPath, (string unused) => { return unused; }); - } else { - // Hardcoded fallback for the godot editor, which doesn't handle the - // global. - return SaveManager.LoadSave(@"./Text/c7-static-map-save.json", "", (string unused) => { return unused; }); - } + return SaveManager.LoadSave(GlobalSingleton.DefaultGamePath, GlobalSingleton.DefaultBicPath, (string unused) => { return unused; }); } private void CreateGame() { @@ -276,8 +269,8 @@ private void DoWorldGenerationAndstartGame(SaveGame save, GlobalSingleton Global save.GameDifficulty = difficulty; log.Information("saving generated map"); - save.Save(Global.DefaultGeneratedGamePath); - Global.LoadGamePath = Global.DefaultGeneratedGamePath; + save.Save(GlobalSingleton.DefaultGeneratedGamePath); + Global.LoadGamePath = GlobalSingleton.DefaultGeneratedGamePath; log.Information("opening map"); CallDeferred("StartGame"); diff --git a/C7/UIElements/NewGame/WorldSetup.cs b/C7/UIElements/NewGame/WorldSetup.cs index c65e9c81..16942c8f 100644 --- a/C7/UIElements/NewGame/WorldSetup.cs +++ b/C7/UIElements/NewGame/WorldSetup.cs @@ -314,7 +314,7 @@ private void ResetAgeGraphics() { private void CreateGame() { GlobalSingleton Global = GetNode("/root/GlobalSingleton"); Global.ResetLoadGamePath(); - SaveGame save = SaveManager.LoadSave(Global.DefaultGamePath, Global.DefaultBicPath, (string unused) => { return unused; }); + SaveGame save = SaveManager.LoadSave(GlobalSingleton.DefaultGamePath, GlobalSingleton.DefaultBicPath, (string unused) => { return unused; }); Global.WorldCharacteristics = new WorldCharacteristics() { landform = landform,