Files
OpenFrontIO/tests/util/utils.ts
evanpelle 7a3a3a59e8 validate coords in construction execution (#1339)
## Description:

Passing in invalidate coordinates in a BuildIntent can cause
ExecutionManager to throw an exception because the coords are not
validated.

## 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
2025-07-03 20:02:39 -07:00

37 lines
1.3 KiB
TypeScript

// Either someone can straight up call player.buildUnit. It's simpler and immediate (no tick required)
// Either someone can straight up call player.buildUnit. It's simpler and immediate (no tick required)
// However buildUnit do not create executions (e.g.: WarshipExecution)
// If you also need execution use function below. Does not work with things not
import { ConstructionExecution } from "../../src/core/execution/ConstructionExecution";
import { Game, Player, UnitType } from "../../src/core/game/Game";
// built via UI (e.g.: trade ships)
export function constructionExecution(
game: Game,
_owner: Player,
x: number,
y: number,
unit: UnitType,
ticks = 4,
) {
game.addExecution(new ConstructionExecution(_owner, unit, game.ref(x, y)));
// 4 ticks by default as it usually goes like this
// Init of construction execution
// Exec construction execution
// Tick of construction execution which adds the execution related to the building/unit
// First tick of the execution of the constructed building/unit
// (sometimes step 3 and 4 are merged in one)
for (let i = 0; i < ticks; i++) {
game.executeNextTick();
}
}
export function executeTicks(game: Game, numTicks: number): void {
for (let i = 0; i < numTicks; i++) {
game.executeNextTick();
}
}