using Godot;
using Mr.BrickAdventures.Autoloads;

namespace Mr.BrickAdventures.scripts.Events;

[GlobalClass]
public partial class SpeedRunEventHandler : Node
{
    public override void _Ready()
    {
        EventBus.Instance.LevelCompleted += OnLevelCompleted;
    }

    public override void _ExitTree()
    {
        if (EventBus.Instance != null)
            EventBus.Instance.LevelCompleted -= OnLevelCompleted;
    }

    private void OnLevelCompleted(int levelIndex, Node currentScene, double completionTime)
    {
        SpeedRunManager.Instance?.Split();
    }
}