using Godot;
using Mr.BrickAdventures.scripts.Resources;

namespace Mr.BrickAdventures.scripts.components;

[GlobalClass]
public partial class SpaceshipExitComponent : Area2D
{
    [Export] public MovementPreset Preset { get; set; }
    [Signal] public delegate void SpaceshipExitEventHandler();

    public override void _Ready()
    {
        BodyEntered += OnBodyEntered;
    }

    private void OnBodyEntered(Node2D body)
    {
        if (body is not PlayerController player) return;
        EmitSignalSpaceshipExit();
        player.ApplyPreset(Preset);
    }
}