Options
All
  • Public
  • Public/Protected
  • All
Menu

The base grid class. This double-dips to implement the "gridless" option

Hierarchy

Index

Constructors

  • Parameters

    • options: any

    Returns BaseGrid

Properties

options: any
w: any

Grid Unit Width

h: any

Grid Unit Height

Methods

  • draw(options?: { color: string; alpha: number }): BaseGrid
  • Draw the grid. Subclasses are expected to override this method to perform their type-specific drawing logic.

    Parameters

    • options: { color: string; alpha: number } = {}
      • color: string
      • alpha: number

    Returns BaseGrid

  • highlightGridPosition(layer: GridHighlight, [options]?: { x: number; y: number; color: number; border: number; alpha: number; shape: Polygon }): void
  • Highlight a grid position for a certain coordinate

    Parameters

    • layer: GridHighlight

      The highlight layer to use

    • [options]: { x: number; y: number; color: number; border: number; alpha: number; shape: Polygon } = {}

      Additional options to configure behaviour.

      • x: number
      • y: number
      • color: number
      • border: number
      • alpha: number
      • shape: Polygon

    Returns void

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

  • getCenter(x: number, y: number): number[]
  • Given a pair of coordinates (x, y), return the center of the grid square which contains that point

    Parameters

    • x: number

      The x-coordinate

    • y: number

      The y-coordinate

    Returns number[]

    An array [cx, cy] of the central point of the grid space which contains (x, y)

  • getSnappedPosition(x: number, y: number, interval?: number, options?: { token: Token }): { x: any; y: any }
  • Given a pair of coordinates (x1,y1), return the grid coordinates (x2,y2) which represent the snapped position Under a "gridless" system, every pixel position is a valid snapping position

    Parameters

    • x: number

      The exact target location x

    • y: number

      The exact target location y

    • interval: number = null
    • options: { token: Token } = {}

    Returns { x: any; y: any }

    An object containing the coordinates of the snapped location

    • x: any
    • y: any
  • getGridPositionFromPixels(x: number, y: number): number[]
  • Given a pair of pixel coordinates, return the grid position as an Array. Always round down to the nearest grid position so the pixels are within the grid space (from top-left).

    Parameters

    • x: number

      The x-coordinate pixel position

    • y: number

      The y-coordinate pixel position

    Returns number[]

    An array representing the position in grid units

  • getPixelsFromGridPosition(x: number, y: number): number[]
  • Given a pair of grid coordinates, return the pixel position as an Array. Always round up to a whole pixel so the pixel is within the grid space (from top-left).

    Parameters

    • x: number

      The x-coordinate grid position

    • y: number

      The y-coordinate grid position

    Returns number[]

    An array representing the position in pixels

  • shiftPosition(x: number, y: number, dx: number, dy: number, options?: { token: Token }): number[]
  • Shift a pixel position [x,y] by some number of grid units dx and dy

    Parameters

    • x: number

      The starting x-coordinate in pixels

    • y: number

      The starting y-coordinate in pixels

    • dx: number

      The number of grid positions to shift horizontally

    • dy: number

      The number of grid positions to shift vertically

    • options: { token: Token } = {}

    Returns number[]

  • Measure the distance traversed over an array of measured segments

    Parameters

    • segments: any[]

      An Array of measured movement segments

    • options: MeasureDistancesOptions = {}

      Additional options which modify the measurement

    Returns number[]

    An Array of distance measurements for each segment

  • getNeighbors(row: number, col: number): [number, number][]
  • Get the grid row and column positions which are neighbors of a certain position

    Parameters

    • row: number

      The grid row coordinate against which to test for neighbors

    • col: number

      The grid column coordinate against which to test for neighbors

    Returns [number, number][]

    An array of grid positions which are neighbors of the row and column

  • Determine a placeable's bounding box based on the size of the grid.

    Parameters

    • w: number

      The width in grid spaces.

    • h: number

      The height in grid spaces.

    Returns Rectangle

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

    internal

    Parameters

    • ray: Ray

      The ray being moved along.

    • offset: Point

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

    • token: Token

      The token placeable being moved.

    Returns { x: number; y: number }

    • x: number
    • y: number
  • _testShape(x: number, y: number, shape: Polygon): boolean
  • Tests whether the given co-ordinates at the center of a grid space are contained within a given shape.

    Parameters

    • x: number

      The X co-ordinate.

    • y: number

      The Y co-ordinate.

    • shape: Polygon

      The shape.

    Returns boolean

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

  • calculatePadding(gridType: number, width: number, height: number, size: number, padding: number, options?: { legacy: boolean }): { width: number; height: number; 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: number

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

    • width: number

      The width of the scene.

    • height: number

      The height of the scene.

    • size: number

      The grid size.

    • padding: number

      The percentage of padding.

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

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

    • width: number
    • height: number
    • x: number
    • y: number