using System;
using System.Collections.Generic;
using System.Linq;
using Godot;
using static ld48.Extensions;

public class Rock : Polygon2D {
    public override void _Ready() {
        base._Ready();
        
        // GD.Print($"====\n{this}");

        // var image = new Image();
        // var points = Polygon.Reverse().SelectMany(v => {
            // var bytes = BitConverter.GetBytes(v.x).ToList();
            // bytes.AddRange(BitConverter.GetBytes(v.y).ToList());
            // return bytes;
        // });
        // image.CreateFromData(Polygon.Length, 1, false, Image.Format.Rgf, points.ToArray());
        // var texture = new ImageTexture();
        // texture.CreateFromImage(image, 0);
        
        // GD.Print("====");
        
        // GD.Print($"{this} {Position}");
        // (Material as ShaderMaterial).SetShaderParam("vertices", Polygon.Length);
        // (Material as ShaderMaterial).SetShaderParam("polyData", texture);

        Color = C(0.4f);
        var subPoly = new Polygon2D();
        var center = V2(Polygon.Average(v => v.x), Polygon.Average(v => v.y));
        subPoly.Polygon = Polygon.Select(v => v.MoveToward(center, 10f)).ToArray();
        subPoly.Color = C(0.5f);
        AddChild(subPoly);
        
        var subPoly2 = new Polygon2D();
        subPoly2.Polygon = Polygon.Select(v => v.MoveToward(center, 50f)).ToArray();
        subPoly2.Color = C(0.6f);
        AddChild(subPoly2);
    }
}

