Managed the freeing of entityplacers. Also cleaned up EntityManager

This commit is contained in:
Katharina Ziolkowski
2026-02-03 15:36:59 +01:00
parent bcbc074c86
commit b65a3bbd6d
8 changed files with 92 additions and 39 deletions
@@ -1,4 +1,5 @@
using Godot;
using System;
using Godot;
using Godot.Collections;
namespace Babushka.scripts.CSharp.GameEntity.Management;
@@ -7,8 +8,18 @@ public partial class EntityNodeCreator : Node
{
[Export] private Dictionary<string, PackedScene> _entityPrefabs;
public Node2D CreateNode2D(string type)
public Node2D InstantiateNode(string type)
{
if (string.IsNullOrEmpty(type))
{
throw new NullReferenceException("The type provided for Node instantiation cannot be null or empty.");
}
if (!_entityPrefabs.ContainsKey(type))
{
throw new Exception($"The type provided for Node instantiation ({type}) is not specified in the EntityNodeCreator dictionary.");
}
return _entityPrefabs[type].Instantiate<Node2D>();
}
}