screeps-clockwork 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,8 @@
1
1
  import { ClockworkCostMatrix } from '../wasm/screeps_clockwork';
2
+ import { ClockworkFlowField } from './flowField';
3
+ import { ClockworkMonoFlowField } from './monoFlowField';
4
+ import { ClockworkMultiroomFlowField } from './multiroomFlowField';
5
+ import { ClockworkMultiroomMonoFlowField } from './multiroomMonoFlowField';
2
6
  /**
3
7
  * Generate a [flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html) for a set of positions
4
8
  * using Dijkstra's algorithm.
@@ -12,7 +16,7 @@ import { ClockworkCostMatrix } from '../wasm/screeps_clockwork';
12
16
  * @param costMatrix - The cost matrix to use for the flow field.
13
17
  * @returns The flow field.
14
18
  */
15
- export declare function dijkstraFlowField(start: RoomPosition[], costMatrix: ClockworkCostMatrix): import("../wasm/screeps_clockwork").FlowField;
19
+ export declare function dijkstraFlowField(start: RoomPosition[], costMatrix: ClockworkCostMatrix): ClockworkFlowField;
16
20
  /**
17
21
  * Generate a [mono-directional flow field](https://glitchassassin.github.io/screeps-clockwork/primitives/flowfield.html)
18
22
  * for a set of positions using Dijkstra's algorithm.
@@ -29,4 +33,44 @@ export declare function dijkstraFlowField(start: RoomPosition[], costMatrix: Clo
29
33
  * @param costMatrix - The cost matrix to use for the flow field.
30
34
  * @returns The flow field.
31
35
  */
