#!/usr/bin/env node // Checks a finished loading screen or set. It fails any caption, loading label or bar that falls outside the 3:4 // profile-grid crop or into the app interface zones (assets/safe-zones.json), any caption that does not match the // plan letter for letter, a name or tagline too small to read on a phone, low contrast, a screen or profile crop of // the wrong size, a face outside the profile circle, a caption about crime or violence, a person without recorded // consent, art not marked as checked for stray text, and any screen, crop, sheet or manifest that is out of date. // Then open the screens and go through references/output-spec.md by eye. // // Usage: // node scripts/check-screens.mjs --plan screen.json --manifest screens/manifest.json [--preview preview.webp] // // Node 18 or newer. No npm packages. Exit code 1 when a check fails. import { createHash } from 'node:crypto' import { existsSync, readFileSync, statSync } from 'node:fs' import { dirname, isAbsolute, join, resolve } from 'node:path' const FLAGS = new Set(['plan', 'manifest', 'preview']) function fail(message) { console.error(message) process.exit(1) } const opts = {} const argv = process.argv.slice(2) for (let i = 0; i < argv.length; i++) { const a = argv[i] if (!a.startsWith('--')) fail(`Unexpected argument "${a}". Flags look like --name value.`) const key = a.slice(2) if (!FLAGS.has(key)) fail(`Unknown flag --${key}. Allowed: ${[...FLAGS].map((f) => `--${f}`).join(', ')}`) const value = argv[i + 1] if (value === undefined || value.startsWith('--')) fail(`--${key} needs a value.`) opts[key] = value i++ } if (!opts.plan || !opts.manifest) fail('Usage: node scripts/check-screens.mjs --plan screen.json --manifest screens/manifest.json [--preview preview.webp]') 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') // The same list as scripts/new-screen.mjs: this format is cocky and funny, never about crime or violence. const BLOCKED = /\b(wanted|kill|killer|killing|murder|gun|guns|weapon|weapons|bomb|robbery|robber|heist|steal|stolen|cop|cops|police|drug|drugs|gang|mafia|cartel|arrest|arrested|jail|prison|blood|dead|die)\b/i const BLOCKED_ART = /\b(gun|guns|weapon|knife|bomb|police|cop|crime|robbery|heist|drugs?|blood|wanted|stolen|steal)\b/i const issues = [] const warnings = [] const notes = [] const plan = readJson(opts.plan, 'Plan') const manifest = readJson(opts.manifest, 'Manifest') const zones = JSON.parse(readFileSync(new URL('../assets/safe-zones.json', import.meta.url), 'utf8')) const planDir = dirname(resolve(opts.plan)) const outDir = dirname(resolve(opts.manifest)) const fromPlan = (p) => (isAbsolute(p) ? p : join(planDir, p)) const fromOut = (p) => (isAbsolute(p) ? p : join(outDir, p)) const style = plan.style ?? {} const subject = plan.subject ?? {} const screens = plan.screens ?? [] // The plan. if (plan.schema !== 'open-world-loading-screen/1') issues.push(`${opts.plan} schema is "${plan.schema}", expected open-world-loading-screen/1.`) if (screens.length < 1 || screens.length > 4) issues.push(`The plan has ${screens.length} screens; a plan has 1 to 4.`) const unfilled = [] const walk = (v, path) => { if (typeof v === 'string' && v.includes('FILL:')) unfilled.push(path) else if (Array.isArray(v)) v.forEach((x, i) => walk(x, `${path}[${i}]`)) else if (v && typeof v === 'object') for (const [k, x] of Object.entries(v)) walk(x, path ? `${path}.${k}` : k) } walk(plan, '') if (unfilled.length) issues.push(`Still marked FILL: ${unfilled.join(', ')}.`) if (!['pet', 'product', 'character', 'person'].includes(subject.kind)) issues.push(`subject.kind is "${subject.kind}"; it must be pet, product, character or person.`) if (subject.kind === 'person') { const c = plan.consent ?? {} if (!['own-photo', 'written-consent'].includes(c.basis) || c.adult_confirmed !== true || c.confirmed !== true) { issues.push('The hero is a person, but the plan does not record consent (consent.basis own-photo or written-consent, consent.adult_confirmed and consent.confirmed true). Do not deliver until the person shown has agreed and is an adult. Never a celebrity, a public figure or a child.') } } else if (subject.photo_has_person === true) { issues.push(`subject.photo_has_person is true but the kind is "${subject.kind}". A photo with a person in it is kind "person" with consent recorded.`) } if (subject.kind && subject.kind !== 'character' && !subject.photo) issues.push(`A ${subject.kind} needs subject.photo.`) screens.forEach((s, i) => { if (s.n !== i + 1) issues.push(`Screens are not numbered 1 to ${screens.length} in order (found ${s.n} at position ${i + 1}).`) const words = String(s.name ?? '').trim().split(/\s+/).filter(Boolean) if (!words.length) issues.push(`Screen ${s.n} has no name.`) else if (words.length > 3 || s.name.length > 20) issues.push(`Screen ${s.n} name "${s.name}" is over 3 words or 20 characters.`) if (!String(s.tagline ?? '').trim()) issues.push(`Screen ${s.n} has no tagline.`) else if (s.tagline.length > 60) issues.push(`Screen ${s.n} tagline "${s.tagline}" is over 60 characters.`) if (BLOCKED.test(`${s.name} ${s.tagline}`)) issues.push(`Screen ${s.n} caption "${s.name}: ${s.tagline}" uses a word about crime or violence. Keep it cocky and funny.`) if (BLOCKED_ART.test(`${s.pose ?? ''} ${s.scene ?? ''}`)) issues.push(`Screen ${s.n} pose or scene mentions crime or violence. Keep it cocky and funny.`) if (s.art_text_free !== true) issues.push(`Screen ${s.n} art is not marked "art_text_free": open the art at full size, confirm it has no letters, numbers, signs, logos, game interface or watermark, then set it to true in the plan.`) }) const tagSet = screens.map((s) => String(s.tagline ?? '').toLowerCase()) if (new Set(tagSet).size !== tagSet.length) warnings.push('Two screens share a tagline. A set reads better with one line of attitude each.') // The manifest against the plan. if (manifest.schema !== 'open-world-loading-screen-manifest/1') issues.push(`${opts.manifest} is not a screen manifest (make it with scripts/compose-screens.mjs).`) const records = manifest.screens ?? [] if (records.length !== screens.length) issues.push(`The manifest has ${records.length} screens; the plan has ${screens.length}. Re-run compose-screens.mjs.`) const set = manifest.settings ?? {} for (const key of ['panel', 'ink', 'accent']) { const want = String(style[key] ?? '').toLowerCase() if (want && set[key] !== want) issues.push(`The screens were drawn with ${key} "${set[key]}", but the plan now says "${want}". Re-run compose-screens.mjs.`) } for (const key of ['case', 'side']) if (style[key] && set[key] !== style[key]) issues.push(`The screens were drawn with ${key} "${set[key]}", but the plan now says "${style[key]}". Re-run compose-screens.mjs.`) const wantLabel = String(plan.loading?.label ?? 'LOADING').trim().toUpperCase() const wantPercent = Number(plan.loading?.percent ?? 64) if (manifest.zones_checked !== zones.checked) warnings.push(`The screens were drawn against safe zones checked ${manifest.zones_checked}; the zone file now says ${zones.checked}. Re-run compose-screens.mjs.`) const inside = (b, r) => b.x >= r.x && b.y >= r.y && b.x + b.width <= r.x + r.width && b.y + b.height <= r.y + r.height const overlaps = (b, r) => b.x < r.x + r.width && b.x + b.width > r.x && b.y < r.y + r.height && b.y + b.height > r.y const expectedName = (s) => (set.case === 'upper' ? s.name.trim().toUpperCase() : s.name.trim()) const nameSizes = [] const tagSizes = [] const soft = {} for (const s of screens) { const r = records.find((x) => x.n === s.n) const where = `Screen ${s.n}` if (!r) { issues.push(`${where} is missing from the manifest. Re-run compose-screens.mjs.`) continue } // The files. const file = fromOut(r.file) if (!existsSync(file)) issues.push(`${where} file not found: ${file}`) else { const dim = imageSize(file) if (!dim || dim.type !== 'png') issues.push(`${where} ${r.file} is not a PNG.`) else if (dim.width !== zones.frame.width || dim.height !== zones.frame.height) issues.push(`${where} is ${dim.width} x ${dim.height}; a loading screen is ${zones.frame.width} x ${zones.frame.height}.`) if (sha(file) !== r.sha256) issues.push(`${where} ${r.file} has changed since it was composed (edited by hand?). Re-run compose-screens.mjs, then check again.`) } const profile = r.profile ?? {} const pfile = fromOut(profile.file ?? '') if (!profile.file || !existsSync(pfile)) issues.push(`${where} profile crop not found. Re-run compose-screens.mjs.`) else { const dim = imageSize(pfile) if (!dim || dim.type !== 'png') issues.push(`${where} profile crop ${profile.file} is not a PNG.`) else if (dim.width !== zones.profile.size || dim.height !== zones.profile.size) issues.push(`${where} profile crop is ${dim.width} x ${dim.height}; it must be ${zones.profile.size} x ${zones.profile.size} (1:1).`) if (sha(pfile) !== profile.sha256) issues.push(`${where} profile crop has changed since it was composed. Re-run compose-screens.mjs.`) if (!(profile.face_offset <= zones.profile.circle_ratio)) issues.push(`${where} the hero's face is ${Math.round((profile.face_offset ?? 1) * 100)} percent of the side from the middle of the profile crop; apps show a circle, so keep it within ${zones.profile.circle_ratio * 100} percent. Move crop.x and crop.y onto the face and recompose.`) if (profile.zoom > 1.5) warnings.push(`${where} profile crop zoom is ${profile.zoom}; the art is upscaled that much, so it may look soft.`) const c = s.crop ?? {} if (c.zoom !== profile.zoom) issues.push(`${where} crop zoom in the plan (${c.zoom}) is not the one drawn (${profile.zoom}). Re-run compose-screens.mjs.`) } // The art it was drawn on is the art the plan names now. if (!s.art) issues.push(`${where} has no "art" in the plan.`) else if (!existsSync(fromPlan(s.art))) issues.push(`${where} art not found: ${fromPlan(s.art)}`) else { if (sha(fromPlan(s.art)) !== r.art_sha256) issues.push(`${where} was composed on other art than the plan names now. Re-run compose-screens.mjs.`) const a = imageSize(fromPlan(s.art)) if (a && (a.width < zones.frame.width || a.height < zones.frame.height)) warnings.push(`${where} art is ${a.width} x ${a.height}, smaller than the screen, so it was upscaled (a draft used as final?).`) if (a && Math.abs(a.width / a.height - 9 / 16) > 0.02) warnings.push(`${where} art is ${a.width} x ${a.height}, not 9:16, so its edges were cropped.`) } // Exact words. if (r.name !== s.name) issues.push(`${where} name on the screen is "${r.name}", but the plan says "${s.name}". Re-run compose-screens.mjs.`) if (r.name_drawn !== expectedName(s)) issues.push(`${where} drew the name "${r.name_drawn}", expected "${expectedName(s)}".`) if ((r.name_lines ?? []).join(' ') !== r.name_drawn) issues.push(`${where} name lines "${(r.name_lines ?? []).join(' / ')}" do not add up to "${r.name_drawn}".`) if ((r.name_lines ?? []).length > 2) issues.push(`${where} name runs to ${(r.name_lines ?? []).length} lines; at most 2.`) if (r.tagline_drawn !== s.tagline.trim()) issues.push(`${where} drew the tagline "${r.tagline_drawn}", but the plan says "${s.tagline.trim()}". Re-run compose-screens.mjs.`) if ((r.tagline_lines ?? []).join(' ') !== r.tagline_drawn) issues.push(`${where} tagline lines "${(r.tagline_lines ?? []).join(' / ')}" do not add up to "${r.tagline_drawn}".`) if ((r.tagline_lines ?? []).length > 3) issues.push(`${where} tagline runs to ${(r.tagline_lines ?? []).length} lines; at most 3.`) if (r.label_drawn !== wantLabel) issues.push(`${where} loading label is "${r.label_drawn}", but the plan says "${wantLabel}". Re-run compose-screens.mjs.`) if (r.percent_drawn !== `${wantPercent}%`) issues.push(`${where} loading percent is "${r.percent_drawn}", but the plan says "${wantPercent}%". Re-run compose-screens.mjs.`) if (r.bar_fill_percent !== wantPercent) issues.push(`${where} the bar is filled to ${r.bar_fill_percent} percent, but the plan says ${wantPercent}. Re-run compose-screens.mjs.`) // Safe zones: every box, the panel and the bar included. const boxes = r.boxes ?? [] for (const role of ['panel', 'name', 'tagline', 'strip', 'label', 'percent', 'bar']) if (!boxes.some((b) => b.role === role)) issues.push(`${where} has no ${role} box in the manifest. Re-run compose-screens.mjs.`) for (const b of boxes) { const what = b.line ? `${b.role} line ${b.line}` : b.role for (const z of zones.zones) { const bad = z.kind === 'keep-inside' ? !inside(b, z.rect) : overlaps(b, z.rect) if (!bad) continue const message = `${where} ${what} (x ${b.x}-${b.x + b.width}, y ${b.y}-${b.y + b.height}) ${z.kind === 'keep-inside' ? 'falls outside' : 'enters'} ${z.label}.` if (z.severity === 'fail') issues.push(message) else (soft[z.id] ??= { label: z.label, screens: new Set() }).screens.add(s.n) } if (!inside(b, zones.title_box) && !issues.some((m) => m.startsWith(`${where} ${what} `))) issues.push(`${where} ${what} falls outside the safe box.`) } // Readable on a phone. if (!(r.name_px >= zones.min_name_px)) issues.push(`${where} name is ${r.name_px} px; at least ${zones.min_name_px} px reads on a phone grid tile. Shorten the name.`) if (!(r.tagline_px >= zones.min_tagline_px)) issues.push(`${where} tagline is ${r.tagline_px} px; at least ${zones.min_tagline_px} px reads on a phone. Shorten the tagline.`) if (!(r.label_px >= zones.min_label_px)) issues.push(`${where} loading label is ${r.label_px} px; at least ${zones.min_label_px} px.`) nameSizes.push(r.name_px) tagSizes.push(r.tagline_px) const cr = r.contrast ?? {} if (!(cr.text_on_panel >= zones.min_contrast)) issues.push(`${where} caption contrast is ${cr.text_on_panel}:1, under ${zones.min_contrast}:1. Pick a darker ink or a lighter panel colour in the plan and recompose.`) if (!(cr.label_on_strip >= zones.min_contrast)) issues.push(`${where} loading label contrast is ${cr.label_on_strip}:1, under ${zones.min_contrast}:1. Recompose with a lighter panel colour or a darker ink.`) if (!(cr.bar_on_strip >= 3)) issues.push(`${where} the bar fill against its strip is ${cr.bar_on_strip}:1, under 3:1. Pick a brighter accent colour in the plan and recompose.`) } for (const z of Object.values(soft)) warnings.push(`Caption on screen(s) ${[...z.screens].join(', ')} falls outside ${z.label}.`) if (nameSizes.length && set.shared_size && new Set(nameSizes).size > 1) issues.push(`The set was meant to share one name size, but the screens use ${[...new Set(nameSizes)].join(', ')} px. Re-run compose-screens.mjs.`) if (tagSizes.length && new Set(tagSizes).size > 1) warnings.push(`Tagline sizes differ across the set (${[...new Set(tagSizes)].join(', ')} px).`) // The contact sheet of a set. if (screens.length > 1) { if (!manifest.sheet) issues.push('A set has a contact sheet. Re-run compose-screens.mjs.') else { const f = fromOut(manifest.sheet.file) if (!existsSync(f)) issues.push(`Sheet not found: ${f}`) else { if (sha(f) !== manifest.sheet.sha256) issues.push('The sheet has changed since it was composed. Re-run compose-screens.mjs.') const current = new Map(records.map((r) => [r.n, r.sha256])) if ((manifest.sheet.screens ?? []).length !== records.length || (manifest.sheet.screens ?? []).some((x) => current.get(x.n) !== x.sha256)) issues.push('The sheet was made from other screens than the manifest lists now. Re-run compose-screens.mjs.') notes.push(`Sheet ${manifest.sheet.file}: the set side by side.`) } } } if (opts.preview) { if (!existsSync(opts.preview)) issues.push(`Preview not found: ${opts.preview}`) else { const dim = imageSize(opts.preview) const kb = statSync(opts.preview).size / 1024 if (!dim || dim.type !== 'webp') issues.push(`${opts.preview} is not a WebP.`) else if (Math.max(dim.width, dim.height) > 2048) issues.push(`${opts.preview} is ${dim.width} x ${dim.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 (a smaller size).`) notes.push(`Preview ${opts.preview}: ${dim ? `${dim.width} x ${dim.height}, ` : ''}${Math.round(kb)} KB.`) } } console.log(`${opts.plan}: ${screens.length} screen${screens.length === 1 ? '' : 's'}, ${subject.kind ?? '?'} hero, caption panel on the ${set.side ?? '?'}, name ${nameSizes.length ? `${Math.min(...nameSizes)} px` : 'no size'}.`) 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. The caption, the loading label and the bar sit inside the 3:4 grid crop and clear of the app interface, every word matches the plan, and the profile crop is 1:1. Now open every screen, its profile crop and the guides at full size and go through references/output-spec.md by eye: the hero is recognisable, no stray text in the art, no extra people, nothing violent, nothing that looks like another game.')