Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 50 additions & 38 deletions C7/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using C7Engine.Pathing;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

public partial class Game : Node {
[Signal] public delegate void TurnEndedEventHandler();
Expand Down Expand Up @@ -94,44 +95,7 @@ public override async void _Ready() {
Global = GetNode<GlobalSingleton>("/root/GlobalSingleton");

try {
// Ensure we clear out our image caches, as scenarios and games will
// use the same filenames but have different content for them.
Util.ClearCaches();

controller = await CreateGame.createGame(
Global.LoadGamePath,
GamePaths.LuaRulesDir,
GamePaths.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.
//
// This weird bit of indirection is necessary because the C7GameData project
// can't depend on the C7 project without a circular dependency, and the
// search logic has a Godot dependency, so it doesn't make sense to live
// in the C7GameData project.
//
// This also helps ensure the weird stateful behavior of the Util class works,
// since the search path/mod path is a static global variable - we want to
// be sure it is always set properly, so doing it during game creation
// is reasonable.
Util.setModPath(scenarioSearchPath);
log.Debug("RelativeModPath ", scenarioSearchPath);
return Util.Civ3MediaPath("Text/PediaIcons.txt");
}); // Spawns engine thread

Global.ResetLoadGamePath();

InitializeMapView();

log.Information("Now in game!");

loadTimer.Stop();
TimeSpan stopwatchElapsed = loadTimer.Elapsed;
log.Information("Game scene load time: " + Convert.ToInt32(stopwatchElapsed.TotalMilliseconds) + " ms");

EmitSignal(SignalName.GameInitialized);
await LoadGame();
} catch (Exception ex) {
errorOnLoad = true;
string message = ex.Message;
Expand All @@ -145,6 +109,54 @@ public override async void _Ready() {
}
}

private async Task LoadGame() {
// Ensure we clear out our image caches, as scenarios and games will
// use the same filenames but have different content for them.
Util.ClearCaches();

CreateGameParams options = new(GamePaths.LuaRulesDir, GamePaths.DefaultBicPath)
{
GetPediaIconsPath = (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.
//
// This weird bit of indirection is necessary because the C7GameData project
// can't depend on the C7 project without a circular dependency, and the
// search logic has a Godot dependency, so it doesn't make sense to live
// in the C7GameData project.
//
// This also helps ensure the weird stateful behavior of the Util class works,
// since the search path/mod path is a static global variable - we want to
// be sure it is always set properly, so doing it during game creation
// is reasonable.
Util.setModPath(scenarioSearchPath);
log.Debug("RelativeModPath ", scenarioSearchPath);
return Util.Civ3MediaPath("Text/PediaIcons.txt");
}
};

if (Global.SaveGame != null) {
controller = await CreateGame.createGame(Global.SaveGame, options);
} else if (Global.LoadGamePath != null) {
controller = await CreateGame.createGame(Global.LoadGamePath, options);
} else {
throw new InvalidOperationException("Save data was not set");
}

Global.ResetLoadGameFields();

InitializeMapView();

log.Information("Now in game!");

loadTimer.Stop();
TimeSpan stopwatchElapsed = loadTimer.Elapsed;
log.Information("Game scene load time: " + Convert.ToInt32(stopwatchElapsed.TotalMilliseconds) + " ms");

EmitSignal(SignalName.GameInitialized);
}

private void InitializeMapView() {
EngineStorage.ReadGameData((GameData gameData) => {
GameMap map = gameData.map;
Expand Down
5 changes: 0 additions & 5 deletions C7/GamePaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ public static string DefaultGamePath {
public const string ModernGraphicsConfig = "c7.lua";
public const string ClassicGraphicsConfig = "civ3.lua";

// The file where a generated map is saved, until we get more advanced ways
// to generate new games.
// TODO: improve this.
public const string DefaultGeneratedGamePath = "./Text/c7-autosave-turn-0.json";

// For now this needs to get passed to QueryCiv3 when importing.
public static string DefaultBicPath { get => Util.GetCiv3Path() + "/Conquests/conquests.biq"; }
}
8 changes: 6 additions & 2 deletions C7/GlobalSingleton.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Godot;
using QueryCiv3;
using C7Engine;
using C7GameData.Save;

/****
Need to pass values from one scene to another, particularly when loading
Expand All @@ -13,6 +13,9 @@ public partial class GlobalSingleton : Node {
// and back to game
public string LoadGamePath;

// Generated game data used when starting a new game
public SaveGame SaveGame;

public bool ModernGraphicsActive { get; private set; }

public GlobalSingleton() {
Expand All @@ -26,8 +29,9 @@ public GlobalSingleton() {
// setup screen, which is what actually kicks off the world generation.
public WorldCharacteristics WorldCharacteristics;

public void ResetLoadGamePath() {
public void ResetLoadGameFields() {
LoadGamePath = GamePaths.DefaultGamePath;
SaveGame = null;
}

public void ToggleModernGraphics() {
Expand Down
Loading