The Grid Layer¶
The Grid Layer is positioned 2nd from bottom in the layers of the Canvas. The Grid Layer is responsible for orienting and segmenting the game space into grid spaces. Currently only a square grid is supported but hex grid support is flagged as a feature for work during Beta development.
The Grid provides convenience tools for measuring distance, restricting token movement, and providing guide lines for anchoring wall segments or other canvas features.
Mod developers may wish to interact with or manipulate this layer and can do so using the singleton instance of
the GridLayer()
class which is accessible from within the client as canvas.grid
.

class
GridLayer
()¶ A CanvasLayer responsible for drawing a square grid

GridLayer.
draw
()¶ Draw square grid lines

GridLayer.
getNearestCenter
(x, y)¶ Given a pair of coordinates (x, y), return the center of the grid square which contains that point
Returns: Array – An Array [x, y] of the central point of the square which contains (x, y)

GridLayer.
getNearestVertex
(x, y)¶ Given a pair of coordinates (x0,y0) return the closest grid vertex (x1, y1)

GridLayer.
getSnappedPosition
(x, y, interval=1)¶ Given a pair of coordinates (x1,y1), return the grid coordinates (x2,y2) which represent the snapped position
Arguments:  x (Number) – The exact target location x
 y (Number) – The exact target location y
 interval (Number) – An interval of grid spaces at which to snap, default is 1.

GridLayer.
getTopLeft
(x, y)¶ Given a pair of coordinates (x, y)  return the topleft of the grid square which contains that point
Returns: Array – An Array [x, y] of the topleft coordinate of the square which contains (x, y)

GridLayer.
measureDistance
(p0, p1)¶ Measure the distance between two grid coordinates
Arguments:  p0 (Object) – The origin coordinate {x, y}
 p1 (Object) – The destination coordinate {x, y}

GridLayer.
size
¶ type: Number
A convenient reference to the pixel grid size used throughout this layer
