From 16ad8e87b4f83d556e56bda3eb7dd1ba2cafbf31 Mon Sep 17 00:00:00 2001 From: zyzyzyryxy <31672205+zyzyzyryxy@users.noreply.github.com> Date: Fri, 5 Jan 2024 21:37:55 +0100 Subject: [PATCH 1/4] Fix lookForAtArea matrix result type. --- dist/index.d.ts | 6 +++--- dist/screeps-tests.ts | 6 +++++- src/helpers.ts | 4 ++-- src/room.ts | 2 +- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dist/index.d.ts b/dist/index.d.ts index 359e968..b69ffcc 100644 --- a/dist/index.d.ts +++ b/dist/index.d.ts @@ -1825,9 +1825,9 @@ interface LookAtResultMatrix { }; } -interface LookForAtAreaResultMatrix { +interface LookForAtAreaResultMatrix { [y: number]: { - [x: number]: Array>; + [x: number]: T[]; }; } @@ -4546,7 +4546,7 @@ interface Room { bottom: number, right: number, asArray?: false, - ): LookForAtAreaResultMatrix; + ): LookForAtAreaResultMatrix; /** * Get the given objets in the supplied area. * @param type One of the LOOK_* constants diff --git a/dist/screeps-tests.ts b/dist/screeps-tests.ts index 15b1a81..a09c5d9 100644 --- a/dist/screeps-tests.ts +++ b/dist/screeps-tests.ts @@ -908,13 +908,17 @@ function resources(o: GenericStore): ResourceConstant[] { const x = flags[10]; const y = x[11]; const entry = y[0]; - entry.flag.remove(); + entry.remove(); const creeps = room.lookForAtArea(LOOK_CREEPS, 10, 10, 20, 20, true); creeps[0].x; creeps[0].y; creeps[0].creep.move(TOP); + + const structuresMatrix = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20); + + structuresMatrix[15][15].find((s) => s.structureType === STRUCTURE_CONTROLLER); } // StoreDefinition diff --git a/src/helpers.ts b/src/helpers.ts index 5461fda..78d5faa 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -226,9 +226,9 @@ interface LookAtResultMatrix { }; } -interface LookForAtAreaResultMatrix { +interface LookForAtAreaResultMatrix { [y: number]: { - [x: number]: Array>; + [x: number]: T[]; }; } diff --git a/src/room.ts b/src/room.ts index 1d88878..13a6871 100644 --- a/src/room.ts +++ b/src/room.ts @@ -247,7 +247,7 @@ interface Room { bottom: number, right: number, asArray?: false, - ): LookForAtAreaResultMatrix; + ): LookForAtAreaResultMatrix; /** * Get the given objets in the supplied area. * @param type One of the LOOK_* constants From 6db6aef636704b21d0d494a543298ec2cf016d21 Mon Sep 17 00:00:00 2001 From: Piotr Paulski Date: Sat, 6 Jan 2024 02:36:40 +0100 Subject: [PATCH 2/4] npm run dtslint From 7f1218ae886391020758199f7850a0e49a4f9f31 Mon Sep 17 00:00:00 2001 From: Piotr Paulski Date: Sat, 6 Jan 2024 12:16:34 +0100 Subject: [PATCH 3/4] Modify new test to explicitly match issue description --- dist/screeps-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/screeps-tests.ts b/dist/screeps-tests.ts index a09c5d9..5fc1524 100644 --- a/dist/screeps-tests.ts +++ b/dist/screeps-tests.ts @@ -916,7 +916,7 @@ function resources(o: GenericStore): ResourceConstant[] { creeps[0].y; creeps[0].creep.move(TOP); - const structuresMatrix = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20); + const structuresMatrix = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20, false); structuresMatrix[15][15].find((s) => s.structureType === STRUCTURE_CONTROLLER); } From 3c5d3d1dcad0af9cc79f9d37c1d436fea5aeef4a Mon Sep 17 00:00:00 2001 From: Piotr Paulski Date: Sat, 6 Jan 2024 12:25:21 +0100 Subject: [PATCH 4/4] Separate tests for default and explicit isArray=false --- dist/screeps-tests.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/dist/screeps-tests.ts b/dist/screeps-tests.ts index 5fc1524..dda67c7 100644 --- a/dist/screeps-tests.ts +++ b/dist/screeps-tests.ts @@ -916,9 +916,15 @@ function resources(o: GenericStore): ResourceConstant[] { creeps[0].y; creeps[0].creep.move(TOP); - const structuresMatrix = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20, false); + // #252 + const structuresMatrix = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20); structuresMatrix[15][15].find((s) => s.structureType === STRUCTURE_CONTROLLER); + + // #252 with explicit isArray=false + const structuresMatrix2 = room.lookForAtArea(LOOK_STRUCTURES, 10, 10, 20, 20, false); + + structuresMatrix2[15][15].find((s) => s.structureType === STRUCTURE_CONTROLLER); } // StoreDefinition