mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:31:55 +00:00
5d9b62da4d
## Description: Create mini map option <img width="741" height="234" alt="Screenshot 2025-09-25 at 4 47 47 PM" src="https://github.com/user-attachments/assets/6c442698-8e3b-44d5-b07e-c4f0a916c3bc" /> ## 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: evan
85 lines
2.2 KiB
TypeScript
85 lines
2.2 KiB
TypeScript
import fs from "fs";
|
|
import path from "path";
|
|
import {
|
|
Difficulty,
|
|
Game,
|
|
GameMapSize,
|
|
GameMapType,
|
|
GameMode,
|
|
GameType,
|
|
PlayerInfo,
|
|
PlayerType,
|
|
} from "../../src/core/game/Game";
|
|
import { createGame } from "../../src/core/game/GameImpl";
|
|
import {
|
|
genTerrainFromBin,
|
|
MapManifest,
|
|
} from "../../src/core/game/TerrainMapLoader";
|
|
import { UserSettings } from "../../src/core/game/UserSettings";
|
|
import { GameConfig } from "../../src/core/Schemas";
|
|
import { TestConfig } from "./TestConfig";
|
|
import { TestServerConfig } from "./TestServerConfig";
|
|
|
|
export async function setup(
|
|
mapName: string,
|
|
_gameConfig: Partial<GameConfig> = {},
|
|
humans: PlayerInfo[] = [],
|
|
currentDir: string = __dirname,
|
|
): Promise<Game> {
|
|
// Suppress console.debug for tests.
|
|
console.debug = () => {};
|
|
|
|
// Simple binary file loading using fs.readFileSync()
|
|
const mapBinPath = path.join(
|
|
currentDir,
|
|
`../testdata/maps/${mapName}/map.bin`,
|
|
);
|
|
const miniMapBinPath = path.join(
|
|
currentDir,
|
|
`../testdata/maps/${mapName}/map4x.bin`,
|
|
);
|
|
const manifestPath = path.join(
|
|
currentDir,
|
|
`../testdata/maps/${mapName}/manifest.json`,
|
|
);
|
|
|
|
const mapBinBuffer = fs.readFileSync(mapBinPath);
|
|
const miniMapBinBuffer = fs.readFileSync(miniMapBinPath);
|
|
const manifest = JSON.parse(
|
|
fs.readFileSync(manifestPath, "utf8"),
|
|
) satisfies MapManifest;
|
|
|
|
const gameMap = await genTerrainFromBin(manifest.map, mapBinBuffer);
|
|
const miniGameMap = await genTerrainFromBin(manifest.map4x, miniMapBinBuffer);
|
|
|
|
// Configure the game
|
|
const serverConfig = new TestServerConfig();
|
|
const gameConfig: GameConfig = {
|
|
gameMap: GameMapType.Asia,
|
|
gameMapSize: GameMapSize.Normal,
|
|
gameMode: GameMode.FFA,
|
|
gameType: GameType.Singleplayer,
|
|
difficulty: Difficulty.Medium,
|
|
disableNPCs: false,
|
|
donateGold: false,
|
|
donateTroops: 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(name, type, null, name);
|
|
}
|