// Shared by the Character sheet scripts: the fields a character has, the rules they must pass, and the "lock text" // that later shots paste into their prompts. No API calls, no npm packages (Node 18 or newer). export const LOOK_IDS = ['photoreal', 'stylised-3d', 'clay'] export const PEOPLE = ['fictional', 'real-with-consent'] export const LIMITS = { name: 40, who: 90, age: 60, face: 260, hair: 160, build: 140, wardrobe: 260, wardrobe_alt: 260, props: 160, never_items: 6, never_each: 80, lock_text: 850, lock_text_short: 260, scene: 320, } // A look is a medium. It is never a named studio, film, franchise or living artist. const NAMED_LOOKS = /\b(pixar|disney|ghibli|dreamworks|illumination|aardman|laika|marvel|sony pictures|studio [a-z]+ style|tim burton|wes anderson|miyazaki|in the style of|in the manner of|style of)\b/i // Likeness of a real or famous person: refused in every text field. const REAL_PERSON = /\b(celebrity|famous|lookalike|look-alike|based on a real|real person|politician|prime minister|public figure)\b/i // Minors: refused. The age field must also say an adult age. const MINOR = /\b(child|children|kid|kids|boy|girl|teen|teenager|teenage|toddler|baby|infant|minor|schoolboy|schoolgirl|preteen|under\s*1[0-9]|1[0-7]\s*(?:years|yr|y\/o|-year))\b/i const ADULT_AGE = /\b([2-8]\d(?:s|-year-old)?|twenties|thirties|forties|fifties|sixties|seventies|eighties|mid|late|early|adult)\b/i export const strip = (text) => String(text ?? '').trim().replace(/\s+/g, ' ').replace(/[.;,\s]+$/, '') const has = (t) => typeof t === 'string' && t.trim() && !t.includes('FILL:') /** The paste-in block. Same words every time: later shots never paraphrase it. */ export function buildLockText(ch) { const never = (ch.never ?? []).map(strip).filter(Boolean) const parts = [`${strip(ch.name)}, ${strip(ch.age)}, ${strip(ch.who)}.`, `Face: ${strip(ch.face)}.`, `Hair: ${strip(ch.hair)}.`, `Build: ${strip(ch.build)}.`, `Wardrobe: ${strip(ch.wardrobe)}.`] if (has(ch.props)) parts.push(`Props: ${strip(ch.props)}.`) if (never.length) parts.push(`Never changes: ${never.join('; ')}.`) const long = parts.join(' ') // The short lock is the author's own line when there is one (the `short` field); otherwise the first clause of each lock. const first = (t) => strip(String(t ?? '').split(/[.;,]/)[0]) const short = has(ch.short) ? strip(ch.short) + '.' : [`${strip(ch.name)}, ${strip(ch.age)}`, first(ch.hair), first(ch.wardrobe), never[0] ? `always ${never[0]}` : ''].filter(Boolean).join('; ') + '.' return { lock_text: long, lock_text_short: short } } /** Every rule a character.json must pass. Returns { issues, warnings }. */ export function checkCharacter(ch) { const issues = [] const warnings = [] if (ch.schema !== 'character-sheet/1') issues.push(`character.json schema is "${ch.schema}", expected character-sheet/1 (make it with scripts/new-character.mjs).`) 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(ch, '') if (unfilled.length) issues.push(`Still marked FILL: ${unfilled.join(', ')}.`) for (const key of ['name', 'who', 'age', 'face', 'hair', 'build', 'wardrobe']) { if (!has(ch[key])) issues.push(`"${key}" is empty. Write it in character.json.`) else if (ch[key].length > LIMITS[key]) issues.push(`"${key}" is ${ch[key].length} characters; the most is ${LIMITS[key]}. Keep only what must not change.`) } for (const key of ['wardrobe_alt', 'props']) if (has(ch[key]) && ch[key].length > LIMITS[key]) issues.push(`"${key}" is ${ch[key].length} characters; the most is ${LIMITS[key]}.`) if (!LOOK_IDS.includes(ch.look)) issues.push(`"look" is "${ch.look}"; use ${LOOK_IDS.join(', ')}. A look is a medium, never a studio or an artist.`) const never = Array.isArray(ch.never) ? ch.never : [] if (!never.length) issues.push('"never" is empty. Lock at least one thing that must not change (a scar, a ring, the hair parting, a watch).') if (never.length > LIMITS.never_items) issues.push(`"never" has ${never.length} items; keep it to ${LIMITS.never_items} or fewer, or none of them is really locked.`) for (const item of never) if (typeof item !== 'string' || !item.trim() || item.length > LIMITS.never_each) issues.push(`A "never" item is empty or over ${LIMITS.never_each} characters.`) // People rules. if (!PEOPLE.includes(ch.people)) issues.push(`"people" is "${ch.people}"; use fictional (an invented adult) or real-with-consent.`) if (ch.people === 'real-with-consent') { if (!has(ch.photo)) issues.push('people is real-with-consent but there is no "photo". A real person is only made from their own photo, with consent.') if (!has(ch.consent_quote) || ch.consent_quote.trim().length < 3) issues.push('people is real-with-consent but "consent_quote" is empty. Ask the user whether the photo is of them or whether they hold the person\'s written consent, and record their answer word for word.') if (ch.adult_confirmed !== true) issues.push('people is real-with-consent but "adult_confirmed" is not true. Ask the user to confirm the person is an adult.') } else if (has(ch.photo)) { issues.push('A photo is set but people is "fictional". A character made from a photo is real-with-consent.') } const all = [...['name', 'who', 'age', 'face', 'hair', 'build', 'wardrobe', 'wardrobe_alt', 'props'].map((k) => ch[k]), ...never].filter((v) => typeof v === 'string').join(' | ') if (NAMED_LOOKS.test(all)) issues.push('A field names a studio, film or artist. A look is a medium ("stylised 3D animation", "clay"), never a named style.') if (REAL_PERSON.test(all)) issues.push('A field mentions a real, famous or lookalike person. Characters are invented adults, or the user\'s own photo with consent; never a celebrity or public figure.') if (MINOR.test(all)) issues.push('A field describes a child or teenager. Characters are adults only.') if (has(ch.age) && !ADULT_AGE.test(ch.age)) issues.push(`"age" ("${ch.age}") does not state an adult age. Say, for example, "a woman in her mid-30s".`) // The lock text must be the one built from the fields now. if (!has(ch.lock_text) || !has(ch.lock_text_short)) issues.push('lock_text is missing. Run scripts/lock-text.mjs.') else if (!issues.length) { const fresh = buildLockText(ch) if (ch.lock_text !== fresh.lock_text || ch.lock_text_short !== fresh.lock_text_short) issues.push('lock_text is out of date with the fields. Run scripts/lock-text.mjs. If a lock changed in a way the sheet shows (the face, the hair, the outfit), the sheet no longer matches it: make a new one.') if (fresh.lock_text.length > LIMITS.lock_text) issues.push(`lock_text is ${fresh.lock_text.length} characters; the most is ${LIMITS.lock_text}. Shorten a field.`) if (fresh.lock_text_short.length > LIMITS.lock_text_short) issues.push(`lock_text_short is ${fresh.lock_text_short.length} characters; the most is ${LIMITS.lock_text_short}. Write a shorter "short" line (new-character.mjs --short).`) } const scenes = Array.isArray(ch.scenes) ? ch.scenes : [] if (scenes.length !== 3) issues.push(`The character has ${scenes.length} scene tests; a sheet is proved with exactly 3.`) for (const s of scenes) if (!has(s.prompt) || s.prompt.length > LIMITS.scene) issues.push(`Scene ${s.n} needs a prompt of at most ${LIMITS.scene} characters.`) if (ch.look === 'photoreal' && has(ch.photo) === false && ch.people === 'real-with-consent') warnings.push('A real-with-consent character with no photo.') return { issues, warnings } } export function fail(message) { console.error(message) process.exit(1) } /** A tiny --flag value parser shared by the scripts. */ export function parseArgs(argv, flags, switches = []) { const opts = {} 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.includes(key)) fail(`Unknown flag --${key}. Allowed: ${flags.map((f) => `--${f}`).join(', ')}`) if (switches.includes(key)) { opts[key] = true continue } const value = argv[i + 1] if (value === undefined || value.startsWith('--')) fail(`--${key} needs a value.`) opts[key] = value i++ } return opts }