@name hexc9
@inputs
@outputs 
@persist HoloN Cells:table
@trigger none


if (first()) {
    Ranks = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
    Files = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "K", "L")
    
    Index = 1
    Cells = table()
    
    for (I = 0, 5) {
        for (J = 0, 5 + I) {
            Cells[Index, table] = table(
                "rank" = Ranks[J + 1, number], # integer
                "file" = Ranks[I + 1, number], # integer
                "cell" = Files[I + 1, string] + Ranks[J + 1, number] # string
            )
            Index++    
        }
    }
    
    for (I = 6, 10) {
        for (J = 0, 15 - I) {
            Cells[Index, table] = table(
                "rank" = Ranks[J + 1, number], # integer
                "file" = Ranks[I + 1, number], # integer
                "cell" = Files[I + 1, string] + Ranks[J + 1, number] # string
            )
            Index++    
        }
    }

    timer("test", 500)
}
 
if (clk("test")) {           
            
local Length = 6

local MeshX  = Length*sqrt(3)
local MeshY  = Length + Length*0.5

local Entity = entity()

for (I = 1, Cells:count()) {
    local Cell = Cells[I, table]
    
    local Y = Cell["file", number] # left/right (file)
    local X = Cell["rank", number]  # up/down (rank)
    
    HoloN++
    holoCreate(HoloN)
    holoModel(HoloN, "hexagon")
    holoScaleUnits(HoloN, vec(Length*2 - 1))
    holoParent(HoloN, Entity)
    
    #holoPos(HoloN, Entity:toWorld(vec(X*MeshX - (MeshX/2)*Y, -Y*MeshY, 0 )))
    holoPos(HoloN, Entity:toWorld(vec(0, -Y*MeshY, 0 )))
    print(Y)

}
}
