using Godot;

namespace Cirno.Scripts;

public partial class IntroManager : Node
{
    [Export] public string TimelineName { get; set; }
    [Export] public string NextMap { get; set; }
    private Node _dialogic;
    
    public override void _Ready()
    {
        _dialogic = this.GetNode("/root/Dialogic");
        
        _dialogic.Connect("timeline_ended", Callable.From(OnTimelineEnded));
        
        _dialogic.Call("start", TimelineName);
    }
    
    private void OnTimelineEnded()
    {
        if (_dialogic.IsConnected("timeline_ended", Callable.From(OnTimelineEnded)))
        {
            _dialogic.Disconnect("timeline_ended", Callable.From(OnTimelineEnded));
        }
        
        DialogueEndAction();
    }
    
    private void DialogueEndAction()
    {
        GlobalState.Instance.GotoScene(NextMap);
        //GetTree().ChangeSceneToFile(NextMap);
    }
    
}