Options
All
  • Public
  • Public/Protected
  • All
Menu

Construct a hexagonal grid

param config

The hexagonal grid configuration

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: number

Grid Unit Width

h: number

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): any[]
    • 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 }): any[]
    • override

      Parameters

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

      Returns any[]

    • _getRulerDestination(ray: any, offset: any, token: any): { x: any; y: any }
    • 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: any; y: any }

      • x: any
      • y: any
    • 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)

    • _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

    • getConfig(type: number, size: number): { columns: boolean; even: boolean; size: number }
    • Compute the grid configuration from a provided type

      Parameters

      • type: number

        The grid type

      • size: number

        The grid size in pixels

      Returns { columns: boolean; even: boolean; size: number }

      • columns: boolean
      • even: boolean
      • size: number
    • 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

    • Compute the top-left pixel coordinate of a hexagon from its offset coordinate.

      Parameters

      Returns Point

      The coordinate in pixels

    • Compute the offset coordinate of a hexagon from a pixel coordinate contained within that hex.

      Parameters

      • point: Point

        The pixel coordinate

      • config: HexGridConfiguration

        The hex grid configuration

      • method: string = "floor"

      Returns HexOffsetCoordinate

      The offset coordinate

    • 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

      Returns { width: number; height: number }

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

      • width: number
      • height: number
    • 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.