using Cirno.Scripts.Actors;
using Godot;

namespace Cirno.Scripts.Components.Actors;

public partial class BossSpriteAnimator : Node2D
{
    [Export]
    public AnimatedSprite2D AnimatedSprite2D { get; private set; }
    
    [Export]
    public Boss Enemy { get; private set; }

    [Export] public StringName NeutralAnimationName { get; private set; } = "default";
    
    [Export]
    public StringName LeftAnimationName { get; private set; } = "left";
    
    [Export]
    public StringName RightAnimationName { get; private set; } = "right";

    public override void _Ready()
    {
        Enemy.ActorSpriteChange += EnemyOnActorSpriteChange;
    }

    private void EnemyOnActorSpriteChange(Vector2 direction)
    {
        if (direction == Vector2.Zero)
        {
            AnimatedSprite2D.Play(NeutralAnimationName);
        }
        else if (direction.X > 0)
        {
            AnimatedSprite2D.Play(RightAnimationName);
        }
        else if (direction.X < 0)
        {
            AnimatedSprite2D.Play(LeftAnimationName);
        }
    }
}