Skip to content

Grid and Walls

TheGenieOfTheCode edited this page Oct 29, 2026 · 2 revisions

Grid and Walls

Small helpers for moving between canvas pixels and grid squares, measuring between creatures the Draw Steel way, asking what stands in a square, and reading how tall a wall is.

Grid positions are { x, y } in squares, counted from the top left of the scene. Canvas positions are { x, y } in pixels.

Squares and pixels

Function Returns
GRID() The size of one square in pixels.
toGrid(point) The square a canvas point is in. Works on a token document too, giving its top left square.
toWorld(square) The pixel position of a square's top left corner.
toCenter(square) The pixel position of a square's centre.
gridEq(a, b) Whether two squares are the same.
gridDist(a, b) Squares between two squares, counting diagonals as one.

Distance between creatures

Draw Steel measures from the nearest edges of two creatures' spaces, not their centres.

Function Returns
tokFootprintDist(a, b) The distance between two tokens' spaces, in the scene's units. Two creatures side by side are one square apart. It counts height: the result is the flat distance or the gap between the two spaces' heights, whichever is larger, so a flier 5 squares up is out of melee reach.
footprintDistFromBounds(aX, aY, aW, aH, bX, bY, bW, bH) The flat distance from raw positions: x and y in pixels, width and height in squares.

With the range3d config off, tokFootprintDist is flat too.

What's in a square

Function Returns
tokenAt(gx, gy, excludeId) The first token whose space covers the square, skipping the token with excludeId and tokens flagged notObstacle. Uses the creature's Draw Steel size.
tileAt(gx, gy) The first tile whose top left corner is on the square.
getTokenById(id) The token on the canvas with that id, or null.

A token with the notObstacle flag set to true under CTLib's scope lies out of the way, such as a creature lying on the ground: collision and landing checks, including chooseFreeSquare in Pickers, treat its square as free.

Walls and doors

Function Returns
wallBetween(from, to) The first wall that blocks movement between the centres of two adjacent squares, preferring walls tagged obstacle, or null.
wallBlocksMovement(wall) Whether a wall stops movement: it has a movement restriction and isn't an open door.
isOpenDoorWall(wall) Whether a wall is a door standing open.
segmentsIntersect(ax, ay, bx, by, cx, cy, dx, dy) Whether two line segments cross. Touching ends don't count.

Wall blocks

A wall block is a tile standing for a solid square of wall, with the walls around its edges. The tile is tagged obstacle, and the tile and its walls share a tag starting wall-block-. See Materials and Tags for tags.

Function Returns
getWallBlockTileAt(gx, gy) The wall block tile on a square, or null.
getWallBlockWalls(tile) { blockTag, walls }: the shared tag and the wall documents.
getWallBlockBottom(tile), getWallBlockTop(tile) The block's height range, from the Wall Height module's flags on its walls, or null.
tileIsOpenDoor(tile) Whether every wall of the block is an open door.

Wall heights

A wall reaches from its bottom to its top, in squares. CTLib reads the height from the first of these the wall has:

  1. The Wall Height module's bottom and top flags, in the scene's units.
  2. A height flag under CTLib's scope, { bottom, top } in squares.
  3. The Foundry levels the wall belongs to, from the lowest bottom to the highest top.

A missing bottom or top reaches endlessly down or up, and a wall with no height at all is endless both ways.

Name What it is
wallHeight(wall, grid) { bottom, top } in squares, with -Infinity and Infinity for endless ends. grid is a SceneGrid, for the wall's scene by default.
coverWallHeight(wall, grid) The height a low cover wall covers: from its bottom, or the scene's ground when it has none, up to its top less LOW_COVER_DROP. A low cover wall with no top counts as 1 square tall.
LOW_COVER_DROP 0.5: a low cover wall counts as half a square shorter than its height.

A dragged token is stopped only by walls whose height reaches its space: the wall's bottom is below the top of the token's space and its top is above the bottom. With the wallHeightMovement config off, every movement wall stops it.

Related Pages

Clone this wiki locally