import { readFile, writeFile } from "node:fs/promises"; import path from "node:path"; import sharp from "sharp"; const output = path.resolve("artifacts/playtest/rom-environment-quality"); const { results } = JSON.parse(await readFile(path.join(output, "results.json"), "utf8")); const columns = ["before", "view-0", "view-1", "view-2"]; for (let start = 0; start < results.length; start += 5) { const subset = results.slice(start, start + 5); const inputs = []; for (const [row, result] of subset.entries()) { for (const [column, suffix] of columns.entries()) { try { const input = await sharp(path.join(output, `${result.slug}-${suffix}.png`)).resize(384, 240).toBuffer(); inputs.push({ input, left: column * 384, top: row * 240 }); } catch { /* Failed captures remain empty and recorded in results.json. */ } } } const file = path.join(output, `review-sheet-${Math.floor(start / 5) + 1}.jpg`); await sharp({ create: { width: 1536, height: subset.length * 240, channels: 3, background: "#161820" } }) .composite(inputs).jpeg({ quality: 90 }).toFile(file); await writeFile(file.replace(/\.jpg$/, ".json"), `${JSON.stringify({ columns, dungeons: subset.map((entry) => entry.slug) }, null, 2)}\n`); console.log(file); }