@2d-game-grid/square
Version:
A simple square grid made for games
71 lines (70 loc) • 3.04 kB
TypeScript
import type { Column, Coordinate, Row } from '@2d-game-grid/core';
import { Cell } from '@2d-game-grid/core';
import { SquareNeighbors } from './SquareNeighbors.js';
import type { DistanceAlgorithm, PathfindingOptions } from './algorithms/index.js';
import type { SquareGrid } from './SquareGrid.js';
import { SquareEdges } from './SquareEdges.js';
import { SquareCorners } from './SquareCorners.js';
import type { SquareDirections } from './SquareDirections.js';
/**
* A Cell is part of a grid. It contains meta information like its coordinates inside the grid and the corresponding value.
*/
export declare class SquareCell<Value> extends Cell<Value, SquareDirections> {
protected readonly grid: SquareGrid<Value>;
/**
* An instance of the cells' neighbors
*/
readonly neighbors: SquareNeighbors<Value>;
/**
* An instance of the cells' edges
*/
readonly edges: SquareEdges<Value>;
/**
* An instance of the cells' corners
*/
readonly corners: SquareCorners<Value>;
/**
*
* @param grid The grid this cell is part of
* @param coordinate The coordinate in the grid
* @param value The value of the cell
*/
constructor(grid: SquareGrid<Value>, coordinate: Coordinate, value: Value);
/**
* @param target The coordinate that the distance should be calculated for
* @param algorithm The used algorithm for the distance calculation
* @returns The distance
*/
getDistance(target: Coordinate, algorithm?: DistanceAlgorithm): number;
/**
* @param maxDistance The maximum distance (including) to a cell that should be returned
* @param algorithm The used algorithm for the distance calculation
* @returns All cells that are in the distance (excluding this cell)
*/
listCellsInDistance(maxDistance: number, algorithm?: DistanceAlgorithm): SquareCell<Value>[];
/**
* @param target The coordinate that the path should end
* @param options The options to customize the pathfinding
* @returns The shortest path including this cell and the target cell
*/
getPath(target: Coordinate, options?: PathfindingOptions<Value>): SquareCell<Value>[];
/**
* @param maxPathSteps The maximum amount of steps to a cell that should be returned (start and end cell included)
* @param options The options to customize the pathfinding
* @returns All cells that are reachable (excluding the start cell)
*/
listReachableCells(maxPathSteps: number, options?: PathfindingOptions<Value>): SquareCell<Value>[];
/**
* @returns The row of the cell
*/
getRow(): Row<Value, SquareDirections, SquareCell<Value>>;
/**
@returns The column of the cell
*/
getColumn(): Column<Value, SquareDirections, SquareCell<Value>>;
/**
* @param cloneValue A custom function to clone the value of this cell (defaults to copying the value)
* @returns The cloned cell
*/
clone(cloneValue?: (value: Value) => Value): SquareCell<Value>;
}