Skip to content

Commit

Permalink
feat(grid): add size getter and hasHex() method
Browse files Browse the repository at this point in the history
  • Loading branch information
flauwekeul committed Jul 26, 2022
1 parent 0748558 commit eb41e71
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/grid/grid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export class Grid<T extends Hex> implements Iterable<T> {
return 'Grid'
}

get size() {
return this.hexes.size
}

[Symbol.iterator]() {
return this.hexes.values()
}
Expand Down Expand Up @@ -51,6 +55,10 @@ export class Grid<T extends Hex> implements Iterable<T> {
return this.hexes.get(hex.toString())
}

hasHex(hex: T): boolean {
return this.hexes.has(hex.toString())
}

setHexes(hexes: Iterable<T>): this {
for (const hex of hexes) {
this.hexes.set(hex.toString(), hex)
Expand Down
1 change: 1 addition & 0 deletions src/grid/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Hex, HexCoordinates } from '../hex'

// todo: rename to Producer / HexGenerator / ...?
export interface Traverser<T extends Hex, R extends Iterable<T> = Iterable<T>> {
(createHex: (coordinates?: HexCoordinates) => T, cursor?: HexCoordinates): R
}
Expand Down

0 comments on commit eb41e71

Please sign in to comment.