Add debug commands

master
John Montagu, the 4th Earl of Sandvich 2024-10-18 11:24:24 -07:00
parent a8e4aca91e
commit 767a9830e7
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
1 changed files with 27 additions and 0 deletions

View File

@ -68,6 +68,8 @@ public partial class World : Node
private string _currentMapResourcePath; private string _currentMapResourcePath;
internal DebugCommands Debug { get; }
//private Entities.Campfire _lastCampfire = null; //private Entities.Campfire _lastCampfire = null;
private const string PLAYER_PATH = "res://Characters/Player.tscn"; private const string PLAYER_PATH = "res://Characters/Player.tscn";
@ -84,6 +86,13 @@ public partial class World : Node
{ {
throw new System.Exception("Another World instance is running."); throw new System.Exception("Another World instance is running.");
} }
Debug = new(this);
}
~World()
{
Debug.Free();
} }
public override void _Ready() public override void _Ready()
@ -336,3 +345,21 @@ public partial class World : Node
public Node FindEntity(string name) => CurrentMap.Entities.GetNode(name); public Node FindEntity(string name) => CurrentMap.Entities.GetNode(name);
} }
internal partial class DebugCommands : Godot.GodotObject
{
private World _world;
internal DebugCommands(World world)
{
_world = world;
}
internal Items.ItemMetadata GiveItem(string item)
{
var itemMetadata = ResourceLoader
.Load<Items.ItemMetadata>($"res://Items/{item}.tres");
_world.CurrentPlayer.Inventory.Add(itemMetadata);
return itemMetadata;
}
}