func At(p Position) ecs.Entity {
	return grid[p.x+p.y*width]
}
//////////////////////////////////////////////////////////////////////////////
At returns the entity currently at the grid position.
package grid
import (
	"fmt"
	"github.com/cozely/cozely/examples/match3/ecs"
)
type Position struct {
	x, y int8
}
var grid []ecs.Entity
var positions [ecs.Size]Position
var width, height int8
func Setup(w, h int8) {
	width, height = w, h
	grid = make([]ecs.Entity, w*h, w*h)
}
func Fill(newTile func() ecs.Entity) {
	for y := int8(0); y < height; y++ {
		for x := int8(0); x < width; x++ {
			e := newTile()
			put(e, x, y)
		}
	}
}
func put(e ecs.Entity, x, y int8) {
	grid[x+y*width] = e
	positions[e] = Position{x: x, y: y}
	e.Add(ecs.GridPosition)
}
func get(x, y int8) ecs.Entity {
	return grid[x+y*width]
}
func PositionOf(e ecs.Entity) Position {
	if !e.Has(ecs.GridPosition) {
		return Nowhere()
	}
	return positions[e]
}