@2d-game-grid/square
Version:
A simple square grid made for games
13 lines (11 loc) • 472 B
text/typescript
import type {SquareGrid} from '../../../SquareGrid.js'
import type {SquareCell} from '../../../SquareCell.js'
/**
* Converts the path coordinates into an array of cells
* @param grid The grid
* @param path An array of path coordinates ([x, y])
* @returns An array of cells in the same order as the path
*/
export function mapCells<Value>(grid: SquareGrid<Value>, path: number[][]): SquareCell<Value>[] {
return path.map(([col, row]) => grid.getCell({row, col}))
}