Move maps generation out of repo, new map structure (#1256)
## Description: Move map generation outside of main repo, it has been rewritten in Go and is much faster. Also refactor how maps are stored, one dir per map. The map binaries are basically identical to before. Some maps like Africa have 1% difference in bytes, but playing it looks exactly the same. Use lazy loading for map data access so only needed files are accessed. Unit tests now load map binary instead of regenerating it from scratch, speeding them up. ## 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 - [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: evan
@@ -17,7 +17,10 @@ let botBehavior: BotBehavior;
|
||||
|
||||
describe("BotBehavior.handleAllianceRequests", () => {
|
||||
beforeEach(async () => {
|
||||
game = await setup("BigPlains", { infiniteGold: true, instantBuild: true });
|
||||
game = await setup("big_plains", {
|
||||
infiniteGold: true,
|
||||
instantBuild: true,
|
||||
});
|
||||
|
||||
const playerInfo = new PlayerInfo(
|
||||
undefined,
|
||||
|
||||
@@ -10,7 +10,7 @@ let player2: Player;
|
||||
|
||||
describe("Disconnected", () => {
|
||||
beforeEach(async () => {
|
||||
game = await setup("Plains", {
|
||||
game = await setup("plains", {
|
||||
infiniteGold: true,
|
||||
instantBuild: true,
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ function attackerBuildsNuke(
|
||||
|
||||
describe("MissileSilo", () => {
|
||||
beforeEach(async () => {
|
||||
game = await setup("Plains", { infiniteGold: true, instantBuild: true });
|
||||
game = await setup("plains", { infiniteGold: true, instantBuild: true });
|
||||
const attacker_info = new PlayerInfo(
|
||||
undefined,
|
||||
"fr",
|
||||
|
||||
@@ -19,7 +19,10 @@ let far_defender: Player;
|
||||
|
||||
describe("SAM", () => {
|
||||
beforeEach(async () => {
|
||||
game = await setup("BigPlains", { infiniteGold: true, instantBuild: true });
|
||||
game = await setup("big_plains", {
|
||||
infiniteGold: true,
|
||||
instantBuild: true,
|
||||
});
|
||||
const defender_info = new PlayerInfo(
|
||||
undefined,
|
||||
"us",
|
||||
|
||||
@@ -10,7 +10,7 @@ let game: Game;
|
||||
|
||||
describe("Teams", () => {
|
||||
test("bots are on the same team, but can attack each other", async () => {
|
||||
game = await setup("Plains", { gameMode: GameMode.Team, playerTeams: 2 });
|
||||
game = await setup("plains", { gameMode: GameMode.Team, playerTeams: 2 });
|
||||
|
||||
const bot1 = game.addPlayer(playerInfo("bot1", PlayerType.Bot));
|
||||
const bot2 = game.addPlayer(playerInfo("bot2", PlayerType.Bot));
|
||||
@@ -25,7 +25,7 @@ describe("Teams", () => {
|
||||
|
||||
test("humans spawn on different teams", async () => {
|
||||
game = await setup(
|
||||
"Plains",
|
||||
"plains",
|
||||
{
|
||||
gameMode: GameMode.Team,
|
||||
playerTeams: 2,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { setup } from "./util/Setup";
|
||||
|
||||
describe("Territory management", () => {
|
||||
test("player owns the tile it spawns on", async () => {
|
||||
const game = await setup("Plains");
|
||||
const game = await setup("plains");
|
||||
game.addPlayer(
|
||||
new PlayerInfo(
|
||||
undefined,
|
||||
|
||||
@@ -60,11 +60,11 @@ async function nearbyUnits(
|
||||
|
||||
describe("Unit Grid range tests", () => {
|
||||
const hasUnitCases = [
|
||||
["Plains", 0, 10, 0, true], // Same spot
|
||||
["Plains", 0, 10, 10, true], // Exactly on the range
|
||||
["Plains", 0, 10, 11, false], // Exactly 1px outside
|
||||
["BigPlains", 0, 198, 42, true], // Inside huge range
|
||||
["BigPlains", 0, 198, 199, false], // Exactly 1px outside huge range
|
||||
["plains", 0, 10, 0, true], // Same spot
|
||||
["plains", 0, 10, 10, true], // Exactly on the range
|
||||
["plains", 0, 10, 11, false], // Exactly 1px outside
|
||||
["big_plains", 0, 198, 42, true], // Inside huge range
|
||||
["big_plains", 0, 198, 199, false], // Exactly 1px outside huge range
|
||||
];
|
||||
|
||||
describe("Is unit in range", () => {
|
||||
@@ -84,13 +84,13 @@ describe("Unit Grid range tests", () => {
|
||||
});
|
||||
|
||||
const unitsInRangeCases = [
|
||||
["Plains", 0, 10, 0, [UnitType.Warship], 1], // Same spot
|
||||
["Plains", 0, 10, 0, [UnitType.City, UnitType.Port], 2], // 2 in range
|
||||
["Plains", 0, 10, 0, [], 0], // no unit
|
||||
["Plains", 0, 10, 10, [UnitType.City], 1], // Exactly on the range
|
||||
["Plains", 0, 10, 11, [UnitType.DefensePost], 0], // 1px outside
|
||||
["BigPlains", 0, 198, 42, [UnitType.TradeShip], 1], // Inside huge range
|
||||
["BigPlains", 0, 198, 199, [UnitType.TransportShip], 0], // 1px outside
|
||||
["plains", 0, 10, 0, [UnitType.Warship], 1], // Same spot
|
||||
["plains", 0, 10, 0, [UnitType.City, UnitType.Port], 2], // 2 in range
|
||||
["plains", 0, 10, 0, [], 0], // no unit
|
||||
["plains", 0, 10, 10, [UnitType.City], 1], // Exactly on the range
|
||||
["plains", 0, 10, 11, [UnitType.DefensePost], 0], // 1px outside
|
||||
["big_plains", 0, 198, 42, [UnitType.TradeShip], 1], // Inside huge range
|
||||
["big_plains", 0, 198, 199, [UnitType.TransportShip], 0], // 1px outside
|
||||
];
|
||||
|
||||
describe("Retrieve all units in range", () => {
|
||||
@@ -116,7 +116,7 @@ describe("Unit Grid range tests", () => {
|
||||
);
|
||||
|
||||
test("Wrong unit type in range", async () => {
|
||||
const game = await setup("Plains", {
|
||||
const game = await setup("plains", {
|
||||
infiniteGold: true,
|
||||
instantBuild: true,
|
||||
});
|
||||
@@ -140,7 +140,7 @@ describe("Unit Grid range tests", () => {
|
||||
});
|
||||
|
||||
test("One inside, one outside of range", async () => {
|
||||
const game = await setup("Plains", {
|
||||
const game = await setup("plains", {
|
||||
infiniteGold: true,
|
||||
instantBuild: true,
|
||||
});
|
||||
|
||||
@@ -15,7 +15,10 @@ let player: Player;
|
||||
|
||||
describe("NukeExecution", () => {
|
||||
beforeEach(async () => {
|
||||
game = await setup("BigPlains", { infiniteGold: true, instantBuild: true });
|
||||
game = await setup("big_plains", {
|
||||
infiniteGold: true,
|
||||
instantBuild: true,
|
||||
});
|
||||
|
||||
(game.config() as TestConfig).nukeMagnitudes = jest.fn(() => ({
|
||||
inner: 10,
|
||||
|
||||
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 7.1 KiB |
|
Before Width: | Height: | Size: 108 B |
|
After Width: | Height: | Size: 84 B |
|
After Width: | Height: | Size: 110 B |
|
After Width: | Height: | Size: 110 B |
|
After Width: | Height: | Size: 70 B |
|
Before Width: | Height: | Size: 120 B |
@@ -1,4 +1,4 @@
|
||||
import fs from "fs/promises";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import {
|
||||
Difficulty,
|
||||
@@ -13,7 +13,6 @@ 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";
|
||||
|
||||
@@ -25,14 +24,25 @@ export async function setup(
|
||||
// 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),
|
||||
// Simple binary file loading using fs.readFileSync()
|
||||
const mapBinPath = path.join(
|
||||
__dirname,
|
||||
`../testdata/maps/${mapName}/map.bin`,
|
||||
);
|
||||
const miniMapBinPath = path.join(
|
||||
__dirname,
|
||||
`../testdata/maps/${mapName}/mini_map.bin`,
|
||||
);
|
||||
|
||||
const mapBinBuffer = fs.readFileSync(mapBinPath);
|
||||
const miniMapBinBuffer = fs.readFileSync(miniMapBinPath);
|
||||
|
||||
// Convert Buffer to string (binary encoding)
|
||||
const mapBinString = mapBinBuffer.toString("binary");
|
||||
const miniMapBinString = miniMapBinBuffer.toString("binary");
|
||||
|
||||
const gameMap = await genTerrainFromBin(mapBinString);
|
||||
const miniGameMap = await genTerrainFromBin(miniMapBinString);
|
||||
|
||||
// Configure the game
|
||||
const serverConfig = new TestServerConfig();
|
||||
|
||||