Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #252: lookForAtArea matrix result type. #253

Merged
merged 4 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1825,9 +1825,9 @@ interface LookAtResultMatrix<K extends LookConstant = LookConstant> {
};
}

interface LookForAtAreaResultMatrix<T, K extends keyof LookAtTypes = keyof LookAtTypes> {
interface LookForAtAreaResultMatrix<T> {
[y: number]: {
[x: number]: Array<LookForAtAreaResult<T, K>>;
[x: number]: T[];
};
}

Expand Down Expand Up @@ -4546,7 +4546,7 @@ interface Room {
bottom: number,
right: number,
asArray?: false,
): LookForAtAreaResultMatrix<AllLookAtTypes[T], T>;
): LookForAtAreaResultMatrix<AllLookAtTypes[T]>;
/**
* Get the given objets in the supplied area.
* @param type One of the LOOK_* constants
Expand Down
12 changes: 11 additions & 1 deletion dist/screeps-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,13 +908,23 @@ 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);

// #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
Expand Down
4 changes: 2 additions & 2 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ interface LookAtResultMatrix<K extends LookConstant = LookConstant> {
};
}

interface LookForAtAreaResultMatrix<T, K extends keyof LookAtTypes = keyof LookAtTypes> {
interface LookForAtAreaResultMatrix<T> {
[y: number]: {
[x: number]: Array<LookForAtAreaResult<T, K>>;
[x: number]: T[];
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ interface Room {
bottom: number,
right: number,
asArray?: false,
): LookForAtAreaResultMatrix<AllLookAtTypes[T], T>;
): LookForAtAreaResultMatrix<AllLookAtTypes[T]>;
/**
* Get the given objets in the supplied area.
* @param type One of the LOOK_* constants
Expand Down