mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 08:45:33 +00:00
39 lines
No EOL
1.1 KiB
C#
39 lines
No EOL
1.1 KiB
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;
|
|
|
|
private AudioStreamPlayer2D _activationSound;
|
|
|
|
private readonly string _activationSoundName = "ActivationSound";
|
|
|
|
public override void _Ready()
|
|
{
|
|
_activationSound = GetNodeOrNull<AudioStreamPlayer2D>(_activationSoundName);
|
|
}
|
|
|
|
public override bool Activate()
|
|
{
|
|
if (!MeetsRequirements()) return false;
|
|
_activationSound?.Play();
|
|
// 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;
|
|
|
|
}
|
|
} |