mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 10:53:31 +00:00
Perf: tradeship spawn (#3240)
## Description: Please merge for v30 if possible. Use .find instead of .filter for tradeShipSpawn since we're only looking for the first (if any) port found at the given tile anyway. Also just return targetTile instead of getting porr.tile() because targetTile is tile we found the port on. Also use no intermediate const, just return right away based on outcome of units.find. Found when working on PR #3220. But tradeShipSpawn is out of 3220's scope since it won't be called by playerImpl buildableUnits() anymore, it should and will be only ever used by TradeShipExecution via playerImpl canBuild(). ## 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:
@@ -1258,13 +1258,9 @@ export class PlayerImpl implements Player {
|
||||
}
|
||||
|
||||
tradeShipSpawn(targetTile: TileRef): TileRef | false {
|
||||
const spawns = this.units(UnitType.Port).filter(
|
||||
(u) => u.tile() === targetTile,
|
||||
);
|
||||
if (spawns.length === 0) {
|
||||
return false;
|
||||
}
|
||||
return spawns[0].tile();
|
||||
return this.units(UnitType.Port).find((u) => u.tile() === targetTile)
|
||||
? targetTile
|
||||
: false;
|
||||
}
|
||||
lastTileChange(): Tick {
|
||||
return this._lastTileChange;
|
||||
|
||||
Reference in New Issue
Block a user