Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Path to Save Current Game and Load Arbitrary Saves #426

Open
wants to merge 7 commits into
base: pcen/save-types-without-references
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@ project.lock.json
C7.ini
log.txt
*.csproj.old*
# testing save.json save file
C7/Text/save.json

# Build results
[Dd]ebug/
34 changes: 34 additions & 0 deletions C7/Art/grid.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently we should check all *.import files into source, but not Godot's .import folder


importer="texture"
type="CompressedTexture2D"
uid="uid://ddwhuw1mk34rf"
path="res://.godot/imported/grid.png-78ae50a518b22416c81002ab51b5507d.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Art/grid.png"
dest_files=["res://.godot/imported/grid.png-78ae50a518b22416c81002ab51b5507d.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
6 changes: 3 additions & 3 deletions C7/Credits.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=2]
[gd_scene load_steps=2 format=3 uid="uid://i4j8a5aipkok"]

[ext_resource path="res://Credits.cs" type="Script" id=1]
[ext_resource type="Script" path="res://Credits.cs" id="1"]

[node name="Node2D" type="Node2D"]
script = ExtResource( 1 )
script = ExtResource("1")
36 changes: 22 additions & 14 deletions C7/Game.cs
Original file line number Diff line number Diff line change
@@ -58,16 +58,18 @@ public override void _Ready() {
GetTree().AutoAcceptQuit = false;
Global = GetNode<GlobalSingleton>("/root/GlobalSingleton");
try {
var animSoundPlayer = new AudioStreamPlayer();
AudioStreamPlayer animSoundPlayer = new();
AddChild(animSoundPlayer);
civ3AnimData = new AnimationManager(animSoundPlayer);
animTracker = new AnimationTracker(civ3AnimData);

controller = CreateGame.createGame(Global.LoadGamePath, Global.DefaultBicPath); // Spawns engine thread
GetNode<GameStatus>("CanvasLayer/Control/GameStatus").CurrentPlayer = controller;

Global.ResetLoadGamePath();
camera = GetNode<MapViewCamera>("MapViewCamera");

using (var gameDataAccess = new UIGameDataAccess()) {
using (UIGameDataAccess gameDataAccess = new()) {
GameMap map = gameDataAccess.gameData.map;
Util.setModPath(gameDataAccess.gameData.scenarioSearchPath);
log.Debug("RelativeModPath ", map.RelativeModPath);
@@ -417,6 +419,10 @@ private void processActions() {
this.OnPlayerEndTurn();
}

if (Input.IsActionJustPressed(C7Action.SaveGame)) {
OnSaveGame("./Text/save.json");
}

if (this.HasCurrentlySelectedUnit()) {
// TODO: replace bool with an invalid TileDirection enum
TileDirection dir = TileDirection.NORTH;
@@ -472,10 +478,9 @@ private void processActions() {
}

if (Input.IsActionJustPressed(C7Action.UnitWait)) {
using (var gameDataAccess = new UIGameDataAccess()) {
UnitInteractions.waitUnit(gameDataAccess.gameData, CurrentlySelectedUnit.id);
GetNextAutoselectedUnit(gameDataAccess.gameData);
}
using UIGameDataAccess gameDataAccess = new();
UnitInteractions.waitUnit(gameDataAccess.gameData, CurrentlySelectedUnit.id);
GetNextAutoselectedUnit(gameDataAccess.gameData);
}

if (Input.IsActionJustPressed(C7Action.UnitFortify)) {
@@ -507,14 +512,12 @@ private void processActions() {
}

if (Input.IsActionJustPressed(C7Action.UnitBuildCity) && CurrentlySelectedUnit.canBuildCity()) {
using (var gameDataAccess = new UIGameDataAccess()) {
MapUnit currentUnit = gameDataAccess.gameData.GetUnit(CurrentlySelectedUnit.id);
log.Debug(currentUnit.Describe());
if (currentUnit.canBuildCity()) {
PopupOverlay popupOverlay = GetNode<PopupOverlay>(PopupOverlay.NodePath);
popupOverlay.ShowPopup(new BuildCityDialog(controller.GetNextCityName()),
PopupOverlay.PopupCategory.Advisor);
}
using UIGameDataAccess gameDataAccess = new();
MapUnit currentUnit = gameDataAccess.gameData.GetUnit(CurrentlySelectedUnit.id);
log.Debug(currentUnit.Describe());
if (currentUnit.canBuildCity()) {
PopupOverlay popupOverlay = GetNode<PopupOverlay>(PopupOverlay.NodePath);
popupOverlay.ShowPopup(new BuildCityDialog(controller.GetNextCityName()), PopupOverlay.PopupCategory.Advisor);
}
}

@@ -557,4 +560,9 @@ public override void _Notification(int what) {
private void OnBuildCity(string name) {
new MsgBuildCity(CurrentlySelectedUnit.id, name).send();
}

private void OnSaveGame(string path) {
log.Debug($"Saving game to {path}");
new MsgSaveGame(path).send();
}
}
6 changes: 3 additions & 3 deletions C7/GlobalSingleton.cs
Original file line number Diff line number Diff line change
@@ -2,9 +2,9 @@
using QueryCiv3;

/****
Need to pass values from one scene to another, particularly when loading
a game in main menu. This script is set to auto load in project settings.
See https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html
Need to pass values from one scene to another, particularly when loading
a game in main menu. This script is set to auto load in project settings.
See https://docs.godotengine.org/en/stable/getting_started/step_by_step/singletons_autoload.html
****/
public partial class GlobalSingleton : Node {
// Will have main menu file picker set this and Game.cs pass it to C7Engine.createGame
10 changes: 6 additions & 4 deletions C7/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -30,11 +30,13 @@ public override void _Ready()
// To pass data between scenes, putting path string in a global singleton and reading it later in createGame
Global = GetNode<GlobalSingleton>("/root/GlobalSingleton");
Global.ResetLoadGamePath();
LoadDialog = new Util.Civ3FileDialog();
LoadDialog.RelPath = @"Conquests/Saves";
LoadDialog = new Util.Civ3FileDialog {
RelPath = @"Conquests/Saves"
};
LoadDialog.Connect("file_selected",new Callable(this,nameof(_on_FileDialog_file_selected)));
LoadScenarioDialog = new Util.Civ3FileDialog();
LoadScenarioDialog.RelPath = @"Conquests/Scenarios";
LoadScenarioDialog = new Util.Civ3FileDialog {
RelPath = @"Conquests/Scenarios"
};
LoadScenarioDialog.Connect("file_selected",new Callable(this,nameof(_on_FileDialog_file_selected)));
GetNode<CanvasLayer>("CanvasLayer").AddChild(LoadDialog);
SetCiv3Home = GetNode<Button>("CanvasLayer/SetCiv3Home");
12 changes: 9 additions & 3 deletions C7/UIElements/GameStatus/GameStatus.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
using Godot;
using System;
using C7GameData;
using Serilog;

public partial class GameStatus : MarginContainer
{

private ILogger log = LogManager.ForContext<GameStatus>();

LowerRightInfoBox LowerRightInfoBox = new LowerRightInfoBox();
Timer endTurnAlertTimer;

private Player player;
public Player CurrentPlayer {
get => player;
set {
player = value;
LowerRightInfoBox.PlayerCivilization = player.civilization.name;
}
}

[Signal] public delegate void BlinkyEndTurnButtonPressedEventHandler();

35 changes: 23 additions & 12 deletions C7/UIElements/GameStatus/LowerRightInfoBox.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Godot;
using System;
using ConvertCiv3Media;
using C7GameData;
using Serilog;
@@ -17,23 +16,41 @@ public partial class LowerRightInfoBox : TextureRect
Label attackDefenseMovement = new Label();
Label terrainType = new Label();
Label yearAndGold = new Label();
Label civAndGovt = new Label(){
Position = new Vector2(0, 90),
AnchorLeft = 0.5f,
AnchorRight = 0.5f,
HorizontalAlignment = HorizontalAlignment.Center,
};

Timer blinkingTimer = new Timer();
Boolean timerStarted = false; //This "isStopped" returns false if it's never been started. So we need this to know if we've ever started it.

bool timerStarted = false; //This "isStopped" returns false if it's never been started. So we need this to know if we've ever started it.

// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
this.CreateUI();
}

private string displayCiv;
public string PlayerCivilization {
get => displayCiv;
set {
displayCiv = value;
civAndGovt.Text = $"{displayCiv} - Despotism (5.5.0)";
civAndGovt.OffsetLeft = -1 * (civAndGovt.Size.X/2.0f);
}
}

private void CreateUI() {
Pcx boxRightColor = new Pcx(Util.Civ3MediaPath("Art/interface/box right color.pcx"));
Pcx boxRightAlpha = new Pcx(Util.Civ3MediaPath("Art/interface/box right alpha.pcx"));
ImageTexture boxRight = PCXToGodot.getImageFromPCXWithAlphaBlend(boxRightColor, boxRightAlpha);
TextureRect boxRightRectangle = new TextureRect();
boxRightRectangle.Texture = boxRight;
boxRightRectangle.SetPosition(new Vector2(0, 0));
TextureRect boxRightRectangle = new() {
Texture = boxRight,
Position = new Vector2(0, 0),
};
AddChild(boxRightRectangle);

Pcx nextTurnColor = new Pcx(Util.Civ3MediaPath("Art/interface/nextturn states color.pcx"));
@@ -75,14 +92,8 @@ private void CreateUI() {
//Then, when they are visible, we add a left margin that's negative and equal to half
//their width.
//Seems like there probably is an easier way, but I haven't found it yet.
Label civAndGovt = new Label();
civAndGovt.Text = "Carthage - Despotism (5.5.0)";
civAndGovt.HorizontalAlignment = HorizontalAlignment.Center;
civAndGovt.SetPosition(new Vector2(0, 90));
civAndGovt.AnchorLeft = 0.5f;
civAndGovt.AnchorRight = 0.5f;
boxRightRectangle.AddChild(civAndGovt);
civAndGovt.OffsetLeft = -1 * (civAndGovt.Size.X/2.0f);
PlayerCivilization = ""; // set empty string as placeholder

yearAndGold.Text = "Turn 0 10 Gold (+0 per turn)";
yearAndGold.HorizontalAlignment = HorizontalAlignment.Center;
Loading