32
- export declare function dijkstraMonoFlowField(start: RoomPosition[], costMatrix: ClockworkCostMatrix): import("../wasm/screeps_clockwork").MonoFlowField;
36
+ export declare function dijkstraMonoFlowField(start: RoomPosition[], costMatrix: ClockworkCostMatrix): ClockworkMonoFlowField;
37
+ /**
38
+ * Generate a multiroom flow field for a set of positions using Dijkstra's algorithm.
39
+ *
40
+ * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
41
+ *
42
+ * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
43
+ * a cost matrix with a default value of at least 1.
44
+ *
45
+ * @param start - The starting positions.
46
+ * @param costMatrixCallback - A function that returns a cost matrix for a given room name.
47
+ * @param options - Options for the flow field generation.
48
+ * @returns The flow field.
49
+ */
50
+ export declare function dijkstraMultiroomFlowField(start: RoomPosition[], { costMatrixCallback, maxTiles, maxRooms, maxRoomDistance, maxTileDistance }: {
51
+ costMatrixCallback: (roomName: string) => ClockworkCostMatrix | undefined;
52
+ maxTiles?: number;
53
+ maxRooms?: number;
54
+ maxRoomDistance?: number;
55
+ maxTileDistance?: number;
56
+ }): ClockworkMultiroomFlowField;
57
+ /**
58
+ * Generate a multiroom mono-directional flow field for a set of positions using Dijkstra's algorithm.
59
+ *
60
+ * Dijkstra's algorithm includes variable costs to account for terrain or other cost functions.
61
+ *
62
+ * Note that values of 0 in the cost matrix may have unexpected behavior. You probably want
63
+ * a cost matrix with a default value of at least 1.
64
+ *
65
+ * @param start - The starting positions.
66
+ * @param costMatrixCallback - A function that returns a cost matrix for a given room name.
67
+ * @param options - Options for the flow field generation.
68
+ * @returns The flow field.
69
+ */
70
+ export declare function dijkstraMultiroomMonoFlowField(start: RoomPosition[], { costMatrixCallback, maxTiles, maxRooms, maxRoomDistance, maxTileDistance }: {
71
+ costMatrixCallback: (roomName: string) => ClockworkCostMatrix | undefined;
72
+ maxTiles?: number;
73
+ maxRooms?: number;
74
+ maxRoomDistance?: number;
75
+ maxTileDistance?: number;
76
+ }): ClockworkMultiroomMonoFlowField;
@@ -0,0 +1,29 @@
1
+ import { DistanceMap } from '../wasm/screeps_clockwork';
2
+ import { Path } from './path';
3
+ /**
4
+ * A distance map for a single room.
5
+ */
6
+ export declare class ClockworkDistanceMap {
7
+ private _map;
8
+ constructor(_map: DistanceMap);
9
+ /**
10
+ * Gets the distance value at a given position.
11
+ */
12
+ get(x: number, y: number): number;
13
+ /**
14
+ * Sets the distance value at a given position.
15
+ */
16
+ set(x: number, y: number, value: number): void;
17
+ /**
18
+ * Converts the distance map into a flat array of distances.
19
+ */
20
+ toArray(): Uint32Array;
21
+ /**
22
+ * Frees the memory allocated for this distance map.
23
+ */
24
+ free(): void;
25
+ /**
26
+ * Path to the origin from a given position.
27
+ */
28
+ pathToOrigin(start: RoomPosition): Path;
29
+ }
@@ -0,0 +1,38 @@
1
+ import { FlowField } from '../wasm/screeps_clockwork';
2
+ import { Path } from './path';
3
+ /**
4
+ * A flow field for a single room that stores multiple directions per tile.
5
+ */
6
+ export declare class ClockworkFlowField {
7
+ private _flowField;
8
+ constructor(_flowField: FlowField);
9
+ /**
10
+ * Get the internal value for a given coordinate.
11
+ */
12
+ get(x: number, y: number): number;
13
+ /**
14
+ * Set the internal value for a given coordinate.
15
+ */
16
+ set(x: number, y: number, value: number): void;
17
+ /**
18
+ * Get the list of valid directions for a given coordinate.
19
+ */
20
+ getDirections(x: number, y: number): DirectionConstant[];
21
+ /**
22
+ * Set the list of valid directions for a given coordinate.
23
+ */
24
+ setDirections(x: number, y: number, directions: DirectionConstant[]): void;
25
+ /**
26
+ * Add a direction to the list of valid directions for a given coordinate.
27
+ */
28
+ addDirection(x: number, y: number, direction: DirectionConstant): void;
29
+ /**
30
+ * Free the memory allocated for this flow field.
31
+ */
32
+ free(): void;
33
+ /**
34
+ * Given a flow field (for a single room), find the path from a given position to
35
+ * the origin. Never paths through other rooms.
36
+ */
37
+ pathToOrigin(start: RoomPosition): Path;
38
+ }
@@ -0,0 +1,26 @@
1
+ import { MonoFlowField } from '../wasm/screeps_clockwork';
2
+ import { Path } from './path';
3
+ /**
4
+ * A flow field for a single room that stores one direction per tile.
5
+ */
6
+ export declare class ClockworkMonoFlowField {
7
+ private _flowField;
8
+ constructor(_flowField: MonoFlowField);
9
+ /**
10
+ * Get the direction for a given coordinate.
11
+ */
12
+ get(x: number, y: number): DirectionConstant | undefined;
13
+ /**
14
+ * Set the direction for a given coordinate.
15
+ */
16
+ set(x: number, y: number, value?: DirectionConstant): void;
17
+ /**
18
+ * Free the memory allocated for this flow field.
19
+ */
20
+ free(): void;
21
+ /**
22
+ * Given a monodirectional flow field (for a single room), find the path from a given position to
23
+ * the origin. Never paths through other rooms.
24
+ */
25
+ pathToOrigin(start: RoomPosition): Path;
26
+ }
@@ -0,0 +1,34 @@
1
+ import { DistanceMap, MultiroomDistanceMap } from '../wasm/screeps_clockwork';
2
+ import { Path } from './path';
3
+ /**
4
+ * A distance map that covers multiple rooms. Typically returned by a function
5
+ * like `bfsMultiroomDistanceMap` rather than created directly.
6
+ */
7
+ export declare class ClockworkMultiroomDistanceMap {
8
+ private _map;
9
+ constructor(_map: MultiroomDistanceMap);
10
+ /**
11
+ * Get the stored value for a given position.
12
+ */
13
+ get(pos: RoomPosition): number;
14
+ /**
15
+ * Set the stored value for a given position.
16
+ */
17
+ set(pos: RoomPosition, value: number): void;
18
+ /**
19
+ * Get the DistanceMap for a given room.
20
+ */
21
+ getRoom(room: string): DistanceMap | undefined;
22
+ /**
23
+ * List all the rooms covered by this distance map.
24
+ */
25
+ getRooms(): string[];
26
+ /**
27
+ * Free the memory allocated for this distance map.
28
+ */
29
+ free(): void;
30
+ /**
31
+ * Path to the origin from a given position.
32
+ */
33
+ pathToOrigin(start: RoomPosition): Path;
34
+ }
@@ -0,0 +1,46 @@
1
+ import { MultiroomFlowField } from '../wasm/screeps_clockwork';
2
+ import { ClockworkFlowField } from './flowField';
3
+ import { Path } from './path';
4
+ /**
5
+ * A flow field that spans multiple rooms, storing multiple directions per tile.
6
+ */
7
+ export declare class ClockworkMultiroomFlowField {
8
+ private _flowField;
9
+ constructor(_flowField: MultiroomFlowField);
10
+ /**
11
+ * Get the flow field value at a given position.
12
+ */
13
+ get(pos: RoomPosition): number;
14
+ /**
15
+ * Set the flow field value at a given position.
16
+ */
17
+ set(pos: RoomPosition, value: number): void;
18
+ /**
19
+ * Get the list of valid directions at a given position.
20
+ */
21
+ getDirections(pos: RoomPosition): DirectionConstant[];
22
+ /**
23
+ * Set the list of valid directions at a given position.
24
+ */
25
+ setDirections(pos: RoomPosition, directions: DirectionConstant[]): void;
26
+ /**
27
+ * Add a direction to the list of valid directions at a given position.
28
+ */
29
+ addDirection(pos: RoomPosition, direction: DirectionConstant): void;
30
+ /**
31
+ * Get the list of rooms in the flow field.
32
+ */
33
+ getRooms(): string[];
34
+ /**
35
+ * Get the flow field for a given room.
36
+ */
37
+ getRoom(roomName: string): ClockworkFlowField | null;
38
+ /**
39
+ * Find a path from a given position to the origin of the flow field.
40
+ */
41
+ pathToOrigin(start: RoomPosition): Path;
42
+ /**
43
+ * Free the memory allocated for this flow field.
44
+ */
45
+ free(): void;
46
+ }
@@ -0,0 +1,34 @@
1
+ import { MultiroomMonoFlowField } from '../wasm/screeps_clockwork';
2
+ import { ClockworkMonoFlowField } from './monoFlowField';
3
+ import { Path } from './path';
4
+ /**
5
+ * A flow field that spans multiple rooms, storing a single direction per tile.
6
+ */
7
+ export declare class ClockworkMultiroomMonoFlowField {
8
+ private _flowField;
9
+ constructor(_flowField: MultiroomMonoFlowField);
10
+ /**
11
+ * Get the direction at a given position.
12
+ */
13
+ get(pos: RoomPosition): DirectionConstant | null;
14
+ /**
15
+ * Set the direction at a given position.
16
+ */
17
+ set(pos: RoomPosition, direction: DirectionConstant | null): void;
18
+ /**
19
+ * Get the list of rooms in the flow field.
20
+ */
21
+ getRooms(): string[];
22
+ /**
23
+ * Get the flow field for a given room.
24
+ */
25
+ getRoom(roomName: string): ClockworkMonoFlowField | null;
26
+ /**
27
+ * Find a path from a given position to the origin of the flow field.
28
+ */
29
+ pathToOrigin(start: RoomPosition): Path;
30
+ /**
31
+ * Free the memory allocated for this flow field.
32
+ */
33
+ free(): void;
34
+ }
@@ -1,7 +1,21 @@
1
1
  import { Path as ClockworkPath } from '../wasm/screeps_clockwork';
