mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-08-18 17:53:29 +00:00
reduce log spam during test: use debug logging for map generation, disable debug logging for unit tests
This commit is contained in:
@@ -32,9 +32,9 @@ export async function generateMap(
|
|||||||
const stream = Readable.from(imageBuffer);
|
const stream = Readable.from(imageBuffer);
|
||||||
const img = await decodePNGFromStream(stream);
|
const img = await decodePNGFromStream(stream);
|
||||||
|
|
||||||
console.log(`Processing Map: ${name}`);
|
console.debug(
|
||||||
console.log("Image loaded successfully");
|
`Processing Map: ${name}, dimensions: ${img.width}x${img.height}`,
|
||||||
console.log("Image dimensions:", img.width, "x", img.height);
|
);
|
||||||
|
|
||||||
const terrain: Terrain[][] = Array(img.width)
|
const terrain: Terrain[][] = Array(img.width)
|
||||||
.fill(null)
|
.fill(null)
|
||||||
@@ -98,7 +98,7 @@ async function createMiniMap(tm: Terrain[][]): Promise<Terrain[][]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processShore(map: Terrain[][]): Coord[] {
|
function processShore(map: Terrain[][]): Coord[] {
|
||||||
console.log("Identifying shorelines");
|
console.debug("Identifying shorelines");
|
||||||
const shorelineWaters: Coord[] = [];
|
const shorelineWaters: Coord[] = [];
|
||||||
for (let x = 0; x < map.length; x++) {
|
for (let x = 0; x < map.length; x++) {
|
||||||
for (let y = 0; y < map[0].length; y++) {
|
for (let y = 0; y < map[0].length; y++) {
|
||||||
@@ -120,7 +120,7 @@ function processShore(map: Terrain[][]): Coord[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processDistToLand(shorelineWaters: Coord[], map: Terrain[][]) {
|
function processDistToLand(shorelineWaters: Coord[], map: Terrain[][]) {
|
||||||
console.log(
|
console.debug(
|
||||||
"Setting Water tiles magnitude = Manhattan distance from nearest land",
|
"Setting Water tiles magnitude = Manhattan distance from nearest land",
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ function neighbors(x: number, y: number, map: Terrain[][]): Terrain[] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function processWater(map: Terrain[][], removeSmall: boolean) {
|
function processWater(map: Terrain[][], removeSmall: boolean) {
|
||||||
console.log("Processing water bodies");
|
console.debug("Processing water bodies");
|
||||||
const visited = new Set<string>();
|
const visited = new Set<string>();
|
||||||
const waterBodies: { coords: Coord[]; size: number }[] = [];
|
const waterBodies: { coords: Coord[]; size: number }[] = [];
|
||||||
|
|
||||||
@@ -209,11 +209,11 @@ function processWater(map: Terrain[][], removeSmall: boolean) {
|
|||||||
for (const coord of largestWaterBody.coords) {
|
for (const coord of largestWaterBody.coords) {
|
||||||
map[coord.x][coord.y].ocean = true;
|
map[coord.x][coord.y].ocean = true;
|
||||||
}
|
}
|
||||||
console.log(`Identified ocean with ${largestWaterBody.size} water tiles`);
|
console.debug(`Identified ocean with ${largestWaterBody.size} water tiles`);
|
||||||
|
|
||||||
if (removeSmall) {
|
if (removeSmall) {
|
||||||
// Assess size of the other water bodies and remove those smaller than min_lake_size
|
// Assess size of the other water bodies and remove those smaller than min_lake_size
|
||||||
console.log("Searching for small water bodies for removal");
|
console.debug("Searching for small water bodies for removal");
|
||||||
for (let w = 1; w < waterBodies.length; w++) {
|
for (let w = 1; w < waterBodies.length; w++) {
|
||||||
if (waterBodies[w].size < min_lake_size) {
|
if (waterBodies[w].size < min_lake_size) {
|
||||||
smallLakes++;
|
smallLakes++;
|
||||||
@@ -223,7 +223,7 @@ function processWater(map: Terrain[][], removeSmall: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(
|
console.debug(
|
||||||
`Identified and removed ${smallLakes} bodies of water smaller than ${min_lake_size} tiles`,
|
`Identified and removed ${smallLakes} bodies of water smaller than ${min_lake_size} tiles`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ function processWater(map: Terrain[][], removeSmall: boolean) {
|
|||||||
//Adjust water tile magnitudes to reflect distance from land
|
//Adjust water tile magnitudes to reflect distance from land
|
||||||
processDistToLand(shorelineWaters, map);
|
processDistToLand(shorelineWaters, map);
|
||||||
} else {
|
} else {
|
||||||
console.log("No water bodies found in the map");
|
console.debug("No water bodies found in the map");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -339,7 +339,7 @@ function removeSmallIslands(map: Terrain[][], removeSmall: boolean) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(
|
console.debug(
|
||||||
`Identified and removed ${smallIslands} islands smaller than ${min_island_size} tiles`,
|
`Identified and removed ${smallIslands} islands smaller than ${min_island_size} tiles`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -348,7 +348,7 @@ function logBinaryAsBits(data: Uint8Array, length: number = 8) {
|
|||||||
const bits = Array.from(data.slice(0, length))
|
const bits = Array.from(data.slice(0, length))
|
||||||
.map((b) => b.toString(2).padStart(8, "0"))
|
.map((b) => b.toString(2).padStart(8, "0"))
|
||||||
.join(" ");
|
.join(" ");
|
||||||
console.log(`Binary data (bits):`, bits);
|
console.debug(`Binary data (bits):`, bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNeighborCoords(x: number, y: number, map: Terrain[][]): Coord[] {
|
function getNeighborCoords(x: number, y: number, map: Terrain[][]): Coord[] {
|
||||||
@@ -372,7 +372,7 @@ async function createMapThumbnail(
|
|||||||
map: Terrain[][],
|
map: Terrain[][],
|
||||||
quality: number = 0.5,
|
quality: number = 0.5,
|
||||||
): Promise<Bitmap> {
|
): Promise<Bitmap> {
|
||||||
console.log("creating thumbnail");
|
console.debug("creating thumbnail");
|
||||||
|
|
||||||
const srcWidth = map.length;
|
const srcWidth = map.length;
|
||||||
const srcHeight = map[0].length;
|
const srcHeight = map[0].length;
|
||||||
|
|||||||
@@ -22,6 +22,9 @@ export async function setup(
|
|||||||
_gameConfig: Partial<GameConfig> = {},
|
_gameConfig: Partial<GameConfig> = {},
|
||||||
humans: PlayerInfo[] = [],
|
humans: PlayerInfo[] = [],
|
||||||
): Promise<Game> {
|
): Promise<Game> {
|
||||||
|
// Suppress console.debug for tests.
|
||||||
|
console.debug = () => {};
|
||||||
|
|
||||||
// Load the specified map
|
// Load the specified map
|
||||||
const mapPath = path.join(__dirname, "..", "testdata", `${mapName}.png`);
|
const mapPath = path.join(__dirname, "..", "testdata", `${mapName}.png`);
|
||||||
const imageBuffer = await fs.readFile(mapPath);
|
const imageBuffer = await fs.readFile(mapPath);
|
||||||
|
|||||||
Reference in New Issue
Block a user