Render textured aerial maps and support legacy recovery links

This commit is contained in:
2026-10-05 18:11:12 +05:00
parent dcc3779262
commit 2cbaf45340
12 changed files with 226 additions and 35 deletions

View File

@@ -1,7 +1,7 @@
import { readFile, mkdir } from "node:fs/promises";
import { dirname, resolve } from "node:path";
import { readFile, mkdir, mkdtemp, copyFile, rm } from "node:fs/promises";
import { dirname, resolve, sep } from "node:path";
import { gunzipSync } from "node:zlib";
import { renderSurfaceMap } from "../renderer/surface-map.mjs";
import { renderSnapshot } from "../renderer/render.mjs";
const [input, output] = process.argv.slice(2);
if (!input || !output)
@@ -13,8 +13,17 @@ const terrain = JSON.parse(
maxOutputLength: 256 * 1024 * 1024,
}).toString(),
);
await mkdir(dirname(resolve(output)), { recursive: true });
const report = await renderSurfaceMap(terrain, output);
console.log(
`Rendered ${report.width} × ${report.height} map cells from ${report.columns.toLocaleString()} surface columns: ${output}`,
);
const parent = dirname(resolve(output));
await mkdir(parent, { recursive: true });
const temporary = await mkdtemp(resolve(parent, ".minegeo-map-"));
try {
const report = await renderSnapshot(terrain, [], temporary);
await copyFile(resolve(temporary, "map.webp"), resolve(output));
console.log(
`Rendered ${report.map.width} × ${report.map.height} aerial map from Y=${report.map.cameraY}: ${output}`,
);
} finally {
if (!temporary.startsWith(parent + sep))
throw new Error("Refusing to remove a map directory outside its parent");
await rm(temporary, { recursive: true, force: true });
}