Class Grid<PropertiesType>

Represents a grid with cells.

Type Parameters

  • PropertiesType extends object = UnknownObject

    The type of the properties of the grid cells.

Constructors

Properties

Type declaration

Use getAll instead.

allX: ((x: number) => GridCellCollection<PropertiesType>) = ...

Type declaration

Use getAllX instead.

allY: ((y: number) => GridCellCollection<PropertiesType>) = ...

Type declaration

Use getAllY instead.

cells: GridCell<PropertiesType>[][] = []

Represents the cells of the grid.

get: (<O>(x: number, y: number, overflow?: O) => O extends true
    ? GridCell<PropertiesType>
    : undefined | GridCell<PropertiesType>) = ...

Type declaration

    • <O>(x, y, overflow?): O extends true
          ? GridCell<PropertiesType>
          : undefined | GridCell<PropertiesType>
    • Gets a cell.

      Type Parameters

      • O extends boolean = true

        Whether to allow overflow. Defaults to true. If false, the cell can exist or be undefined.

      Parameters

      • x: number

        The x coordinate to check.

      • y: number

        The y coordinate to check.

      • overflow: O = ...

        Whether to allow overflow. Defaults to true.

      Returns O extends true
          ? GridCell<PropertiesType>
          : undefined | GridCell<PropertiesType>

      • The cell.

Use getCell instead.

set: ((x: number, y: number, value: GridCell<PropertiesType>) => void) = ...

Type declaration

    • (x, y, value): void
    • Sets the value of a cell in the grid.

      Parameters

      • x: number

        The x-coordinate of the cell.

      • y: number

        The y-coordinate of the cell.

      • value: GridCell<PropertiesType>

        The value to set for the cell.

      Returns void

Use setCell instead.

xSize: number

The size of the grid along the x-axis.

ySize: number

The size of the grid along the x-axis.

Methods

  • Gets an array containing all cells orthogonally adjacent to a specific cell.

    Parameters

    • x: number

      The x coordinate to check.

    • y: number

      The y coordinate to check.

    • distance: number = 1

      The distance to check. Defaults to 1.

    • fill: boolean = false

      Whether to fill the adjacent cells. Defaults to false.

    • overflow: boolean = true

      Whether to allow overflow. Defaults to true.

    Returns GridCellCollection<PropertiesType>

    • An array of all cells.
  • Gets an array containing all cells diagonally adjacent from a specific cell.

    Parameters

    • x: number

      The x coordinate to check.

    • y: number

      The y coordinate to check.

    • distance: number = 1

      The distance to check. Defaults to 1.

    • fill: boolean = false

      Whether to fill the diagonal. Defaults to false.

    • overflow: boolean = true

      Whether to allow overflow. Defaults to true.

    Returns GridCellCollection<PropertiesType>

    • An array of all cells.
  • Gets an array containing all cells that surround a cell.

    Parameters

    • x: number

      The x coordinate to check.

    • y: number

      The y coordinate to check.

    • distance: number = 1

      The distance to check. Defaults to 1.

    • fill: boolean = false

      Whether to fill the surrounding cells. Defaults to false.

    • overflow: boolean = true

      Whether to allow overflow. Defaults to true.

    Returns GridCellCollection<PropertiesType>

    • An array of all cells.
  • Resizes the grid. Merges the cells if the new grid is bigger and truncates the cells if the new grid is smaller.

    Parameters

    • xSize: number

      The new size of the grid along the x-axis.

    • OptionalySize: number

      The new size of the grid along the y-axis. Defaults to xSize.

    Returns void

  • Sets the value of a cell in the grid.

    Parameters

    • x: number

      The x-coordinate of the cell.

    • y: number

      The y-coordinate of the cell.

    • value: GridCell<PropertiesType>

      The value to set for the cell.

    Returns void

  • Calculates the distance between two points on the grid.

    Parameters

    • x1: number

      The x-coordinate of the first point.

    • y1: number

      The y-coordinate of the first point.

    • x2: number

      The x-coordinate of the second point.

    • y2: number

      The y-coordinate of the second point.

    Returns number

    The distance between the two points.

    Use your own distance function instead.

  • Gets the grid instance with the specified key.

    Type Parameters

    Parameters

    • key: symbol

      The key of the grid instance.

    Returns Grid<T>

    • The grid instance.