cirnogodot/Scripts/Interactables/Switch.cs
2025-02-24 10:24:12 +01:00

29 lines
No EOL
850 B
C#

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()) 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;
}
}