mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
29 lines
No EOL
850 B
C#
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;
|
|
|
|
}
|
|
} |