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
This commit is contained in:
VariableVince
2026-02-18 22:51:36 +01:00
committed by GitHub
parent ba2a947061
commit 4f08e57304
4 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -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()),
);
+1 -1
View File
@@ -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 }>;
+1 -1
View File
@@ -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 }> {
+1 -1
View File
@@ -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(