mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-09 10:05:53 +00:00
State persistance between scenes
This commit is contained in:
parent
1e38945f63
commit
35254935e4
13 changed files with 142 additions and 27 deletions
|
|
@ -8,8 +8,9 @@ using GTweensGodot.Extensions;
|
|||
public partial class GlobalState : Node
|
||||
{
|
||||
public static GlobalState Instance { get; private set; }
|
||||
|
||||
public static SessionSettings Session => GlobalState.Instance.SessionSettings;
|
||||
public Node CurrentScene { get; set; }
|
||||
public string CurrentSceneId { get; private set; }
|
||||
|
||||
private ColorRect _fader { get; set; }
|
||||
|
||||
|
|
@ -71,12 +72,18 @@ public partial class GlobalState : Node
|
|||
|
||||
private void DeferredGotoScene(string path, MapStartDataResource startData = null)
|
||||
{
|
||||
// if (InventoryManager.Instance is not null)
|
||||
// {
|
||||
// SessionSettings.Items = InventoryManager.Instance.Save();
|
||||
// }
|
||||
|
||||
// It is now safe to remove the current scene.
|
||||
CurrentScene.Free();
|
||||
|
||||
// Load a new scene.
|
||||
var nextScene = GD.Load<PackedScene>(path);
|
||||
|
||||
CurrentSceneId = nextScene.GetSceneUniqueId();
|
||||
|
||||
// Instance the new scene.
|
||||
CurrentScene = nextScene.Instantiate();
|
||||
|
||||
|
|
@ -153,4 +160,25 @@ public partial class GlobalState : Node
|
|||
_loadingPlaque?.Hide();
|
||||
_fader.TweenModulateAlpha(0, 1f).PlayUnpausable();
|
||||
}
|
||||
|
||||
public void SaveGame()
|
||||
{
|
||||
var items = InventoryManager.Instance.Save();
|
||||
var serializedSavedata = new Godot.Collections.Dictionary<string, Variant>()
|
||||
{
|
||||
{ "Items", items },
|
||||
{ "Level", CurrentSceneId }
|
||||
};
|
||||
|
||||
var saveFile = FileAccess.Open("user://savegame.save", FileAccess.ModeFlags.Write);
|
||||
|
||||
var jsonString = Json.Stringify(serializedSavedata);
|
||||
|
||||
saveFile.StoreLine(jsonString);
|
||||
}
|
||||
|
||||
public void LoadGame()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue