mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 21:24:14 +00:00
1ecd6c4ee1
Resolve #1652 1. Add the ability to toggle **gold donations** and **troop donations** for private lobbies ~2. Add relevant translations.~ 3. Refactor `canDonate` to be specific to gold and troop donations 4. Add placeholders for singleplayer mode if this is to be extended to support that too. 5. Add Tests for Donate logic <img width="1643" height="1788" alt="image" src="https://github.com/user-attachments/assets/82b93400-a1f0-45f0-8b2b-a7f78dc0c3e9" /> _Private Lobby_  _Testing Troop Send In Private Lobby_  _Troop Send Complete In Private Lobby_  Confirming that public teams still works - [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 have read and accepted the CLA agreement (only required once). regression is found: DISCORD_USERNAME: cool_clarky --------- Co-authored-by: Scott Anderson <662325+scottanderson@users.noreply.github.com> Co-authored-by: Drills Kibo <59177241+drillskibo@users.noreply.github.com>
86 lines
2.2 KiB
TypeScript
86 lines
2.2 KiB
TypeScript
import fs from "fs";
|
|
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,
|
|
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}/mini_map.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.mini_map,
|
|
miniMapBinBuffer,
|
|
);
|
|
|
|
// Configure the game
|
|
const serverConfig = new TestServerConfig();
|
|
const gameConfig: GameConfig = {
|
|
gameMap: GameMapType.Asia,
|
|
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);
|
|
}
|