Add TriggerActionFactory and related resources for button and logic sequence components

This commit is contained in:
2025-10-30 02:21:27 +01:00
parent f2ff758dcb
commit 2c126cd7ea
22 changed files with 250 additions and 13 deletions

View File

@@ -9,6 +9,7 @@ using GameCore.ECS.Interfaces;
using GameCore.Input;
using GameCore.Interaction;
using GameCore.Inventory;
using GameCore.Logic;
using GameCore.Movement;
using GameCore.Physics;
using GameCore.Player;
@@ -21,11 +22,13 @@ public class ComponentFactory
private readonly Dictionary<Type, Func<Resource, IComponent>> _factories = new();
private readonly EffectFactory _effectFactory;
private readonly InteractionRequirementFactory _requirementFactory;
private readonly TriggerActionFactory _triggerActionFactory;
public ComponentFactory(EffectFactory effectFactory, InteractionRequirementFactory requirementFactory)
public ComponentFactory(EffectFactory effectFactory, InteractionRequirementFactory requirementFactory, TriggerActionFactory triggerActionFactory)
{
_effectFactory = effectFactory;
_requirementFactory = requirementFactory;
_triggerActionFactory = triggerActionFactory;
Register<AttributeComponentResource>(CreateAttributeComponent);
Register<WeaponComponentResource>(CreateWeaponComponent);
@@ -40,6 +43,9 @@ public class ComponentFactory
Register<PickupComponentResource>(CreatePickupComponent);
Register<EquipmentComponentResource>(_ => new EquipmentComponent());
Register<DoorComponentResource>(CreateDoorComponent);
Register<WorldIdComponentResource>(res => new WorldIdComponent(res.WorldId));
Register<ButtonComponentResource>(CreateButtonComponent);
Register<LogicSequenceComponentResource>(CreateLogicSequenceComponent);
}
public IComponent Create(Resource resource)
@@ -129,4 +135,47 @@ public class ComponentFactory
return component;
}
private ButtonComponent CreateButtonComponent(ButtonComponentResource resource)
{
var component = new ButtonComponent
{
ChannelId = resource.ChannelId,
IsToggle = resource.IsToggle,
IsOneTimeUse = resource.IsOneTimeUse,
IsPressed = false,
HasBeenUsed = false,
};
foreach (var reqResource in resource.Requirements)
{
var requirement = _requirementFactory.Create(reqResource);
if (requirement != null)
{
component.Requirements.Add(requirement);
}
}
return component;
}
private LogicSequenceComponent CreateLogicSequenceComponent(LogicSequenceComponentResource resource)
{
var component = new LogicSequenceComponent
{
RequiredChannels = resource.RequiredChannels.ToList(),
IsOneTimeTrigger = resource.IsOneTimeTrigger,
};
foreach (var actionResource in resource.OnCompleteActions)
{
var action = _triggerActionFactory.Create(actionResource);
if (action != null)
{
component.OnCompleteActions.Add(action);
}
}
return component;
}
}