Add TimeElapsed property

master
John Montagu, the 4th Earl of Sandvich 2024-10-18 11:10:34 -07:00
parent 28a408de1b
commit df82248670
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 12 additions and 0 deletions

View File

@ -14,6 +14,10 @@ public partial class GlobalState : Node, ISave
[Export] [Export]
public Stats Stats { get; set; } public Stats Stats { get; set; }
private ulong _saveTimeElapsed = 0;
public ulong TimeElapsed => _saveTimeElapsed + Godot.Time.GetTicksMsec();
public static GlobalState Instance { get; private set; } public static GlobalState Instance { get; private set; }
[Export] [Export]
@ -76,6 +80,7 @@ public partial class GlobalState : Node, ISave
Progression = save.Progression; Progression = save.Progression;
MapState = save.MapState; MapState = save.MapState;
Stats = save.Stats; Stats = save.Stats;
_saveTimeElapsed = save.TimeElapsed; // use as offset
var inventory = World.Instance.CurrentPlayer.Inventory; var inventory = World.Instance.CurrentPlayer.Inventory;
inventory.Items = Stats.Items; inventory.Items = Stats.Items;
@ -96,6 +101,7 @@ public partial class GlobalState : Node, ISave
save.Progression = Progression; save.Progression = Progression;
save.MapState = MapState; save.MapState = MapState;
save.Stats = Stats; save.Stats = Stats;
save.TimeElapsed = TimeElapsed; // update time elapsed when saving
var inventory = World.Instance.CurrentPlayer.Inventory; var inventory = World.Instance.CurrentPlayer.Inventory;
Stats.Items = inventory.Items; Stats.Items = inventory.Items;

View File

@ -9,4 +9,6 @@ public interface ISave
public State.Global.MapState MapState { get; set; } public State.Global.MapState MapState { get; set; }
public State.Global.Stats Stats { get; set; } public State.Global.Stats Stats { get; set; }
public ulong TimeElapsed { get; }
} }

View File

@ -13,10 +13,14 @@ public partial class Save : Resource, ISave
[Export] [Export]
public State.Global.Stats Stats { get; set; } public State.Global.Stats Stats { get; set; }
[Export]
public ulong TimeElapsed { get; set; }
public Save() public Save()
{ {
Progression = new(); Progression = new();
MapState = new(); MapState = new();
Stats = new(); Stats = new();
TimeElapsed = 0;
} }
} }