#!/usr/bin/env node // Writes screen.json, the plan for one loading screen (or a set of up to 4): the hero (a pet, a product, an // invented character or a person who has agreed), one art direction, the caption style, the loading bar and one // entry per screen with its exact name and tagline. Each screen's pose and scene are left as FILL: for you to write. // It calls no API. // // Usage: // node scripts/new-screen.mjs --out screen.json --kind pet|product|character|person // --description "a small scruffy terrier mix called Patch" // --keep "a wiry cream coat, a black patch over one eye, one ear up and one folded, a red collar" // [--photo patch.jpg] --names "Patch" --taglines "Mayor of the dog park. Self-appointed." // (--preset sunset-street|midday-boardwalk|dusk-neon | --look "one sentence" [--world "the street around"]) // [--side left|right] [--panel #hex --ink #hex --accent #hex] [--case upper|as-written] // [--label LOADING] [--percent 64] [--font "Helvetica Neue"] [--font-file brand.ttf] // [--consent own-photo|written-consent --adult-confirmed] [--force] // // --names and --taglines: 1 to 4 entries each, separated by | (one screen, or a set of up to 4 that share a hero). // --photo: the hero's photo (required for pet, product and person; optional for character). // --consent and --adult-confirmed: only for kind person. Use them only after the person shown has said yes in // plain words (or the photo is of the user themselves) and is an adult. Never a celebrity or a public figure. // Node 18 or newer. No npm packages. import { existsSync, readFileSync, writeFileSync } from 'node:fs' import { dirname, isAbsolute, relative, resolve } from 'node:path' const FLAGS = new Set([ 'out', 'kind', 'description', 'keep', 'photo', 'names', 'taglines', 'preset', 'look', 'world', 'side', 'panel', 'ink', 'accent', 'case', 'label', 'percent', 'font', 'font-file', 'consent', 'adult-confirmed', 'force', ]) const SWITCHES = new Set(['force', 'adult-confirmed']) 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(', ')}`) if (SWITCHES.has(key)) { opts[key] = true; continue } const value = argv[i + 1] if (value === undefined || value.startsWith('--')) fail(`--${key} needs a value.`) opts[key] = value i++ } const usage = 'Usage: node scripts/new-screen.mjs --out screen.json --kind pet|product|character|person --description "..." --keep "..." [--photo hero.jpg] --names "Name" --taglines "One line." (--preset sunset-street | --look "...")' if (!opts.out || !opts.kind || !opts.description || !opts.keep || !opts.names || !opts.taglines) fail(usage) if (existsSync(opts.out) && !opts.force) fail(`${opts.out} already exists. Pick another --out, or pass --force to replace it.`) const gen = JSON.parse(readFileSync(new URL('../assets/generation-input.json', import.meta.url), 'utf8')) const preset = opts.preset ? gen.presets[opts.preset] : undefined if (opts.preset && !preset) fail(`--preset must be one of: ${Object.keys(gen.presets).join(', ')}`) if (!preset && !opts.look) fail(`Give --preset or --look, so the screen has one art direction.\n${usage}`) if (!['pet', 'product', 'character', 'person'].includes(opts.kind)) fail('--kind must be pet, product, character or person.') if (opts.photo === undefined && opts.kind !== 'character') fail(`A ${opts.kind} needs --photo (the reference the art keeps recognisable).`) // The words that stay out of captions: this format is cocky and funny, never about crime or violence. // check-screens.mjs applies the same list. 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 names = opts.names.split('|').map((t) => t.trim().replace(/\s+/g, ' ')) const taglines = opts.taglines.split('|').map((t) => t.trim().replace(/\s+/g, ' ')) if (names.length < 1 || names.length > 4) fail(`--names has ${names.length} entries. Give 1 to 4 (one screen, or a set of up to 4).`) if (taglines.length !== names.length) fail(`--taglines has ${taglines.length} entries but --names has ${names.length}. Give one tagline per name.`) names.forEach((t, i) => { const words = t.split(' ').filter(Boolean) if (!t) fail(`Name ${i + 1} is empty.`) if (words.length > 3 || t.length > 20) fail(`Name ${i + 1} "${t}" is over 3 words or 20 characters. A short name reads on a phone.`) if (/[<>]/.test(t) || /[<>]/.test(taglines[i])) fail('Captions cannot contain < or >.') if (BLOCKED.test(t)) fail(`Name ${i + 1} "${t}" uses a word about crime or violence. Keep it cocky and funny.`) }) taglines.forEach((t, i) => { if (!t) fail(`Tagline ${i + 1} is empty.`) if (t.length > 60) fail(`Tagline ${i + 1} "${t}" is ${t.length} characters. Keep it to 60 or fewer: one line of attitude.`) if (BLOCKED.test(t)) fail(`Tagline ${i + 1} "${t}" uses a word about crime or violence. Keep it cocky and funny (a hot dog stand, a convertible, a skateboard), not criminal.`) }) const sameTagline = taglines.find((t, i) => taglines.findIndex((x) => x.toLowerCase() === t.toLowerCase()) !== i) if (sameTagline) fail(`Two screens share the tagline "${sameTagline}". Each screen needs its own.`) const pick = (name, value, allowed, fallback) => { const v = value ?? fallback if (!allowed.includes(v)) fail(`--${name} must be ${allowed.join(', ')}, not "${v}".`) return v } const hex = (name, value, fallback) => { const v = value ?? fallback if (!/^#[0-9a-fA-F]{6}$/.test(v)) fail(`--${name} must be a #hex colour like #141414.`) return v.toLowerCase() } const outDir = dirname(resolve(opts.out)) let photo = '' if (opts.photo) { const abs = isAbsolute(opts.photo) ? opts.photo : resolve(opts.photo) if (!existsSync(abs)) fail(`Photo not found: ${abs}`) if (!/\.(jpe?g|png|webp)$/i.test(abs)) fail('The photo must be a .jpg, .png or .webp image.') photo = relative(outDir, abs) } if (opts.kind === 'person') { const consent = opts.consent if (!['own-photo', 'written-consent'].includes(consent)) fail('A person needs --consent own-photo (a photo of the user themselves) or --consent written-consent (the person agreed in plain words), and --adult-confirmed. Stop here if you do not have that: never use a photo of someone who has not agreed, a celebrity, a public figure or a child.') if (!opts['adult-confirmed']) fail('A person must be an adult. Pass --adult-confirmed only when you know they are.') } else if (opts.consent || opts['adult-confirmed']) { fail('--consent and --adult-confirmed are only for --kind person.') } const style = preset?.style ?? {} const side = pick('side', opts.side, ['left', 'right'], 'left') const percent = Number(opts.percent ?? 64) if (!Number.isInteger(percent) || percent < 1 || percent > 99) fail('--percent must be a whole number from 1 to 99 (a loading bar that is part way).') const label = (opts.label ?? 'LOADING').trim().toUpperCase() if (!/^[A-Z0-9 ]{3,14}$/.test(label)) fail('--label must be 3 to 14 letters, digits or spaces, such as LOADING.') const plan = { schema: 'open-world-loading-screen/1', subject: { kind: opts.kind, description: opts.description.trim(), keep: opts.keep.trim(), photo, photo_has_person: opts.kind === 'person', }, consent: { basis: opts.kind === 'person' ? opts.consent : '', adult_confirmed: opts.kind === 'person', confirmed: opts.kind === 'person', }, preset: opts.preset ?? '', look: opts.look ?? preset.look, world: opts.world ?? preset?.world ?? 'a busy sunny city street with palm trees, low-rise buildings, bright awnings and parked cars', style: { font: opts.font ?? 'Helvetica Neue', font_file: opts['font-file'] ? relative(outDir, resolve(opts['font-file'])) : '', panel: hex('panel', opts.panel, style.panel ?? '#ffd23f'), ink: hex('ink', opts.ink, style.ink ?? '#1a0f1f'), accent: hex('accent', opts.accent, style.accent ?? '#ff3d7f'), case: pick('case', opts.case, ['upper', 'as-written'], 'upper'), side, }, loading: { label, percent }, references: { anchor: '' }, screens: names.map((name, i) => ({ n: i + 1, name, tagline: taglines[i], pose: 'FILL: the hero\'s cocky three-quarter pose, in one sentence (sunglasses, a chin up, arms crossed, a smug half-smile)', scene: 'FILL: where it stands, in one sentence (a hot dog stand, a convertible at the kerb, a skateboard), nothing violent or criminal', draft: '', art: '', art_text_free: false, crop: { x: side === 'left' ? 0.62 : 0.38, y: 0.3, zoom: 1.4 }, })), } writeFileSync(opts.out, `${JSON.stringify(plan, null, 2)}\n`) console.log(`Wrote ${opts.out}: ${names.length} screen${names.length === 1 ? '' : 's'} for ${opts.kind} "${opts.description.trim()}", look ${opts.preset ? `preset ${opts.preset}` : 'your own'}, caption panel on the ${side}.`) console.log('Next: write each screen\'s "pose" and "scene" (references/prompt-patterns.md). After you have looked at the final art, set its "art_text_free" and move its "crop" to the hero\'s face.') if (opts.kind === 'person') console.log('Kind person: consent is recorded as given. If that is not true, delete this file and stop.')