mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-08 10:55:54 +00:00
Boxswitch with state
This commit is contained in:
parent
036a36a80f
commit
87645f2617
14 changed files with 278 additions and 37 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
|
|
@ -9,6 +10,9 @@ public partial class Switch : Interactable
|
|||
[Export] public Node2D Target { get; set; }
|
||||
[Export] public Array<Node2D> Targets { get; private set; } = [];
|
||||
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
|
||||
|
||||
[Signal]
|
||||
public delegate void OnActivatedEventHandler(ActivationType activationType);
|
||||
|
||||
private AudioStreamPlayer2D _activationSound;
|
||||
|
||||
|
|
@ -23,17 +27,19 @@ public partial class Switch : Interactable
|
|||
{
|
||||
if (!MeetsRequirements()) return false;
|
||||
_activationSound?.Play();
|
||||
|
||||
EmitSignal(SignalName.OnActivated, (int)activationType);
|
||||
|
||||
// Compatibility for old single system
|
||||
bool success = ActivateTarget(Target);
|
||||
bool success = ActivateTarget(Target, activationType);
|
||||
|
||||
return Targets.Aggregate(success, (current, target) => ActivateTarget(target) | success);
|
||||
return Targets.Aggregate(success, (current, target) => ActivateTarget(target, activationType) | success);
|
||||
}
|
||||
|
||||
private bool ActivateTarget(Node2D target)
|
||||
private bool ActivateTarget(Node2D target, ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
if (target is not IActivable activable) return false;
|
||||
activable?.Activate(ActivationType);
|
||||
activable?.Activate(activationType);
|
||||
return true;
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue