using Godot;
using Newlon.Components.GUI.Seedpackets;

namespace Newlon.Components.GUI;

public partial class GridLoader : GridContainer
{
    private const string PLANT_RESOURCE_PATH = "res://resources/plants/";
    private PackedScene _plantCard;

    public override void _Ready()
    {
        _plantCard = ResourceLoader.Load<PackedScene>("res://scenes/gui/seedpacket.tscn");

        var list = GameRegistry.GetPlants();
        list.Sort((a, b) =>
        {
            return a.Order - b.Order;
        });
        foreach (var resource in list)
        {
            Seedpacket slot = _plantCard.Instantiate<Seedpacket>();
            AddChild(slot);

            slot.SetResource(resource);
            slot.SetHandler(new ChoosableHandler(slot));
        }
    }
}
