Files
OpenFrontIO/src/scripts/generateTerrainMaps.ts
T
Duwibi ce7a7c555d Add Falkland Islands map (#681)
## Description:
This PR adds the Falkland Islands map. It has 12 nations - most of the
regions of the islands. All use the Falkland Island flag as they don't
have their own.

## Please complete the following:

- [ ] I have added screenshots for all UI updates
- [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:

<DISCORD USERNAME>
Nikola123
2025-05-08 14:34:13 -07:00

96 lines
1.9 KiB
TypeScript

import fs from "fs/promises";
import path from "path";
import sharp from "sharp";
import { generateMap } from "./TerrainMapGenerator.js";
const maps = [
"Africa",
"Asia",
"WorldMap",
"BlackSea",
"Europe",
"EuropeClassic",
"Mars",
"Mena",
"Oceania",
"NorthAmerica",
"SouthAmerica",
"Britannia",
"GatewayToTheAtlantic",
"Australia",
"Pangaea",
"Iceland",
"BetweenTwoSeas",
"Japan",
"KnownWorld",
"FaroeIslands",
"DeglaciatedAntarctica",
"FalklandIslands",
];
const removeSmall = true;
async function loadTerrainMaps() {
await Promise.all(
maps.map(async (map) => {
const mapPath = path.resolve(
process.cwd(),
"resources",
"maps",
map + ".png",
);
const imageBuffer = await fs.readFile(mapPath);
const {
map: mainMap,
miniMap,
thumb,
} = await generateMap(imageBuffer, removeSmall, map);
const outputPath = path.join(
process.cwd(),
"resources",
"maps",
map + ".bin",
);
const miniOutputPath = path.join(
process.cwd(),
"resources",
"maps",
map + "Mini.bin",
);
const thumbOutputPath = path.join(
process.cwd(),
"resources",
"maps",
map + "Thumb.webp",
);
await Promise.all([
fs.writeFile(outputPath, mainMap),
fs.writeFile(miniOutputPath, miniMap),
sharp(Buffer.from(thumb.data), {
raw: {
width: thumb.width,
height: thumb.height,
channels: 4,
},
})
.webp({ quality: 45 })
.toFile(thumbOutputPath),
]);
}),
);
}
async function main() {
try {
await loadTerrainMaps();
console.log("Terrain maps generated successfully");
} catch (error) {
console.error("Error generating terrain maps:", error);
process.exit(1);
}
}
main();