mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 21:44:49 +00:00
d35d0f38cb
## Description: 1. Refactor WarshipExecution so that it takes either attrs or a warship unit. This makes testing much simpler as the unit test can construct a warship and then pass it into a warship execution 2. Have MoveWarshipExecution set the patrol tile, not the move tile so warships stay in new location instead of moving back to original location. 3. Warships no longer target trade ships outside of its patrol range. this prevents warships from wandering 4. Refactored & simplified WarshipExecution 5. Added more tests for warships 6. Move health modification from PlayerExecution to WarshipExecution since Warships are the only unit that have health 7. Move fields from WarshipExecution to the Warship unit itself, this allows other executions & components to see more data about the warship. ## Please complete the following: - [x] I have added screenshots for all UI updates - [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: <DISCORD USERNAME>
64 lines
1.8 KiB
TypeScript
64 lines
1.8 KiB
TypeScript
import fs from "fs/promises";
|
|
import path from "path";
|
|
import {
|
|
Difficulty,
|
|
Game,
|
|
GameMapType,
|
|
GameMode,
|
|
GameType,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
} from "../../src/core/game/Game";
|
|
import { createGame } from "../../src/core/game/GameImpl";
|
|
import { genTerrainFromBin } from "../../src/core/game/TerrainMapLoader";
|
|
import { UserSettings } from "../../src/core/game/UserSettings";
|
|
import { GameConfig } from "../../src/core/Schemas";
|
|
import { generateMap } from "../../src/scripts/TerrainMapGenerator";
|
|
import { TestConfig } from "./TestConfig";
|
|
import { TestServerConfig } from "./TestServerConfig";
|
|
|
|
export async function setup(
|
|
mapName: string,
|
|
_gameConfig: Partial<GameConfig> = {},
|
|
humans: PlayerInfo[] = [],
|
|
): Promise<Game> {
|
|
// Suppress console.debug for tests.
|
|
console.debug = () => {};
|
|
|
|
// Load the specified map
|
|
const mapPath = path.join(__dirname, "..", "testdata", `${mapName}.png`);
|
|
const imageBuffer = await fs.readFile(mapPath);
|
|
const { map, miniMap } = await generateMap(imageBuffer, false);
|
|
const gameMap = await genTerrainFromBin(String.fromCharCode.apply(null, map));
|
|
const miniGameMap = await genTerrainFromBin(
|
|
String.fromCharCode.apply(null, miniMap),
|
|
);
|
|
|
|
// Configure the game
|
|
const serverConfig = new TestServerConfig();
|
|
const gameConfig: GameConfig = {
|
|
gameMap: GameMapType.Asia,
|
|
gameMode: GameMode.FFA,
|
|
gameType: GameType.Singleplayer,
|
|
difficulty: Difficulty.Medium,
|
|
disableNPCs: false,
|
|
bots: 0,
|
|
infiniteGold: false,
|
|
infiniteTroops: false,
|
|
instantBuild: false,
|
|
..._gameConfig,
|
|
};
|
|
const config = new TestConfig(
|
|
serverConfig,
|
|
gameConfig,
|
|
new UserSettings(),
|
|
false,
|
|
);
|
|
|
|
return createGame(humans, [], gameMap, miniGameMap, config);
|
|
}
|
|
|
|
export function playerInfo(name: string, type: PlayerType): PlayerInfo {
|
|
return new PlayerInfo("fr", name, type, null, name);
|
|
}
|