Files
OpenFrontIO/tests/util/Setup.ts
T
evanpelle 0dc68ced31 Add pause button when replaying (#726)
## Description:

This PR does two things:

1. Allow pausing on replay
2. As part of the refactoring, in singleplayer games, LocalServer now
waits for the last turn to complete execution before sending the next
turn. Previously, low end devices would sometimes fall behind getting
the "playing the past" bug where commands were delayed. Now when a
devices cannot keep up, the entire game slows down.

## Please complete the following:

- [ ] I have added screenshots for all UI updates
- [ ] I confirm I have thoroughly tested these changes and take full
responsibility for any bugs introduced
- [ ] 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>

Co-authored-by: evan <openfrontio@gmail.com>
2025-05-11 13:28:38 -07:00

59 lines
1.7 KiB
TypeScript

import fs from "fs/promises";
import path from "path";
import {
Difficulty,
Game,
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: GameConfig = {},
humans: PlayerInfo[] = [],
): Promise<Game> {
// 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 = {
gameMap: null,
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,
);
// Create and return the game
return createGame(humans, [], gameMap, miniGameMap, config);
}
export function playerInfo(name: string, type: PlayerType): PlayerInfo {
return new PlayerInfo("fr", name, type, null, name);
}