Options
All
  • Public
  • Public/Protected
  • All
Menu

Construct a hexagonal grid

Hierarchy

Index

Constructors

Properties

columnar: boolean

Is this hex grid column-based (flat-topped), or row-based (pointy-topped)?

even: boolean

Is this hex grid even or odd?

w: any

Grid Unit Width

h: any

Grid Unit Height

width: any
height: any
options: any
POINTY_HEX_BORDERS: any = ...

Special border polygons for different token sizes.

FLAT_HEX_BORDERS: any = ...

Special border polygons for different token sizes.

Accessors

  • get hexPoints(): PointArray[]
  • An array of the points which define a hexagon for this grid shape

    Returns PointArray[]

  • get pointyHexPoints(): number[][]
  • A matrix of x and y offsets which is multiplied by the width/height vector to get pointy-top polygon coordinates

    Returns number[][]

  • get flatHexPoints(): number[][]
  • A matrix of x and y offsets which is multiplied by the width/height vector to get flat-top polygon coordinates

    Returns number[][]

Methods

  • Draw the grid. Subclasses are expected to override this method to perform their type-specific drawing logic.

    Parameters

    • options: {} = {}

      Returns HexagonalGrid

    • getPolygon(x: number, y: number, w: number, h: number, points: PointArray[]): number[]
    • A convenience method for getting all the polygon points relative to a top-left [x,y] coordinate pair

      Parameters

      • x: number

        The top-left x-coordinate

      • y: number

        The top-right y-coordinate

      • w: number
      • h: number
      • points: PointArray[]

      Returns number[]

    • getBorderPolygon(w: number, h: number, p: number): number[]
    • Get a border polygon based on the width and height of a given token.

      Parameters

      • w: number

        The width of the token in hexes.

      • h: number

        The height of the token in hexes.

      • p: number

        The padding size in pixels.

      Returns number[]

    • getGridPositionFromPixels(x: any, y: any): number[]
    • getPixelsFromGridPosition(row: any, col: any): number[]
    • getCenter(x: any, y: any): number[]
    • getSnappedPosition(x: any, y: any, interval?: number, __namedParameters?: { token: any }): { x: any; y: any }
    • override

      Parameters

      • x: any
      • y: any
      • interval: number = 1
      • __namedParameters: { token: any } = {}
        • token: any

      Returns { x: any; y: any }

      • x: any
      • y: any
    • _getClosestVertex(xc: any, yc: any, ox: any, oy: any): { x: number; y: number }
    • Parameters

      • xc: any
      • yc: any
      • ox: any
      • oy: any

      Returns { x: number; y: number }

      • x: number
      • y: number
    • shiftPosition(x: any, y: any, dx: any, dy: any, __namedParameters?: { token: any }): number[]
    • override

      Parameters

      • x: any
      • y: any
      • dx: any
      • dy: any
      • __namedParameters: { token: any } = {}
        • token: any

      Returns number[]

    • _getRulerDestination(ray: any, offset: any, token: any): { x: number; y: number }
    • Calculate the resulting token position after moving along a ruler segment.

      Parameters

      • ray: any

        The ray being moved along.

      • offset: any

        The offset of the ruler's origin relative to the token's position.

      • token: any

        The token placeable being moved.

      Returns { x: number; y: number }

      • x: number
      • y: number
    • Determine a placeable's bounding box based on the size of the grid.

      Parameters

      • w: any

        The width in grid spaces.

      • h: any

        The height in grid spaces.

      Returns Rectangle

    • highlightGridPosition(layer: any, options?: {}): void
    • getNeighbors(row: any, col: any): number[][]
    • measureDistances(segments: any, options?: {}): any
    • measureDistance(p0: Point, p1: Point): number
    • Measure the distance in grid units between two pixel-based coordinates.

      Parameters

      • p0: Point

        The initial point

      • p1: Point

        The terminal point

      Returns number

      The measured distance in grid units

    • getTopLeft(x: any, y: any): number[]
    • Given a pair of coordinates (x, y) - return the top-left of the grid square which contains that point

      Parameters

      • x: any
      • y: any

      Returns number[]

      An Array [x, y] of the top-left coordinate of the square which contains (x, y)

    • _computeHexGridDimensions(size: number, [options]?: { legacy: boolean }): void
    • Compute hexagonal grid width and height.

      Parameters

      • size: number

        Size of the hex.

      • [options]: { legacy: boolean } = {}
        • legacy: boolean

      Returns void

    • _drawRows(grid: any, nrows: number, ncols: number): void
    • Compute and draw row style hexagons.

      Parameters

      • grid: any

        Reference to the grid graphics.

      • nrows: number

        Number of rows.

      • ncols: number

        Number of columns.

      Returns void

    • _drawColumns(grid: any, nrows: number, ncols: number): void
    • Compute and draw column style hexagons.

      Parameters

      • grid: any

        Reference to the grid graphics.

      • nrows: number

        Number of rows.

      • ncols: number

        Number of columns.

      Returns void

    • _drawHexagon(grid: any, poly: number[]): void
    • Draw a hexagon from polygon points.

      Parameters

      • grid: any

        Reference to the grid graphics.

      • poly: number[]

        Array of points to draw the hexagon.

      Returns void

    • _adjustSnapForTokenSize(x: number, y: number, token: Token): [number, number]
    • Implement special rules for snapping tokens of various sizes on a hex grid.

      Parameters

      • x: number

        The X co-ordinate of the hexagon's top-left bounding box.

      • y: number

        The Y co-ordinate of the hexagon's top-left bounding box.

      • token: Token

        The token.

      Returns [number, number]

    • _adjustPositionForTokenSize(row: number, col: number, token: Token): [number, number]
    • Implement special rules for determining the grid position of tokens of various sizes on a hex grid.

      Parameters

      • row: number

        The row number.

      • col: number

        The column number.

      • token: Token

        The token.

      Returns [number, number]

      The adjusted row and column number.

    • _drawGrid([preview]?: { color: string; alpha: number }): Graphics
    • Draw the grid lines.

      Parameters

      • [preview]: { color: string; alpha: number } = {}

        Override settings used in place of those saved to the scene data.

        • color: string
        • alpha: number

      Returns Graphics

    • _getGridPositionFromPixels(x: number, y: number, method?: string): number[]
    • Get the position in grid space from a pixel coordinate.

      Parameters

      • x: number

        The origin x-coordinate

      • y: number

        The origin y-coordinate

      • method: string = "floor"

        The rounding method applied

      Returns number[]

      The row, column combination

    • calculatePadding(gridType: any, width: any, height: any, size: any, padding: any, __namedParameters?: { legacy: any }): { width: any; height: any; x: number; y: number }
    • Calculate the total size of the canvas with padding applied, as well as the top-left co-ordinates of the inner rectangle that houses the scene.

      Parameters

      • gridType: any

        The grid type to calculate padding for. {@see CONST.GRID_TYPES}

      • width: any

        The width of the scene.

      • height: any

        The height of the scene.

      • size: any

        The grid size.

      • padding: any

        The percentage of padding.

      • __namedParameters: { legacy: any } = {}
        • legacy: any

      Returns { width: any; height: any; x: number; y: number }

      • width: any
      • height: any
      • x: number
      • y: number
    • Measure the distance in hexagons between two cube coordinates.

      Parameters

      Returns number

      The distance between the two cube coordinates in hexagons

    • implementationFor(gridType: number): Function
    • Returns the class responsible for the implementation of a given grid type.

      Parameters

      • gridType: number

        The grid type. {@see CONST.GRID_TYPES}

      Returns Function

      (typeof BaseGrid) A constructor for a grid of the given type.

    • _computeLegacySizing(s: number, columnar: boolean): { w: number; h: number }
    • Legacy hex sizing set the 'size' of a hexagon (the distance from a hexagon's centre to a vertex) to be equal to half the grid size. This created some measuring inaccuracies that added up over larger distances.

      Parameters

      • s: number

        The grid size.

      • columnar: boolean

        Are the hexagons stacked in columns, or rows?

      Returns { w: number; h: number }

      The width and height of a single hexagon, in pixels.

      • w: number
      • h: number
    • _computeHexSizing(s: number, columnar: boolean): { w: number; h: number }
    • We set the 'size' of a hexagon (the distance from a hexagon's centre to a vertex) to be equal to the grid size divided by √3. This makes the distance from top-to-bottom on a flat-topped hexagon, or left-to-right on a pointy- topped hexagon equal to the grid size.

      Parameters

      • s: number

        The grid size.

      • columnar: boolean

        Are the hexagons stacked in columns, or rows?

      Returns { w: number; h: number }

      The width and height of a single hexagon, in pixels.

      • w: number
      • h: number