#!/usr/bin/env node // Puts a character into a film plan so every shot is held to it. It never calls an API and never edits the file you // give it: it writes a new one and prints what changed. // // meleon-film/1 (the shared plan the film assembly reads): adds the character under plan.characters (the server // stores `plan` and never reads it, so this is for the Skills and for people). Shots are not touched. // cinematic-brand-film/1: sets locks.cast and locks.wardrobe from the character, references.cast_bible to the // text-free sheet, and copies the consent quote when the character is made from a photo. // destination-teaser/1: sets locks.people from the character's short lock. // // Usage: // node scripts/handoff.mjs --character character.json --film film.json --out film.with-character.json // // Node 18 or newer. No npm packages. import { existsSync, readFileSync, writeFileSync } from 'node:fs' import { dirname, isAbsolute, join, relative, resolve } from 'node:path' import { checkCharacter, fail, parseArgs, strip } from './character-lib.mjs' const opts = parseArgs(process.argv.slice(2), ['character', 'film', 'out']) if (!opts.character || !opts.film || !opts.out) fail('Usage: node scripts/handoff.mjs --character character.json --film film.json --out film.with-character.json') if (resolve(opts.out) === resolve(opts.film)) fail('--out must be a new file: this script does not overwrite your film plan.') for (const p of [opts.character, opts.film]) if (!existsSync(p)) fail(`Not found: ${p}`) const ch = JSON.parse(readFileSync(opts.character, 'utf8')) const film = JSON.parse(readFileSync(opts.film, 'utf8')) const { issues } = checkCharacter(ch) if (issues.length) { for (const i of issues) console.error(`problem: ${i}`) fail('The character does not pass its own checks. Run scripts/check-sheet.mjs and fix it before it goes into a film.') } if (!ch.reference) fail('The character has no sheet yet (character.reference is empty). Make and approve the sheet first.') const charDir = dirname(resolve(opts.character)) const outDir = dirname(resolve(opts.out)) const sheetRel = relative(outDir, isAbsolute(ch.reference) ? ch.reference : join(charDir, ch.reference)) const changes = [] const set = (obj, key, value, label) => { const was = obj[key] obj[key] = value changes.push(`${label}: ${was ? 'was set, now' : 'set to'} "${String(value).slice(0, 90)}${String(value).length > 90 ? '...' : ''}"`) } const faceRoute = ch.look === 'clay' ? 'Kling 3 Turbo Pro or Veo 3.1 for any shot with a visible face; Seedance refused a stylised 3D face in testing and a clay face is untested (try one 480p draft)' : 'Kling 3 Turbo Pro or Veo 3.1 for any shot with a visible face; Seedance refuses a clearly visible face (photoreal and stylised 3D were both refused in testing)' if (film.schema === 'meleon-film/1') { film.plan ??= {} const entry = { name: ch.name, look: ch.look, lock_text: ch.lock_text, lock_text_short: ch.lock_text_short, never: ch.never, reference: sheetRel, face_route: faceRoute, people: ch.people } const list = Array.isArray(film.plan.characters) ? film.plan.characters : [] const at = list.findIndex((c) => c.name === ch.name) if (at >= 0) list[at] = entry else list.push(entry) film.plan.characters = list changes.push(`plan.characters: ${at >= 0 ? 'replaced' : 'added'} ${ch.name} (${list.length} character${list.length === 1 ? '' : 's'} in the plan)`) } else if (typeof film.schema === 'string' && film.schema.startsWith('cinematic-brand-film/')) { film.locks ??= {} film.references ??= {} film.brief ??= {} set(film.locks, 'cast', [ch.age, ch.face, ch.hair, ch.build].map(strip).join('; '), 'locks.cast') set(film.locks, 'wardrobe', [strip(ch.wardrobe), ch.props ? strip(ch.props) : '', ...ch.never.map((n) => `never changes: ${strip(n)}`)].filter(Boolean).join('; '), 'locks.wardrobe') set(film.references, 'cast_bible', sheetRel, 'references.cast_bible') film.brief.character_sheet = ch.name if (ch.people === 'real-with-consent') { film.brief.person = 'own-photo' film.brief.consent_quote = ch.consent_quote film.brief.consent_recorded = ch.consent_recorded changes.push('brief.person: own-photo, with the consent quote and its date copied from character.json') } else { film.brief.person = film.brief.person === 'none' || !film.brief.person ? 'synthetic' : film.brief.person } } else if (film.schema === 'destination-teaser/1') { film.locks ??= {} set(film.locks, 'people', ch.lock_text_short, 'locks.people') } else { fail(`Unknown film plan schema "${film.schema}". This script knows meleon-film/1, cinematic-brand-film/1 and destination-teaser/1.`) } writeFileSync(opts.out, `${JSON.stringify(film, null, 2)}\n`) console.log(`${opts.out}: ${ch.name} is in the plan.`) for (const c of changes) console.log(` ${c}`) console.log(`\nReference to attach to every shot with ${ch.name}: ${sheetRel}`) console.log(`Faces on screen: ${faceRoute}.`) console.log('The sheet narrows drift but does not remove it: check every keyframe against the sheet before paying for video.')