using Cirno.Scripts.Activables;
using Godot;

namespace Cirno.Scripts.Utils;

[Tool]
public partial class TeleporterLinker : Node2D
{
    private Teleporter _teleporter;

    [Export] public Color Color { get; set; } = Colors.Blue;
    
    public override void _Ready()
    {
        _teleporter = GetParentOrNull<Teleporter>();
    }

    public override void _Draw()
    {
        if (!Engine.IsEditorHint())
            return;
        if (_teleporter is null) return;
        if (!_teleporter.IsEnabled) return;
        if (_teleporter.Target is null) return;
        
        Vector2 start = _teleporter.GlobalPosition;
        Vector2 end = _teleporter.Target.GlobalPosition;
        
        DrawLine(ToLocal(start), ToLocal(end) + new Vector2(4,4), Color, 2.0f);
    }
    
    public override void _Process(double delta)
    {
        if (Engine.IsEditorHint())
        {
            QueueRedraw();
        }
    }
    
    
}