Add button interaction system with event publishing and requirements handling
This commit is contained in:
52
GameCore/Logic/LogicSequenceSystem.cs
Normal file
52
GameCore/Logic/LogicSequenceSystem.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user