UNPKG

@2d-game-grid/square

Version:
37 lines (36 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SquareNeighbors = void 0; const core_1 = require("@2d-game-grid/core"); /** * The representation of all neighbors of a cell */ class SquareNeighbors extends core_1.Neighbors { /** * @param directions The allowed directions * @returns An array of all existing neighbor cell coordinates */ listCoordinates(directions = core_1.ALL_DIRECTIONS) { return super.listCoordinates(directions); } /** * @param directions The allowed directions * @returns An array of all existing neighbor cells */ list(directions = core_1.ALL_DIRECTIONS) { return super.list(directions); } getOffsetCoordinate(direction) { return { TOP_LEFT: { col: -1, row: -1 }, TOP: { col: 0, row: -1 }, TOP_RIGHT: { col: 1, row: -1 }, RIGHT: { col: 1, row: 0 }, BOTTOM_RIGHT: { col: 1, row: 1 }, BOTTOM: { col: 0, row: 1 }, BOTTOM_LEFT: { col: -1, row: 1 }, LEFT: { col: -1, row: 0 }, }[direction]; } } exports.SquareNeighbors = SquareNeighbors;