mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 23:41:59 +00:00
0b9d43cb46
## Description: I hope we can get this into v30? The nation count is configurable now, just like the bot count. Replaced the "Disable Nations" toggle with a nations slider (0–400) in SinglePlayer and Host Lobby modals. <img width="710" height="121" alt="Screenshot 2026-03-03 021952" src="https://github.com/user-attachments/assets/c8d0f0c3-db51-4303-95fa-dbc770460ec2" /> Public games are staying exactly the same, this is just for singleplayer and private lobby fun. Youtubers could play HvN against 400 nations, for example. Singleplayer enjoyers no longer have to play against 1 nation in HvN, they can freely choose. `GameConfig.disableNations: boolean` got replaced by `nations: number (0-400, optional)` `undefined` = map default, `0` = disabled, number = custom count Nations slider defaults to the map's nation count, shows "(MAP DEFAULT)" label when unchanged Compact map toggle reduces nations to 25% when at default, restores when toggled off (just like we already do with bots) The nation count for HvN no longer automatically matches the human count in singleplayer and private games, only in public games. **What if there aren't enough nations configured for the map?** We just use the HvN logic (Generate random nations) ### Warning **This infra PR also needs to get merged: https://github.com/openfrontio/infra/pull/263 Otherwise players can set 0 nations and get achievements.** ## 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: FloPinguin
87 lines
2.3 KiB
TypeScript
87 lines
2.3 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,
|
|
ConfigClass: typeof TestConfig = TestConfig,
|
|
): 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,
|
|
nations: "default",
|
|
donateGold: false,
|
|
donateTroops: false,
|
|
bots: 0,
|
|
infiniteGold: false,
|
|
infiniteTroops: false,
|
|
instantBuild: false,
|
|
randomSpawn: false,
|
|
..._gameConfig,
|
|
};
|
|
const config = new ConfigClass(
|
|
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);
|
|
}
|