Options
All
  • Public
  • Public/Protected
  • All
Menu

A CanvasLayer responsible for drawing a square grid

Hierarchy

Index

Constructors

Properties

grid: BaseGrid

The Grid container

highlight: Container

The Grid Highlight container

highlightLayers: any = {}

Map named highlight layers

borders: Container

Placeable Object borders which are drawn overtop of the Grid

options: { name: string } = ...

Options for this layer instance.

Type declaration

  • name: string
interactiveChildren: boolean = false
renderable: boolean

Accessors

  • get type(): number
  • The grid type rendered in this Scene

    Returns number

  • get size(): number
  • A convenient reference to the pixel grid size used throughout this layer

    Returns number

  • get w(): any
  • Get grid unit width

    Returns any

  • get h(): any
  • Get grid unit height

    Returns any

  • get isHex(): boolean
  • A boolean flag for whether the current grid is hexagonal

    Returns boolean

  • get name(): string
  • The canonical name of the CanvasLayer

    Returns string

  • get hookName(): string
  • The name used by hooks to construct their hook string. Note: You should override this getter if hookName should not return the class constructor name.

    Returns string

  • get layerOptions(): any
  • inheritdoc

    Returns any

  • Return a reference to the active instance of this canvas layer

    Returns CanvasLayer

Methods

  • _draw(preview?: { type: number; dimensions: any; color: number; alpha: number; gridColor: number; gridAlpha: number }): Promise<void>
  • Draw the grid

    Parameters

    • preview: { type: number; dimensions: any; color: number; alpha: number; gridColor: number; gridAlpha: number } = {}

      Override settings used in place of those saved to the Scene data

      • type: number
      • dimensions: any
      • color: number
      • alpha: number
      • gridColor: number
      • gridAlpha: number

    Returns Promise<void>

  • 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

    Parameters

    • x: number

      The exact target location x

    • y: number

      The exact target location y

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

    Returns { x: any; y: any }

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

    Parameters

    • x: number

      Coordinate X.

    • y: number

      Coordinate Y.

    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

      Coordinate X.

    • y: number

      Coordinate Y.

    Returns number[]

    An Array [x, y] of the central point of the square which contains (x, y)

  • measureDistance(origin: { x: number; y: number }, target: { x: number; y: number }, options?: MeasureDistancesOptions): number
  • Measure the distance between two point coordinates.

    example

    Measure grid distance between two points

    let distance = canvas.grid.measureDistance({x: 1000, y: 1000}, {x: 2000, y: 2000});
    

    Parameters

    • origin: { x: number; y: number }

      The origin point

      • x: number
      • y: number
    • target: { x: number; y: number }

      The target point

      • x: number
      • y: number
    • options: MeasureDistancesOptions = {}

      Additional options which modify the measurement

    Returns number

    The measured distance between these points

  • Measure the distance traveled over an array of distance segments.

    Parameters

    • segments: any[]

      An array of measured segments

    • options: MeasureDistancesOptions = {}

      Additional options which modify the measurement

    Returns number[]

  • addHighlightLayer(name: string): any
  • Define a new Highlight graphic

    Parameters

    • name: string

      The name for the referenced highlight layer

    Returns any

  • clearHighlightLayer(name: string): void
  • Clear a specific Highlight graphic

    Parameters

    • name: string

      The name for the referenced highlight layer

    Returns void

  • destroyHighlightLayer(name: string): void
  • Destroy a specific Highlight graphic

    Parameters

    • name: string

      The name for the referenced highlight layer

    Returns void

  • getHighlightLayer(name: string): any
  • Obtain the highlight layer graphic by name

    Parameters

    • name: string

      The name for the referenced highlight layer

    Returns any

  • highlightPosition(name: string, options: any): boolean
  • Add highlighting for a specific grid position to a named highlight graphic

    Parameters

    • name: string

      The name for the referenced highlight layer

    • options: any

      Options for the grid position that should be highlighted

    Returns boolean

  • isNeighbor(r0: number, c0: number, r1: number, c1: number): boolean
  • Test if a specific row and column position is a neighboring location to another row and column coordinate

    Parameters

    • r0: number

      The original row position

    • c0: number

      The original column position

    • r1: number

      The candidate row position

    • c1: number

      The candidate column position

    Returns boolean

  • Draw the canvas layer, rendering its internal components and returning a Promise. The Promise resolves to the drawn layer once its contents are successfully rendered.

    Parameters

    • options: any = {}

    Returns Promise<CanvasLayer>

  • Deconstruct data used in the current layer in preparation to re-draw the canvas

    Parameters

    • options: any = {}

    Returns Promise<CanvasLayer>

  • _tearDown(options: any): Promise<void>
  • The inner _tearDown method which may be customized by each CanvasLayer subclass.

    Parameters

    • options: any

    Returns Promise<void>