Add button interaction system with event publishing and requirements handling
This commit is contained in:
35
GameCore/Logic/SpawnEntityAction.cs
Normal file
35
GameCore/Logic/SpawnEntityAction.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using GameCore.ECS;
|
||||
using GameCore.Events;
|
||||
using GameCore.Logic.Interfaces;
|
||||
using GameCore.Math;
|
||||
using GameCore.Physics;
|
||||
|
||||
namespace GameCore.Logic;
|
||||
|
||||
public class SpawnEntityAction(string archetypeId, string spawnerWorldId) : ITriggerAction
|
||||
{
|
||||
public void Execute(World world)
|
||||
{
|
||||
var spawnerEntity = world.FindEntityByWorldId(spawnerWorldId);
|
||||
if (spawnerEntity == null)
|
||||
{
|
||||
world.Logger.Warn($"[SpawnEntityAction] Could not find spawner with WorldId: {spawnerWorldId}");
|
||||
return;
|
||||
}
|
||||
|
||||
var position = world.GetComponent<PositionComponent>(spawnerEntity.Value);
|
||||
if (position == null)
|
||||
{
|
||||
world.Logger.Warn($"[SpawnEntityAction] Spawner '{spawnerWorldId}' does not have a PositionComponent.");
|
||||
return;
|
||||
}
|
||||
|
||||
world.PublishEvent(new SpawnEntityEvent(
|
||||
archetypeId,
|
||||
position.Position,
|
||||
Vector3.Zero,
|
||||
default));
|
||||
|
||||
world.Logger.Info($"[SpawnEntityAction] Spawning '{archetypeId}' at '{spawnerWorldId}'.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user