fix bad tile crash (#1237)

## Description:

Sending invalid coords can cause game to crash. Make sure to validate
tile ref.

## Please complete the following:

- [x] I have added screenshots for all UI updates
- [x] I process any text displayed to the user through translateText()
and I've added it to the en.json file
- [x] I have added relevant tests to the test directory
- [x] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [x] I understand that submitting code with bugs that could have been
caught through manual testing blocks releases and new features for all
contributors

## Please put your Discord username so you can be contacted if a bug or
regression is found:
evan
This commit is contained in:
evanpelle
2025-06-20 09:49:55 -07:00
committed by GitHub
parent 0cd663df02
commit 9ae544595b
11 changed files with 57 additions and 54 deletions
+3
View File
@@ -688,6 +688,9 @@ export class GameImpl implements Game {
ref(x: number, y: number): TileRef {
return this._map.ref(x, y);
}
isValidRef(ref: TileRef): boolean {
return this._map.isValidRef(ref);
}
x(ref: TileRef): number {
return this._map.x(ref);
}
+5 -1
View File
@@ -5,7 +5,7 @@ export type TileUpdate = bigint;
export interface GameMap {
ref(x: number, y: number): TileRef;
isValidRef(ref: TileRef): boolean;
x(ref: TileRef): number;
y(ref: TileRef): number;
cell(ref: TileRef): Cell;
@@ -117,6 +117,10 @@ export class GameMapImpl implements GameMap {
return this.yToRef[y] + x;
}
isValidRef(ref: TileRef): boolean {
return this.isValidCoord(this.x(ref), this.y(ref));
}
x(ref: TileRef): number {
return this.refToX[ref];
}
+3
View File
@@ -496,6 +496,9 @@ export class GameView implements GameMap {
ref(x: number, y: number): TileRef {
return this._map.ref(x, y);
}
isValidRef(ref: TileRef): boolean {
return this._map.isValidRef(ref);
}
x(ref: TileRef): number {
return this._map.x(ref);
}