using Godot;

namespace Cirno.Scripts.Components;

public partial class AlarmSpriteSwitcher : Node2D
{
    private AlarmManager _alarmManager;
    [Export]
    private AnimatedSprite2D _sprite;

    [Export]
    private string _inactiveAnimationName = "default";
    
    [Export]
    private string _activeAnimationName = "alarmed";

    public override void _Ready()
    {
        base._Ready();
        _alarmManager = this.GetAlarmManager();
        
        _alarmManager.AlarmEnabled += AlarmManagerOnAlarmEnabled;
        _alarmManager.AlarmDisabled += AlarmManagerOnAlarmDisabled;
    }

    private void AlarmManagerOnAlarmDisabled()
    {
        _sprite.Play(_inactiveAnimationName);
    }

    private void AlarmManagerOnAlarmEnabled(Vector2 location)
    {
        _sprite.Play(_activeAnimationName);
    }
}