global game state manager

godot-4.1.1
HumanoidSandvichDispenser 2023-07-24 12:40:28 -07:00
parent c2a4385deb
commit cc3ca57467
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
7 changed files with 108 additions and 0 deletions

View File

@ -0,0 +1,34 @@
using Godot;
namespace SupaLidlGame.Debug;
public partial class DebugConsole : Node
{
public void SetProp(
Utils.World world,
string entityName,
string property,
string value)
{
var ent = world.CurrentMap.Entities.GetNodeOrNull(entityName);
if (ent is not null)
{
ent.Set(property, value);
}
}
public string CallMethod(
Utils.World world,
string entityName,
string method,
string[] args)
{
var ent = world.CurrentMap.Entities.GetNodeOrNull(entityName);
if (ent is not null)
{
var returnValue = ent.Call(method, args);
return returnValue.ToString();
}
return "";
}
}

View File

@ -58,4 +58,15 @@ alignment = 1
visible = false
layout_mode = 2
[node name="DebugUI" type="CanvasLayer" parent="."]
layer = 2
[node name="Control" type="Control" parent="DebugUI"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="MusicPlayer" type="AudioStreamPlayer" parent="."]

View File

@ -0,0 +1,10 @@
using Godot;
namespace SupaLidlGame.State.Global;
public partial class GlobalState : Node
{
public Utils.World World { get; set; }
public Progression Progression { get; set; }
}

View File

@ -0,0 +1,9 @@
using Godot;
using Godot.Collections;
namespace SupaLidlGame.State.Global;
public partial class Progression : Resource
{
public Dictionary<PackedScene, bool> BossStatus { get; set; }
}

View File

@ -0,0 +1,18 @@
[gd_scene format=3 uid="uid://be8bc4eivsg4s"]
[node name="DebugUI" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 12
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 0

View File

@ -17,6 +17,9 @@ public partial class World : Node2D
[Export]
public Player CurrentPlayer { get; set; }
[Export]
public Boss CurrentBoss { get; set; }
[Export]
public UI.UIController UIController { get; set; }
@ -44,7 +47,18 @@ public partial class World : Node2D
public override void _Ready()
{
// check if world already exists
var globalState = GetNode<State.Global.GlobalState>("/root/GlobalState");
if (globalState.World is not null)
{
throw new System.InvalidOperationException();
}
globalState.World = this;
Godot.RenderingServer.SetDefaultClearColor(Godot.Colors.Black);
if (StartingArea is not null)
{
LoadScene(StartingArea);
@ -74,11 +88,19 @@ public partial class World : Node2D
public void RegisterBoss(Boss boss)
{
CurrentBoss = boss;
UIController.BossBar.Boss = boss;
MusicPlayer.Stream = boss.Music;
MusicPlayer.Play();
}
public void DeregisterBoss(Boss boss)
{
CurrentBoss = null;
UIController.BossBar.Boss = null;
MusicPlayer.Stop();
}
private void LoadMap(Map map)
{
GD.Print("Loading map " + map.Name);

View File

@ -15,6 +15,10 @@ run/main_scene="res://Scenes/Level.tscn"
config/features=PackedStringArray("4.1", "C#", "Forward Plus")
config/icon="res://icon.svg"
[autoload]
DebugConsole="*res://Debug/DebugConsole.cs"
[display]
window/size/viewport_width=640