mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
Game state manager and restored inventory
This commit is contained in:
parent
f0f49f8fb4
commit
a0ec2f3d74
27 changed files with 1283 additions and 1175 deletions
|
|
@ -3,6 +3,7 @@ using Cirno.Scripts.Components.FSM._3DPlayer;
|
|||
using Cirno.Scripts.Enums;
|
||||
using Cirno.Scripts.Misc;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -19,16 +20,10 @@ public partial class GameController : Node
|
|||
[Export] private Marker3D _cameraTarget;
|
||||
public Vector3? PlayerPosition => _player?.GlobalPosition ?? null;
|
||||
public Vector3? PlayerVelocity => _player?.Velocity ?? null;
|
||||
public GameState GameState { get; private set; }
|
||||
|
||||
[Signal]
|
||||
public delegate void GameStateChangeEventHandler(GameState state);
|
||||
|
||||
[Signal]
|
||||
public delegate void ManagerReadyEventHandler();
|
||||
|
||||
[Export] public StringName PauseActionName { get; private set; } = "pause";
|
||||
|
||||
[Export] public MapResource MapResource { get; private set; }
|
||||
|
||||
[Export] public PackedScene PlayerTemplate { get; set; }
|
||||
|
|
@ -43,6 +38,8 @@ public partial class GameController : Node
|
|||
|
||||
private Vector3 _lastCheckPointPosition;
|
||||
|
||||
private GameState GameState => GameStateManager.Instance.GameState;
|
||||
|
||||
public Vector3 LastCheckPointPosition
|
||||
{
|
||||
get => _lastCheckPointPosition;
|
||||
|
|
@ -52,6 +49,12 @@ public partial class GameController : Node
|
|||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
|
||||
var gsm = new GameStateManager();
|
||||
gsm.ProcessMode = ProcessModeEnum.Always;
|
||||
this.AddChild(gsm);
|
||||
gsm.Init(GameState.Playing);
|
||||
|
||||
RenderingServer.SetDefaultClearColor(Colors.Black);
|
||||
if (GlobalState.Instance.SessionSettings.GameMode is GameMode.Roguelite)
|
||||
{
|
||||
|
|
@ -90,7 +93,7 @@ public partial class GameController : Node
|
|||
|
||||
if (_hud != null)
|
||||
{
|
||||
this.GameStateChange += _hud.OnGameStateChanged;
|
||||
GameStateManager.Instance.GameStateChange += _hud.OnGameStateChanged;
|
||||
}
|
||||
|
||||
if (_inventoryManager != null && _hud != null)
|
||||
|
|
@ -100,7 +103,7 @@ public partial class GameController : Node
|
|||
|
||||
//PlayerRespawned += OnPlayerRespawned;
|
||||
|
||||
GameState = GameState.Playing;
|
||||
//GameStateManager.Instance.GameState = GameState.Playing;
|
||||
|
||||
|
||||
CallDeferred(MethodName.DelayPlayerSpawn);
|
||||
|
|
@ -112,86 +115,6 @@ public partial class GameController : Node
|
|||
{
|
||||
EmitSignalManagerReady();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (GameState is GameState.Paused && Input.IsActionJustPressed(PauseActionName))
|
||||
{
|
||||
Unpause();
|
||||
}
|
||||
}
|
||||
|
||||
public void Pause()
|
||||
{
|
||||
if (GameState == GameState.Playing)
|
||||
{
|
||||
ChangeState(GameState.Paused);
|
||||
}
|
||||
}
|
||||
|
||||
public void Unpause()
|
||||
{
|
||||
if (GameState == GameState.Paused)
|
||||
{
|
||||
CallDeferred(MethodName.ChangeState, (int)GameState.Playing);
|
||||
//ChangeState(GameState.Playing);
|
||||
}
|
||||
}
|
||||
|
||||
public GameState ToggleControlMode()
|
||||
{
|
||||
if (GameState is GameState.Playing)
|
||||
{
|
||||
ChangeState(GameState.Controlling);
|
||||
}
|
||||
else if (GameState is GameState.Controlling)
|
||||
{
|
||||
ChangeState(GameState.Playing);
|
||||
}
|
||||
|
||||
return GameState;
|
||||
}
|
||||
|
||||
public void ChangeState(GameState state)
|
||||
{
|
||||
if (state == GameState) return;
|
||||
GameState = state;
|
||||
EmitSignal(SignalName.GameStateChange, (int)state);
|
||||
GD.Print($"Game state changed to {state}");
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case GameState.Paused:
|
||||
case GameState.Dialogue:
|
||||
case GameState.Shop:
|
||||
case GameState.Inventory:
|
||||
GlobalState.Instance.ChangeCursor(true);
|
||||
|
||||
GetTree().SetPause(true);
|
||||
//Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
break;
|
||||
case GameState.Playing:
|
||||
case GameState.Controlling:
|
||||
//Input.MouseMode = Input.MouseModeEnum.Confined;
|
||||
GlobalState.Instance.ChangeCursor(false);
|
||||
DelayedUnpause();
|
||||
//CallDeferred(MethodName.DelayedUnpause);
|
||||
//GetTree().SetPause(false);
|
||||
break;
|
||||
case GameState.Menu:
|
||||
GlobalState.Instance.ChangeCursor(true);
|
||||
//Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
DelayedUnpause();
|
||||
//CallDeferred(MethodName.DelayedUnpause);
|
||||
//GetTree().SetPause(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void DelayedUnpause()
|
||||
{
|
||||
GetTree().SetPause(false);
|
||||
}
|
||||
|
||||
private void DelayPlayerSpawn()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue