Switch multitarget

This commit is contained in:
Marco 2025-02-24 10:24:12 +01:00
commit a5dac0606c
3 changed files with 36 additions and 22 deletions

View file

@ -1,20 +1,29 @@
using Godot;
using System.Linq;
using Godot;
using Godot.Collections;
namespace Cirno.Scripts.Interactables;
public partial class Switch : Interactable
{
[Export] public Node2D Target { get; set; }
[Export] public Array<Node2D> Targets { get; private set; } = new Array<Node2D>();
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
public override bool Activate()
{
if (MeetsRequirements() && Target is IActivable activable)
{
activable?.Activate(ActivationType);
return true;
}
if (!MeetsRequirements()) return false;
// Compatibility for old single system
bool success = ActivateTarget(Target);
return Targets.Aggregate(success, (current, target) => ActivateTarget(target) | success);
}
private bool ActivateTarget(Node2D target)
{
if (target is not IActivable activable) return false;
activable?.Activate(ActivationType);
return true;
return false;
}
}