Merge pull request #139 from BeGj/fix/click-outside-map-for-findWarshipsNearCell

handle findWarshipsNearCell (unhandled exception) when clicking outside the map
This commit is contained in:
evanpelle
2025-03-04 06:33:37 -08:00
committed by GitHub
+4
View File
@@ -82,6 +82,10 @@ export class UnitLayer implements Layer {
* @returns Array of player's warships in range, sorted by distance (closest first)
*/
private findWarshipsNearCell(cell: { x: number; y: number }): UnitView[] {
if (!this.game.isValidCoord(cell.x, cell.y)) {
// The cell coordinate were invalid (user probably clicked outside the map), therefore no warships can be found
return [];
}
const clickRef = this.game.ref(cell.x, cell.y);
// Make sure we have the current player