From 4f08e573040451097c971ec509fa9de4ab80e00a Mon Sep 17 00:00:00 2001 From: VariableVince <24507472+VariableVince@users.noreply.github.com> Date: Wed, 18 Feb 2026 22:51:36 +0100 Subject: [PATCH] Small refactor: nearbyUnits readonly UnitType[] (#3236) ## Description: PR 4/x in effort to break up PR https://github.com/openfrontio/OpenFrontIO/pull/3220. Follows on already merged https://github.com/openfrontio/OpenFrontIO/pull/3235. Please see if these can be merged for v30. - **Game**/**GameImpl**/**GameView**: nearbyUnits required "UnitType | UnitType[]" for tiles, but calls UnitGrid nearbyUnits which requires "UnitType | readonly UnitType[]". Made the requirement the same for Game/GameImpl/GameView nearbyUnits. This way, we don't have make a shallow copy of the StructureTypes array everytime we want to send it as an argument. Other callers than listNukeBreakAlliance in Util.ts are unaffected. - **Util.ts**: listNukeBreakAlliance needs no shallow copy of StructureTypes anymore as argument for NearbyUnits ## 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 ## Please put your Discord username so you can be contacted if a bug or regression is found: tryout33 --- src/core/execution/Util.ts | 2 +- src/core/game/Game.ts | 2 +- src/core/game/GameImpl.ts | 2 +- src/core/game/GameView.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/execution/Util.ts b/src/core/execution/Util.ts index a4a414e89..ed33836f5 100644 --- a/src/core/execution/Util.ts +++ b/src/core/execution/Util.ts @@ -119,7 +119,7 @@ export function listNukeBreakAlliance( // Also check if any allied structures would be destroyed game - .nearbyUnits(targetTile, magnitude.outer, [...StructureTypes]) + .nearbyUnits(targetTile, magnitude.outer, StructureTypes) .forEach(({ unit }) => playersToBreakAllianceWith.add(unit.owner().smallID()), ); diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 5f17f2b01..26395acf5 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -793,7 +793,7 @@ export interface Game extends GameMap { nearbyUnits( tile: TileRef, searchRange: number, - types: UnitType | UnitType[], + types: UnitType | readonly UnitType[], predicate?: UnitPredicate, includeUnderConstruction?: boolean, ): Array<{ unit: Unit; distSquared: number }>; diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 0f807e3d3..0339fdb33 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -895,7 +895,7 @@ export class GameImpl implements Game { nearbyUnits( tile: TileRef, searchRange: number, - types: UnitType | UnitType[], + types: UnitType | readonly UnitType[], predicate?: UnitPredicate, includeUnderConstruction?: boolean, ): Array<{ unit: Unit; distSquared: number }> { diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index 974874ad1..f02e0e10b 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -711,7 +711,7 @@ export class GameView implements GameMap { nearbyUnits( tile: TileRef, searchRange: number, - types: UnitType | UnitType[], + types: UnitType | readonly UnitType[], predicate?: UnitPredicate, ): Array<{ unit: UnitView; distSquared: number }> { return this.unitGrid.nearbyUnits(