Add button interaction system with event publishing and requirements handling

This commit is contained in:
2025-10-30 02:21:33 +01:00
parent 86afb57809
commit 3fcb31d92f
11 changed files with 240 additions and 5 deletions

View File

@@ -0,0 +1,52 @@
using GameCore.ECS;
using GameCore.ECS.Interfaces;
using GameCore.Events;
namespace GameCore.Logic;
public class LogicSequenceSystem : ISystem
{
private readonly World _world;
public LogicSequenceSystem(World world)
{
_world = world;
world.Subscribe<ButtonPressedEvent>(OnButtonPressed);
}
public void Update(World world, float deltaTime)
{
}
private void OnButtonPressed(ButtonPressedEvent e)
{
var logicEntities = _world.GetEntitiesWith<LogicSequenceComponent>();
foreach (var entity in logicEntities)
{
var logic = _world.GetComponent<LogicSequenceComponent>(entity);
if (logic == null || (logic.IsOneTimeTrigger && logic.HasTriggered)) continue;
if (logic.RequiredChannels.Contains(e.ChannelId))
{
if (e.NewState)
logic.ActivatedChannels.Add(e.ChannelId);
else
logic.ActivatedChannels.Remove(e.ChannelId);
_world.Logger.Info(
$"[LogicSequenceSystem] Channel '{e.ChannelId}' activated. Total {logic.ActivatedChannels.Count}/{logic.RequiredChannels.Count}");
if (logic.ActivatedChannels.Count == logic.RequiredChannels.Count)
{
_world.Logger.Info("[LogicSequenceSystem] All channels activated. Executing actions.");
foreach (var action in logic.OnCompleteActions) action.Execute(_world);
if (logic.IsOneTimeTrigger) logic.HasTriggered = true;
logic.ActivatedChannels.Clear();
}
}
}
}
}