45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
import { mkdir, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
import {
|
|
optionValue,
|
|
projectPath,
|
|
projectRoot,
|
|
slugify,
|
|
} from "./lib/recipe.mjs";
|
|
import { inspectWdb } from "./lib/wdb.mjs";
|
|
|
|
const argv = process.argv.slice(2);
|
|
const sourceRoot = path.resolve(
|
|
process.env.RUNEWAKER_ROOT
|
|
?? path.join(projectRoot, "../rom-pvt-server-backups/Runewaker"),
|
|
);
|
|
const requested = optionValue(argv, "--wdb") ?? argv.find((value) => value.endsWith(".wdb"));
|
|
if (!requested) {
|
|
throw new Error("Usage: npm run runewaker:instance -- inspect-wdb --wdb dgn_name.wdb");
|
|
}
|
|
const wdbFile = path.isAbsolute(requested)
|
|
? requested
|
|
: path.join(sourceRoot, "Resource", "wdb", "dungeon", requested);
|
|
const slug = slugify(optionValue(argv, "--slug", path.parse(wdbFile).name));
|
|
const workRoot = path.join(projectRoot, "runewaker-export-work", slug, "inspection");
|
|
const nativeReportFile = path.join(workRoot, "wdb-report.json");
|
|
const summaryFile = path.join(workRoot, "wdb-environment-candidates.json");
|
|
|
|
const inspection = await inspectWdb({ wdbFile, reportFile: nativeReportFile });
|
|
const summary = {
|
|
schemaVersion: 1,
|
|
wdb: projectPath(wdbFile),
|
|
descriptorCount: inspection.report.descriptorCount,
|
|
recommendation: inspection.recommendation,
|
|
candidates: inspection.candidates.slice(0, 30).map(({ descriptor, ...candidate }) => ({
|
|
...candidate,
|
|
representativePlacement: descriptor,
|
|
})),
|
|
};
|
|
await mkdir(path.dirname(summaryFile), { recursive: true });
|
|
await writeFile(summaryFile, JSON.stringify(summary, null, 2) + "\n", "utf8");
|
|
console.log("\n[runewaker] recommendation: "
|
|
+ (summary.recommendation?.resource ?? "none")
|
|
+ " (" + (summary.recommendation?.confidence ?? "unavailable") + ")");
|
|
console.log("[runewaker] inspection: " + projectPath(summaryFile));
|