using Godot;
using static ld48.Extensions;

public class Tutorial : Node2D {
    [Export] private Texture texture;

    private TextureRect texRect;

    private bool show;
    private float alpha;

    private float initialDelay;
        
    public override void _Ready() {
        base._Ready();

        texRect = GetNode("CanvasLayer").GetNode<TextureRect>("TextureRect");
        texRect.Texture = texture;
    }

    public override void _Process(float delta) {
        base._Process(delta);

        if (initialDelay < 10f) {
            initialDelay += delta;
        } else {
            if (show) alpha += (1f - alpha) / 10f;
            else alpha += (0f - alpha) / 10f;
        }
        
        texRect.Modulate = Colors.White.Alpha(alpha);
    }

    public void Entered(Node body) {
        if (body is Hero hero) {
            show = true;
        }
    }
    
    public void Exited(Node body) {
        if (body is Hero hero) {
            show = false;
        }
    }
}

