cirnogodot/Scripts/AlarmManager.cs

81 lines
2 KiB
C#
Raw Normal View History

2025-02-04 13:22:05 +01:00
using Godot;
namespace Cirno.Scripts;
2025-06-23 18:30:42 +02:00
public partial class AlarmManager : Node
2025-02-04 13:22:05 +01:00
{
2025-03-01 23:46:25 +01:00
[Export]
public AudioStream AlarmSound { get; private set; }
2025-02-21 18:57:00 +01:00
public static AlarmManager Instance { get; private set; }
2025-02-04 13:22:05 +01:00
public bool IsAlarmOn { get; private set; } = false;
public Vector2 LastAlarmPosition { get; private set; } = new Vector2();
2025-06-23 18:30:42 +02:00
public Vector3 LastAlarmPosition3D { get; private set; } = new Vector3();
2025-02-04 13:22:05 +01:00
[Signal]
public delegate void AlarmEnabledEventHandler(Vector2 location);
2025-06-23 18:30:42 +02:00
[Signal]
public delegate void AlarmEnabled3DEventHandler(Vector3 location);
2025-02-04 13:22:05 +01:00
[Signal]
public delegate void AlarmDisabledEventHandler();
2025-06-27 15:06:33 +02:00
//private AudioStreamPlayer _player;
2025-03-01 23:46:25 +01:00
2025-02-21 18:57:00 +01:00
public override void _Ready()
{
Instance = this;
2025-03-01 23:46:25 +01:00
2025-06-27 15:06:33 +02:00
// 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);
//
//
// }
2025-02-21 18:57:00 +01:00
}
2025-02-04 13:22:05 +01:00
public void SoundAlarm(Vector2 location)
{
if (IsAlarmOn) return;
IsAlarmOn = true;
LastAlarmPosition = location;
2025-06-23 18:30:42 +02:00
EmitSignalAlarmEnabled(location);
GD.Print($"Alarm sounded at {location}");
2025-06-27 15:06:33 +02:00
//_player?.Play();
2025-06-23 18:30:42 +02:00
}
public void SoundAlarm(Vector3 location)
{
if (IsAlarmOn) return;
IsAlarmOn = true;
LastAlarmPosition3D = location;
EmitSignalAlarmEnabled3D(location);
2025-02-04 13:22:05 +01:00
GD.Print($"Alarm sounded at {location}");
2025-06-27 15:06:33 +02:00
//_player?.Play();
2025-02-04 13:22:05 +01:00
}
2025-04-28 12:22:00 +02:00
public void SoundSilentAlarm(Vector2 location)
{
if (IsAlarmOn) return;
EmitSignal(nameof(AlarmEnabled), location);
}
2025-02-04 13:22:05 +01:00
public void DisableAlarm()
{
IsAlarmOn = false;
EmitSignal(nameof(AlarmDisabled));
2025-06-27 15:06:33 +02:00
//_player?.Stop();
2025-02-04 13:22:05 +01:00
}
}