2
+ /**
3
+ * A path from a start position to an end position. Typically returned by a
4
+ * function like `pathToFlowFieldOrigin` rather than created directly.
5
+ */
2
6
  export declare class Path {
3
7
  private readonly path;
4
8
  constructor(path: ClockworkPath);
9
+ /**
10
+ * Iterate over the path.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * for (const pos of path) {
15
+ * console.log(pos);
16
+ * }
17
+ * ```
18
+ */
5
19
  [Symbol.iterator](): {
6
20
  next: () => {
7
21
  value: RoomPosition;
@@ -9,7 +23,14 @@ export declare class Path {
9
23
  };
10
24
  };
11
25
  /**
12
- * Iterate over the path in reverse order
26
+ * Iterate over the path in reverse order.
27
+ *
28
+ * @example
29
+ * ```typescript
30
+ * for (const pos of path.reversed()) {
31
+ * console.log(pos);
32
+ * }
33
+ * ```
13
34
  */
14
35
  reversed(): Generator<never, {
15
36
  next: () => {
@@ -17,10 +38,28 @@ export declare class Path {
17
38
  done: boolean;
18
39
  };
19
40
  }, unknown>;
41
+ /**
42
+ * Get the position at a given index.
43
+ */
20
44
  get(index: number): RoomPosition;
45
+ /**
46
+ * Get the length of the path.
47
+ */
21
48
  get length(): number;
22
- findNextIndex(index: number): number | undefined;
49
+ /**
50
+ * Given a current position, find the index of the next position in the path.
51
+ */
52
+ findNextIndex(pos: RoomPosition): number | undefined;
53
+ /**
54
+ * Convert the path to an array of positions.
55
+ */
23
56
  toArray(): RoomPosition[];
57
+ /**
58
+ * Convert the path to an array of positions in reverse order.
59
+ */
24
60
  toArrayReversed(): RoomPosition[];
61
+ /**
62
+ * Free the memory allocated for this path.
63
+ */
25
64
  free(): void;
26
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screeps-clockwork",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "A WASM movement library for Screeps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -36,19 +36,19 @@
36
36
  "@rollup/plugin-node-resolve": "^15.1.0",
37
37
  "@rollup/plugin-typescript": "^12.1.1",
38
38
  "@rollup/plugin-wasm": "^6.2.2",
39
- "@types/node": "^22.9.3",
39
+ "@types/node": "^22.10.1",
40
40
  "@types/screeps": "^3.3.0",
41
- "@typescript-eslint/eslint-plugin": "^8.15.0",
42
- "@typescript-eslint/parser": "^8.15.0",
43
- "eslint": "^9.15.0",
41
+ "@typescript-eslint/eslint-plugin": "^8.17.0",
42
+ "@typescript-eslint/parser": "^8.17.0",
43
+ "eslint": "^9.16.0",
44
44
  "npm-run-all": "^4.1.5",
45
- "prettier": "^3.3.3",
45
+ "prettier": "^3.4.2",
46
46
  "rollup": "2.79.2",
47
47
  "rollup-plugin-clear": "^2.0.7",
48
48
  "rollup-plugin-copy": "^3.5.0",
49
49
  "rollup-plugin-screeps": "^1.0.1",
50
50
  "source-map": "0.6.1",
51
- "typedoc": "^0.27.0-beta.2",
51
+ "typedoc": "^0.27.3",
52
52
  "typescript": "^5.7.2"
53
53
  },
54
54
  "dependencies": {
@@ -1,3 +0,0 @@
1
- import { DistanceMap } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
3
- export declare function pathToDistanceMapOrigin(start: RoomPosition, distanceMap: DistanceMap): Path;
@@ -1,3 +0,0 @@
1
- import { FlowField } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
3
- export declare function pathToFlowFieldOrigin(start: RoomPosition, flowField: FlowField): Path;
@@ -1,3 +0,0 @@
1
- import { MonoFlowField } from '../wasm/screeps_clockwork';
2
- import { Path } from './path';
3
- export declare function pathToMonoFlowFieldOrigin(start: RoomPosition, flowField: MonoFlowField): Path;