2026-02-03 15:36:59 +01:00
|
|
|
using System;
|
|
|
|
|
using Godot;
|
2025-12-18 14:27:27 +01:00
|
|
|
using Godot.Collections;
|
|
|
|
|
|
|
|
|
|
namespace Babushka.scripts.CSharp.GameEntity.Management;
|
|
|
|
|
|
|
|
|
|
public partial class EntityNodeCreator : Node
|
|
|
|
|
{
|
2026-02-03 13:55:13 +01:00
|
|
|
[Export] private Dictionary<string, PackedScene> _entityPrefabs;
|
2025-12-18 14:27:27 +01:00
|
|
|
|
2026-02-03 15:36:59 +01:00
|
|
|
public Node2D InstantiateNode(string type)
|
2025-12-18 14:27:27 +01:00
|
|
|
{
|
2026-02-03 15:36:59 +01:00
|
|
|
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.");
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-03 13:55:13 +01:00
|
|
|
return _entityPrefabs[type].Instantiate<Node2D>();
|
2025-12-18 14:27:27 +01:00
|
|
|
}
|
|
|
|
|
}
|