Skip to content

Commit d59641a

Browse files
committed
feat(layer): add getting of layers list
1 parent 27ddab1 commit d59641a

5 files changed

Lines changed: 32 additions & 8 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ const layer = pathfinding.createLayer(
6060
```
6161
* `grid` - _Grid with walkable tiles_
6262

63+
### ⚡️ Get list of created layers
64+
```ts
65+
pathfinding.getLayers()
66+
```
67+
68+
### ⚡️ Get layer by id
69+
```ts
70+
pathfinding.getLayer(
71+
id: string
72+
)
73+
```
74+
* `id` - _Layer id_
75+
6376
### ⚡️ Remove exist layer of grid
6477
```ts
6578
layer.remove()

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pathfinding/index.d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ export declare class Pathfinding {
2424
*/
2525
createLayer(grid: PathfindingGrid): PathfindingLayer;
2626
/**
27-
* Check for layer presence.
27+
* Get list of created layers.
28+
*/
29+
getLayers(): PathfindingLayer[];
30+
/**
31+
* Get layer by id.
2832
*
2933
* @param id - Layer id
3034
*/
31-
hasLayer(id: string): boolean;
35+
getLayer(id: string): PathfindingLayer | null;
3236
/**
3337
* Remove layer of grid.
3438
*

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pathfinding-worker",
33
"description": "Fast node.js pathfinding on workers for grid-based games",
4-
"version": "2.3.0",
4+
"version": "2.4.0",
55
"keywords": [
66
"astar",
77
"dijkstra",

src/pathfinding/index.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,19 @@ export class Pathfinding {
8686
}
8787

8888
/**
89-
* Check for layer presence.
89+
* Get list of created layers.
90+
*/
91+
public getLayers(): PathfindingLayer[] {
92+
return Array.from(this.layers.values());
93+
}
94+
95+
/**
96+
* Get layer by id.
9097
*
9198
* @param id - Layer id
9299
*/
93-
public hasLayer(id: string): boolean {
94-
return this.layers.has(id);
100+
public getLayer(id: string): PathfindingLayer | null {
101+
return this.layers.get(id) ?? null;
95102
}
96103

97104
/**
@@ -100,7 +107,7 @@ export class Pathfinding {
100107
* @param id - Layer id
101108
*/
102109
public removeLayer(id: string): void {
103-
if (!this.hasLayer(id)) {
110+
if (!this.getLayer(id)) {
104111
throw Error(`Layer with id '${id}' is not found`);
105112
}
106113

0 commit comments

Comments
 (0)