mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 04:35:54 +00:00
Map Level resources system
This commit is contained in:
parent
1a714dd54d
commit
6e997bd01b
21 changed files with 199 additions and 26 deletions
|
|
@ -11,8 +11,6 @@ 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; }
|
||||
|
||||
public SessionSettings SessionSettings { get; set; } = new();
|
||||
|
|
@ -24,6 +22,10 @@ public partial class GlobalState : Node
|
|||
private readonly StringName _menuMouseTexturePath = "uid://d3oxwik1uoe4j";
|
||||
private readonly StringName _reticuleMouseTexturePath = "uid://8nns6w0skiy3";
|
||||
|
||||
private readonly StringName _mapsDatabaseResource = "uid://blf2ii0j3fqil";
|
||||
|
||||
private MapsDatabase _mapsDatabase;
|
||||
|
||||
private Texture2D _menuMouseTexture;
|
||||
private Image _menuMouseImage;
|
||||
|
||||
|
|
@ -33,6 +35,8 @@ public partial class GlobalState : Node
|
|||
|
||||
this.ProcessMode = ProcessModeEnum.Always;
|
||||
|
||||
_mapsDatabase = ResourceLoader.Load<MapsDatabase>(_mapsDatabaseResource);
|
||||
|
||||
Viewport root = GetTree().Root;
|
||||
// Using a negative index counts from the end, so this gets the last child node of `root`.
|
||||
CurrentScene = root.GetChild(-1);
|
||||
|
|
@ -96,6 +100,12 @@ public partial class GlobalState : Node
|
|||
//CallDeferred(MethodName.DeferredGotoScene, path, startData);
|
||||
}
|
||||
|
||||
public void GotoScene(MapResource map)
|
||||
{
|
||||
this.SessionSettings.LevelNumber = map.LevelId;
|
||||
GoToScene(map.ScenePath.ToString(), map.StartData);
|
||||
}
|
||||
|
||||
private void DeferredGotoScene(string path, MapStartDataResource startData = null)
|
||||
{
|
||||
// It is now safe to remove the current scene.
|
||||
|
|
@ -107,7 +117,6 @@ public partial class GlobalState : Node
|
|||
|
||||
// Load a new scene.
|
||||
var nextScene = GD.Load<PackedScene>(path);
|
||||
CurrentSceneId = nextScene.GetSceneUniqueId();
|
||||
|
||||
// Instance the new scene.
|
||||
CurrentScene = nextScene.Instantiate();
|
||||
|
|
@ -196,7 +205,7 @@ public partial class GlobalState : Node
|
|||
var serializedSavedata = new Godot.Collections.Dictionary<string, Variant>()
|
||||
{
|
||||
{ "Items", items },
|
||||
{ "Level", CurrentSceneId }
|
||||
{ "Level", SessionSettings.LevelNumber }
|
||||
};
|
||||
|
||||
var saveFile = FileAccess.Open("user://savegame.save", FileAccess.ModeFlags.Write);
|
||||
|
|
@ -226,4 +235,6 @@ public partial class GlobalState : Node
|
|||
{
|
||||
GotoScene(CurrentScene.GetSceneFilePath());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue