mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Switch multitarget
This commit is contained in:
parent
8d1c0beadc
commit
a5dac0606c
3 changed files with 36 additions and 22 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue