mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:55:35 +00:00
81 lines
No EOL
2 KiB
C#
81 lines
No EOL
2 KiB
C#
using Godot;
|
|
|
|
namespace Cirno.Scripts;
|
|
|
|
public partial class AlarmManager : Node
|
|
{
|
|
[Export]
|
|
public AudioStream AlarmSound { get; private set; }
|
|
|
|
public static AlarmManager Instance { get; private set; }
|
|
|
|
public bool IsAlarmOn { get; private set; } = false;
|
|
|
|
public Vector2 LastAlarmPosition { get; private set; } = new Vector2();
|
|
public Vector3 LastAlarmPosition3D { get; private set; } = new Vector3();
|
|
|
|
[Signal]
|
|
public delegate void AlarmEnabledEventHandler(Vector2 location);
|
|
|
|
[Signal]
|
|
public delegate void AlarmEnabled3DEventHandler(Vector3 location);
|
|
|
|
[Signal]
|
|
public delegate void AlarmDisabledEventHandler();
|
|
|
|
//private AudioStreamPlayer _player;
|
|
|
|
public override void _Ready()
|
|
{
|
|
Instance = this;
|
|
|
|
// if (AlarmSound is not null)
|
|
// {
|
|
// var player = GetNodeOrNull<AudioStreamPlayer>("AlarmSoundPlayer");
|
|
// if (player is not null)
|
|
// {
|
|
// player.Stream = AlarmSound;
|
|
// _player = player;
|
|
// }
|
|
//
|
|
// //this.CallDeferred("add_child", player);
|
|
//
|
|
//
|
|
// }
|
|
}
|
|
|
|
public void SoundAlarm(Vector2 location)
|
|
{
|
|
if (IsAlarmOn) return;
|
|
IsAlarmOn = true;
|
|
LastAlarmPosition = location;
|
|
EmitSignalAlarmEnabled(location);
|
|
|
|
GD.Print($"Alarm sounded at {location}");
|
|
//_player?.Play();
|
|
}
|
|
|
|
public void SoundAlarm(Vector3 location)
|
|
{
|
|
if (IsAlarmOn) return;
|
|
IsAlarmOn = true;
|
|
LastAlarmPosition3D = location;
|
|
EmitSignalAlarmEnabled3D(location);
|
|
|
|
GD.Print($"Alarm sounded at {location}");
|
|
//_player?.Play();
|
|
}
|
|
|
|
public void SoundSilentAlarm(Vector2 location)
|
|
{
|
|
if (IsAlarmOn) return;
|
|
EmitSignal(nameof(AlarmEnabled), location);
|
|
}
|
|
|
|
public void DisableAlarm()
|
|
{
|
|
IsAlarmOn = false;
|
|
EmitSignal(nameof(AlarmDisabled));
|
|
//_player?.Stop();
|
|
}
|
|
} |