mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Map Level resources system
This commit is contained in:
parent
1a714dd54d
commit
6e997bd01b
21 changed files with 199 additions and 26 deletions
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Components.FSM;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Activables;
|
||||
|
|
@ -9,12 +10,13 @@ namespace Cirno.Scripts.Activables;
|
|||
public partial class LevelTeleporter : Teleporter
|
||||
{
|
||||
[Export] public string LevelPath { get; private set; }
|
||||
[Export] public MapResource Map { get; private set; }
|
||||
|
||||
[Export] public bool SaveInventory { get; private set; }
|
||||
|
||||
protected override async Task Teleport(IStateMachine<PlayerState, CharacterBody2D> player)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(LevelPath)) return;
|
||||
if (string.IsNullOrWhiteSpace(LevelPath) && Map is null) return;
|
||||
//player.RequestMovementDisable(true);
|
||||
player.SetState(PlayerState.Cutscene);
|
||||
|
||||
|
|
@ -34,6 +36,14 @@ public partial class LevelTeleporter : Teleporter
|
|||
GlobalState.Instance.SessionSettings.Items = InventoryManager.Instance.Save();
|
||||
}
|
||||
|
||||
GlobalState.Instance.GotoScene(LevelPath);
|
||||
if (!string.IsNullOrWhiteSpace(LevelPath))
|
||||
{
|
||||
GlobalState.Instance.GotoScene(LevelPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalState.Instance.GotoScene(Map);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,8 @@ public partial class GameManager : Node2D
|
|||
|
||||
public Vector2? PlayerPosition => _player?.GlobalPosition ?? null;
|
||||
|
||||
[Export] public MapResource MapResource { get; private set; }
|
||||
|
||||
[Export] public PackedScene PlayerTemplate { get; set; }
|
||||
|
||||
[Export] public Dictionary<int, NodePath> SpawnMarkers { get; private set; } = new();
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
14
Scripts/Resources/MapResource.cs
Normal file
14
Scripts/Resources/MapResource.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class MapResource : Resource
|
||||
{
|
||||
[Export] public int LevelId { get; set; }
|
||||
[Export] public StringName MapName { get; set; }
|
||||
[Export] public StringName MapDescription { get; set; }
|
||||
[Export] public StringName ScenePath { get; set; }
|
||||
[Export] public bool WeaponsAllowed { get; set; }
|
||||
[Export] public MapStartDataResource StartData { get; set; }
|
||||
}
|
||||
1
Scripts/Resources/MapResource.cs.uid
Normal file
1
Scripts/Resources/MapResource.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://quy4d4tgvqfy
|
||||
10
Scripts/Resources/MapsDatabase.cs
Normal file
10
Scripts/Resources/MapsDatabase.cs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Resources;
|
||||
|
||||
[GlobalClass]
|
||||
public partial class MapsDatabase : Resource
|
||||
{
|
||||
[Export] public Array<MapResource> Maps { get; set; }
|
||||
}
|
||||
1
Scripts/Resources/MapsDatabase.cs.uid
Normal file
1
Scripts/Resources/MapsDatabase.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://denacldr388km
|
||||
|
|
@ -9,6 +9,8 @@ public class SessionSettings
|
|||
public bool GodMode { get; set; } = false;
|
||||
|
||||
public Godot.Collections.Dictionary<string, int> Items { get; set; } = new();
|
||||
|
||||
public int LevelNumber { get; set; } = 0;
|
||||
|
||||
public float Health { get; set; }
|
||||
public float Shield { get; set; }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue