mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
60 lines
No EOL
1.6 KiB
C#
60 lines
No EOL
1.6 KiB
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts.Interactables;
|
|
|
|
[Tool]
|
|
public partial class AlarmBox3D : Interactable3D
|
|
{
|
|
private AnimationPlayer _animationPlayer;
|
|
public StringName FlashAnimationName { get; private set; } = "Flash";
|
|
|
|
[Signal] public delegate void OnActivatedEventHandler(ActivationType activationType);
|
|
|
|
[Signal]
|
|
public delegate void PlayActivationSoundEventHandler();
|
|
|
|
public override void _Ready()
|
|
{
|
|
if (Engine.IsEditorHint()) return;
|
|
|
|
_animationPlayer = GetNode<AnimationPlayer>("AnimationPlayer");
|
|
|
|
//CallDeferred(MethodName.InitDeferred);
|
|
InitDeferred();
|
|
}
|
|
|
|
private void InitDeferred()
|
|
{
|
|
if (AlarmManager.Instance is not null)
|
|
{
|
|
AlarmManager.Instance.AlarmEnabled3D += OnAlarmEnabled3D;
|
|
AlarmManager.Instance.AlarmDisabled += InstanceOnAlarmDisabled;
|
|
}
|
|
}
|
|
|
|
private void InstanceOnAlarmDisabled()
|
|
{
|
|
_animationPlayer.Stop();
|
|
}
|
|
|
|
private void OnAlarmEnabled3D(Vector3 location)
|
|
{
|
|
// TODO: set animation, make blinky
|
|
GD.Print($"Enabled alarm in box {this.Name}");
|
|
_animationPlayer.Play(FlashAnimationName);
|
|
}
|
|
|
|
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|
{
|
|
EmitSignal(SignalName.OnActivated, (int)activationType);
|
|
EmitSignalPlayActivationSound();
|
|
if (AlarmManager.Instance is not null)
|
|
{
|
|
//_activationSound?.Play();
|
|
|
|
AlarmManager.Instance.DisableAlarm();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
} |