2025-02-24 10:24:12 +01:00
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Godot;
|
|
|
|
|
|
using Godot.Collections;
|
2025-01-30 17:24:40 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Cirno.Scripts.Interactables;
|
|
|
|
|
|
|
|
|
|
|
|
public partial class Switch : Interactable
|
|
|
|
|
|
{
|
2025-02-15 14:33:44 +01:00
|
|
|
|
[Export] public Node2D Target { get; set; }
|
2025-02-24 10:24:12 +01:00
|
|
|
|
[Export] public Array<Node2D> Targets { get; private set; } = new Array<Node2D>();
|
2025-02-15 14:33:44 +01:00
|
|
|
|
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
|
2025-01-30 17:24:40 +01:00
|
|
|
|
|
2025-03-01 23:46:25 +01:00
|
|
|
|
private AudioStreamPlayer2D _activationSound;
|
|
|
|
|
|
|
|
|
|
|
|
private readonly string _activationSoundName = "ActivationSound";
|
|
|
|
|
|
|
|
|
|
|
|
public override void _Ready()
|
|
|
|
|
|
{
|
|
|
|
|
|
_activationSound = GetNodeOrNull<AudioStreamPlayer2D>(_activationSoundName);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-30 17:43:39 +01:00
|
|
|
|
public override bool Activate()
|
2025-01-30 17:24:40 +01:00
|
|
|
|
{
|
2025-02-24 10:24:12 +01:00
|
|
|
|
if (!MeetsRequirements()) return false;
|
2025-03-01 23:46:25 +01:00
|
|
|
|
_activationSound?.Play();
|
2025-02-24 10:24:12 +01:00
|
|
|
|
// 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;
|
2025-01-30 17:43:39 +01:00
|
|
|
|
|
2025-01-30 17:24:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|