using Godot;
using static ld48.Extensions;

public class RopeSegment : Node2D {
    public Vector2 a;
    public Vector2 b;
    public bool freeze;
    public bool frozen;
    public float slipSign;
    public bool slippable = true;

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

        // if (!frozen || !freeze) {
            Update();
        // }

        frozen = freeze;
    }

    public override void _Draw() {
        base._Draw();
        
        // DrawLine(a, b, freeze ? Colors.Cyan : Colors.Yellow, 2f, true);
        // DrawString(Game.font, (a+b)/2f, slipSign.ToString());
        
        DrawLine(a, b, C(0.05f, 0.05f, 0.1f), 3f, true);
        DrawLine(a, b, C(0.2f, 0.2f, 0.3f), 1f, true);
        
        // if (slippable) {
        //     var start = (a+b)/2f + Direction() * 20f;
        //     var pointAt = start + Direction() * 1f * 40f;
        //     DrawLine(start, pointAt, Colors.Black, 4f);
        //     DrawLine(pointAt + Direction() * 4f, pointAt + Direction().Rotated(35f) * (15f + 5f), Colors.Black, 5f);
        //     DrawLine(pointAt + Direction() * 4f, pointAt + Direction().Rotated(-35f) * (15f + 5f), Colors.Black, 5f);
        //     DrawLine(start, pointAt, C(0.8f, 0.8f, 1f), 2f);
        //     DrawLine(pointAt + Direction() * 4f, pointAt + Direction().Rotated(35f) * (15f + 5f), C(0.8f, 0.8f, 1f), 3f);
        //     DrawLine(pointAt + Direction() * 4f, pointAt + Direction().Rotated(-35f) * (15f + 5f), C(0.8f, 0.8f, 1f), 3f);
        //     
        //     DrawString(Game.font, (a+b)/2f, slipSign.ToString());
        // }
    }

    public Vector2 Direction() {
        return (b - a).Normalized();
    }

    public float Length() {
        return (b - a).Length();
    }
}

