#!/usr/bin/env node // Checks a finished character sheet: character.json passes every rule (adult, no named look, consent for a photo, // current lock text), the board is the right size and was drawn on the art the character names, every label is the // exact word the plan expects and sits on calm backdrop, each of the eight cells holds a figure and no two figures touch, // the three scene tests exist in 16:9, and the optional test clip is a real 5 second video. Then open the // board and the scene tests and check them by eye (references/output-spec.md): the same face in all eight views is // a human check, not a script's. // // Usage: // node scripts/check-sheet.mjs --character character.json [--board character-sheet.jpg] [--preview preview.webp] [--no-scenes] // // Node 18 or newer. No npm packages. ffprobe is used for the clip when it is installed. Exit code 1 when a check fails. import { createHash } from 'node:crypto' import { existsSync, readFileSync, statSync } from 'node:fs' import { spawnSync } from 'node:child_process' import { dirname, isAbsolute, join, resolve } from 'node:path' import { checkCharacter, fail, parseArgs } from './character-lib.mjs' const opts = parseArgs(process.argv.slice(2), ['character', 'board', 'preview', 'no-scenes'], ['no-scenes']) if (!opts.character) fail('Usage: node scripts/check-sheet.mjs --character character.json [--board character-sheet.jpg] [--preview preview.webp] [--no-scenes]') const readJson = (path, what) => { if (!existsSync(path)) fail(`${what} not found: ${path}`) try { return JSON.parse(readFileSync(path, 'utf8')) } catch { fail(`${what} is not valid JSON: ${path}`) } } /** Width and height from a PNG, JPEG or WebP header, without decoding the image. */ function imageSize(path) { const b = readFileSync(path) if (b.length > 24 && b.readUInt32BE(0) === 0x89504e47) return { type: 'png', width: b.readUInt32BE(16), height: b.readUInt32BE(20) } if (b.length > 4 && b[0] === 0xff && b[1] === 0xd8) { let p = 2 while (p + 9 < b.length) { if (b[p] !== 0xff) { p++; continue } const marker = b[p + 1] if (marker === 0xff) { p++; continue } if (marker === 0xd8 || marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) { p += 2; continue } const len = b.readUInt16BE(p + 2) if (marker >= 0xc0 && marker <= 0xcf && ![0xc4, 0xc8, 0xcc].includes(marker)) return { type: 'jpeg', width: b.readUInt16BE(p + 7), height: b.readUInt16BE(p + 5) } p += 2 + len } return null } if (b.length > 30 && b.toString('ascii', 0, 4) === 'RIFF' && b.toString('ascii', 8, 12) === 'WEBP') { const chunk = b.toString('ascii', 12, 16) if (chunk === 'VP8 ') return { type: 'webp', width: b.readUInt16LE(26) & 0x3fff, height: b.readUInt16LE(28) & 0x3fff } if (chunk === 'VP8L') { const bits = b.readUInt32LE(21) return { type: 'webp', width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 } } if (chunk === 'VP8X') return { type: 'webp', width: 1 + b.readUIntLE(24, 3), height: 1 + b.readUIntLE(27, 3) } } return null } const sha = (path) => createHash('sha256').update(readFileSync(path)).digest('hex') const issues = [] const warnings = [] const notes = [] const layout = JSON.parse(readFileSync(new URL('../assets/layout.json', import.meta.url), 'utf8')) const lim = layout.limits const ch = readJson(opts.character, 'character.json') const base = dirname(resolve(opts.character)) const fromBase = (p) => (isAbsolute(p) ? p : join(base, p)) // The character. const own = checkCharacter(ch) issues.push(...own.issues) warnings.push(...own.warnings) // The board. const boardArg = opts.board ?? ch.sheet if (!boardArg) issues.push('No board: pass --board character-sheet.jpg (or run compose-sheet.mjs, which sets character.sheet).') else { const boardPath = existsSync(resolve(boardArg)) ? resolve(boardArg) : fromBase(boardArg) const manifestPath = `${boardPath}.json` if (!existsSync(boardPath)) issues.push(`Board not found: ${boardPath}`) else if (!existsSync(manifestPath)) issues.push(`${manifestPath} is missing. Run scripts/compose-sheet.mjs.`) else { const m = readJson(manifestPath, 'Board record') const outDir = dirname(boardPath) const dim = imageSize(boardPath) if (!dim || dim.type !== 'jpeg') issues.push(`${boardPath} is not a JPEG.`) else if (dim.width !== layout.canvas.width || dim.height !== layout.canvas.height) issues.push(`The board is ${dim.width} x ${dim.height}; it is ${layout.canvas.width} x ${layout.canvas.height}.`) if (sha(boardPath) !== m.sha256) issues.push('The board has changed since it was composed (edited by hand?). Run compose-sheet.mjs again, then check.') if (m.layout_checked !== layout.checked) warnings.push(`The board was drawn against layout bands checked ${m.layout_checked}; the layout file now says ${layout.checked}. Run compose-sheet.mjs again.`) // The art it was drawn on. const artPath = join(outDir, m.art) if (!existsSync(artPath)) issues.push(`The text-free art is missing: ${artPath}`) else if (sha(artPath) !== m.art_sha256) issues.push('The board was drawn on other art than the file now at its art path. Run compose-sheet.mjs again.') if (m.art_resized) warnings.push(`The art was ${m.art_size?.width} x ${m.art_size?.height} and was resized to the board, so the label bands may not line up. Make the sheet at ${layout.canvas.width} x ${layout.canvas.height}.`) if (!ch.reference) issues.push('character.reference is empty: later shots need the text-free art as their reference. Run compose-sheet.mjs (it sets it).') else if (!existsSync(fromBase(ch.reference))) issues.push(`character.reference not found: ${fromBase(ch.reference)}`) else if (resolve(fromBase(ch.reference)) !== resolve(artPath)) issues.push('character.reference is not the art the board was drawn on.') if (ch.sheet && resolve(fromBase(ch.sheet)) !== boardPath) warnings.push('character.sheet is not this board.') if (m.character !== ch.name) issues.push(`The board was drawn for "${m.character}", but the character is now "${ch.name}". Run compose-sheet.mjs again.`) // Exact words, on calm backdrop. const expected = [ ...layout.turnaround.views.map((v) => ({ id: v.id, role: 'view', text: v.label })), ...layout.expressions.items.map((v) => ({ id: v.id, role: 'expression', text: v.label })), { id: 'name', role: 'header', text: String(ch.name ?? '').trim() }, { id: 'who', role: 'header', text: String(ch.who ?? '').trim() }, ] for (const x of expected) { const l = (m.labels ?? []).find((y) => y.id === x.id) if (!l) { issues.push(`The label "${x.text}" is missing from the board. Run compose-sheet.mjs.`); continue } if (l.text !== x.text) issues.push(`The label for ${x.id} reads "${l.text}", expected "${x.text}". Run compose-sheet.mjs again.`) if (l.x < 0 || l.y < 0 || l.x + l.width > m.width || l.y + l.height > m.height) issues.push(`The label "${l.text}" falls outside the board.`) if (l.art_under_percent > lim.max_label_art_percent) issues.push(`The label "${l.text}" sits on the art: ${l.art_under_percent}% of the pixels around it are not backdrop (over ${lim.max_label_art_percent}%). A foot, a hand or a shadow runs into its band: re-roll the sheet with the figures smaller and higher, or say the bottom band stays empty (references/prompt-patterns.md).`) if (!(l.contrast >= lim.min_label_contrast)) issues.push(`The label "${l.text}" has contrast ${l.contrast}:1, under ${lim.min_label_contrast}:1.`) } if ((m.labels ?? []).length !== expected.length) issues.push(`The board has ${(m.labels ?? []).length} labels; expected ${expected.length}.`) // Eight cells, each with a figure; no two figures touching. for (const c of m.cells ?? []) if (c.fill_percent < lim.min_cell_fill_percent) issues.push(`The ${c.id} ${c.role === 'view' ? 'view' : 'portrait'} cell holds only ${c.fill_percent}% art (under ${lim.min_cell_fill_percent}%): that figure is missing, tiny or somewhere else. Re-roll.`) if ((m.cells ?? []).length !== 8) issues.push(`The board lists ${(m.cells ?? []).length} cells; expected 8 (four views and four portraits).`) if (!Array.isArray(m.gaps)) issues.push('The board record has no gap measures. Run compose-sheet.mjs again.') for (const g of m.gaps ?? []) { if (g.clear_px < lim.min_gap_px) issues.push(`The ${g.between} touch or overlap (the clear gap "${g.id}" is ${g.clear_px} px, under ${lim.min_gap_px} px). Re-roll with the figures smaller or the gaps wider.`) else if (g.clear_px < lim.warn_gap_px) warnings.push(`The ${g.between} nearly touch (a clear gap of ${g.clear_px} px). Look at it by eye.`) } notes.push(`Board ${boardPath}: ${dim?.width} x ${dim?.height}, ${Math.round(statSync(boardPath).size / 1024)} KB, ${(m.labels ?? []).length} labels, worst art under a label ${Math.max(0, ...(m.labels ?? []).map((l) => l.art_under_percent))}%.`) } } // Scene tests (16:9), the optional second outfit and clip. const wide = (d) => d && Math.abs(d.width / d.height - 16 / 9) / (16 / 9) < 0.02 if (!opts['no-scenes']) { let made = 0 for (const s of ch.scenes ?? []) { if (!s.image) { issues.push(`Scene test ${s.n} has no image yet.`); continue } const p = fromBase(s.image) if (!existsSync(p)) { issues.push(`Scene test ${s.n} image not found: ${p}`); continue } const d = imageSize(p) if (!d) issues.push(`Scene test ${s.n} (${s.image}) is not a readable JPEG, PNG or WebP.`) else if (!wide(d)) issues.push(`Scene test ${s.n} is ${d.width} x ${d.height}; it should be 16:9.`) else if (Math.min(d.width, d.height) < 720) warnings.push(`Scene test ${s.n} is ${d.width} x ${d.height}, small for a face check. Make it at 1K or larger.`) made++ } if (made === 3) notes.push('Three scene tests present, 16:9.') } if (ch.alt_outfit) { const p = fromBase(ch.alt_outfit) if (!existsSync(p)) issues.push(`The second outfit image is missing: ${p}`) else if (!ch.wardrobe_alt) issues.push('alt_outfit is set but wardrobe_alt is empty.') } if (ch.clip) { const p = fromBase(typeof ch.clip === 'string' ? ch.clip : ch.clip.file ?? '') if (!existsSync(p)) issues.push(`The test clip is missing: ${p}`) else { const probe = spawnSync('ffprobe', ['-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=codec_name,width,height:format=duration', '-of', 'json', p], { encoding: 'utf8' }) if (probe.error || probe.status !== 0) warnings.push('ffprobe is not available, so the test clip was not measured. Check it plays and runs about 5 seconds.') else { const j = JSON.parse(probe.stdout) const v = j.streams?.[0] const seconds = Number(j.format?.duration) if (!v) issues.push('The test clip has no video stream.') else { if (!(seconds >= 4 && seconds <= 6.5)) issues.push(`The test clip runs ${seconds.toFixed(1)} s; expected about 5 s.`) if (v.width < v.height) issues.push(`The test clip is ${v.width} x ${v.height}; it should be 16:9.`) notes.push(`Test clip ${p}: ${v.codec_name} ${v.width} x ${v.height}, ${seconds.toFixed(1)} s.`) } } } } if (opts.preview) { const p = resolve(opts.preview) if (!existsSync(p)) issues.push(`Preview not found: ${p}`) else { const d = imageSize(p) const kb = statSync(p).size / 1024 if (!d || d.type !== 'webp') issues.push(`${opts.preview} is not a WebP.`) else if (Math.max(d.width, d.height) > 2048) issues.push(`${opts.preview} is ${d.width} x ${d.height}; keep previews at most 2048 px on the long edge.`) if (kb > 400) warnings.push(`${opts.preview} is ${Math.round(kb)} KB; aim for 150-400 KB.`) notes.push(`Preview ${opts.preview}: ${d ? `${d.width} x ${d.height}, ` : ''}${Math.round(kb)} KB.`) } } console.log(`${opts.character}: ${ch.name ?? '(no name)'}, ${ch.look ?? '?'}, ${ch.people ?? '?'}.`) for (const n of notes) console.log(`note: ${n}`) for (const w of warnings) console.log(`warning: ${w}`) if (issues.length) { for (const i of issues) console.log(`FAIL: ${i}`) process.exit(1) } console.log('PASS: technical checks. Every label is exact and on calm backdrop, the eight cells hold figures, the locks are current. Now open the board and the scene tests at full size and go through references/output-spec.md by eye: the same face in every view, the outfit exactly as locked, natural hands, nothing written anywhere.')