/** * The prompts on the art board, built from the manifest and STYLE.md §1. Nobody types * a prompt by hand (STYLE.md §6): the same words describe the rose every time. */ import type { Asset, Cell, Manifest } from './manifest.js'; /** Where a cut falls: rounded once and shared by the board's overlay and `art:accept`. */ export function cutLines(size: number, parts: number): number[] { return Array.from({ length: parts + 1 }, (_, i) => Math.round((i * size) / parts)); } export interface CellBox { readonly index: number; readonly row: number; readonly col: number; readonly x0: number; readonly y0: number; readonly x1: number; readonly y1: number; readonly cx: number; readonly cy: number; /** The safe box: the drawing stays inside it (STYLE.md §9). */ readonly safe: { readonly x0: number; readonly y0: number; readonly x1: number; readonly y1: number }; } /** STYLE.md §9: the clear band inside every cell edge, as a share of the cell's shorter side. */ export const SAFE_MARGIN = 0.12; export function cellBoxes(width: number, height: number, cols: number, rows: number): CellBox[] { const xs = cutLines(width, cols); const ys = cutLines(height, rows); const boxes: CellBox[] = []; for (let row = 0; row < rows; row++) { for (let col = 0; col < cols; col++) { const x0 = xs[col] ?? 0, x1 = xs[col + 1] ?? width, y0 = ys[row] ?? 0, y1 = ys[row + 1] ?? height; const m = Math.round(SAFE_MARGIN * Math.min(x1 - x0, y1 - y0)); boxes.push({ index: boxes.length, row, col, x0, y0, x1, y1, cx: Math.round((x0 + x1) / 2), cy: Math.round((y0 + y1) / 2), safe: { x0: x0 + m, y0: y0 + m, x1: x1 - m, y1: y1 - m } }); } } return boxes; } /** The size one cell ships at: its share of the sheet. */ export function cellSize(a: Asset): { width: number; height: number } { const g = a.grid ?? { cols: 1, rows: 1 }; return { width: Math.floor(a.width / g.cols), height: Math.floor(a.height / g.rows) }; } /** A cell made on its own is made on the generator canvas closest to its shape. */ export function soloCanvas(a: Asset): { width: number; height: number } { const { width, height } = cellSize(a); if (height > width * 1.2) return { width: 1024, height: 1536 }; if (width > height * 1.2) return { width: 1536, height: 1024 }; return { width: 1024, height: 1024 }; } /** * The first line after the style: what kind of image this is, in words a generator * understands (STYLE.md §6). Generators follow the first lines best. */ const MAKE: Record, string> = { sheet: 'a character reference sheet: the same character painted several times on plain paper, so that every later picture can match it.', sprite: 'one small painted picture of a single thing, on a transparent background, to be placed into a game scene.', layer: 'a tall painted scene for a phone screen, with transparent areas exactly where the setting says, because the sky is painted separately behind it.', icon: 'an app icon: one bold, simple painted image filling a square, readable even when very small.' }; const list = (items: readonly string[]): string => items.join('; '); /** The shared avoid lines, less any this picture is allowed to break. */ const shared = (a: Asset, m: Manifest): string[] => m.avoid.filter((line) => !(a.allow ?? []).includes(line)); /** A sheet is cut apart, so its pictures must not touch. Everything else is said positively in the layout. */ const SHEET_AVOID = ['pictures touching or overlapping', 'grid lines, frames or labels']; /** The character the picture shows, if any, and its name. */ function characterOf(a: Asset, m: Manifest): { name: string; sheet: string; description: string } | null { if (a.character === undefined) return null; const c = m.characters[a.character]; return c ? { name: a.character, ...c } : null; } /** The reference pictures to attach when making `a`. */ export function attachments(a: Asset, m: Manifest): string[] { const c = characterOf(a, m); const sheet = c && c.sheet !== a.id ? [c.sheet] : []; return a.over ? [...sheet, a.over] : sheet; } /** "Reference: …", for a picture of a character made after its sheet. */ function referenceLines(a: Asset, m: Manifest): string[] { const c = characterOf(a, m); if (!c || c.sheet === a.id) return []; return [`Reference: attach the image ${c.sheet}, the ${c.name}'s character sheet, and match it exactly: the same shapes, colours, proportions and face.`]; } /** The subject, followed by the character's description when the picture shows one. */ function subjectLine(a: Asset, m: Manifest, subject: string): string { const c = characterOf(a, m); return c ? `${subject} ${c.description}`.trim() : subject; } function canvasLine(width: number, height: number, background: Asset['background'], single: boolean): string { if (!single) return `Canvas: ${width} × ${height} px, ${background === 'transparent' ? 'transparent background' : 'painted to every edge'}.`; return `Canvas: ${width} × ${height} px, transparent background. One subject, whole and centred, filling about 70 % of the canvas with clear space all round; no ground and no cast shadow.`; } const board = (id: string): string => `Board id: ${id}`; /** The prompt for one picture, or for a whole sprite sheet. */ export function promptFor(a: Asset, m: Manifest, style: string): string { if (a.type === 'spritesheet') return sheetPrompt(a, m, style); const lines = [style, '', `Make: ${MAKE[a.type]}`, ...referenceLines(a, m), `Subject: ${subjectLine(a, m, a.subject ?? '')}`]; if (a.setting) lines.push(`Setting: ${a.setting}`); if (a.composition) lines.push(`Composition: ${a.composition}`); lines.push( canvasLine(a.width, a.height, a.background, a.type === 'sprite'), `Include: ${list(a.include)}`, `Avoid: ${list([...a.avoid, ...shared(a, m)])}`, board(a.id) ); return lines.join('\n'); } /** * One layer of a layered character (STYLE.md §3b): only its part, painted over the guide in * register, so the app can stack the layers into any look the player chose. */ function layerPrompt(a: Asset, m: Manifest, style: string): string { const g = a.grid ?? { cols: 1, rows: 1 }; const cells = a.cells ?? []; const c = characterOf(a, m); return [ style, '', `Make: one layer of a layered sprite sheet: only one part of the ${c?.name ?? 'figure'}, in ${cells.length} poses, painted over a guide in exact register so the parts can be stacked into one figure.`, ...referenceLines(a, m), `Guide: attach the image ${a.over ?? ''} and paint over it. Keep its canvas and its grid. In every picture, paint only the part named below, exactly where it sits on the guide's figure, at exactly the same size, pose and position; then leave out the guide itself, so that everything except this part is fully transparent.`, `Part: ${a.subject ?? ''}`, `Drawn alike: ${a.angle ?? ''}`, `Layout: the guide's ${g.cols} × ${g.rows} cells, read left to right, top row first; nothing moved, nothing scaled.`, `Canvas: ${a.width} × ${a.height} px, transparent everywhere except the part; no ground and no cast shadows.`, 'The poses under the part, as in the guide:', ...cells.map((cell, i) => `${i + 1}. ${cell.does}`), `Include: ${list(a.include)}`, `Avoid: ${list([...a.avoid, ...SHEET_AVOID, ...shared(a, m)])}`, board(a.id) ].join('\n'); } function sheetPrompt(a: Asset, m: Manifest, style: string): string { if (a.over) return layerPrompt(a, m, style); const g = a.grid ?? { cols: 1, rows: 1 }; const cells = a.cells ?? []; const many = (n: number, word: string): string => `${n} ${word}${n === 1 ? '' : 's'}`; return [ style, '', `Make: a sprite sheet: ${cells.length} separate painted pictures on one image, which will be cut apart so that each becomes its own picture in the game.`, ...referenceLines(a, m), `Subject: ${subjectLine(a, m, '') || 'each picture is its own thing, described in the list below.'}`, `Drawn alike: ${a.angle ?? ''}`, `Layout: ${many(g.cols, 'column')} × ${many(g.rows, 'row')} of equal, invisible cells, read left to right, top row first. One picture in the middle of each cell, all at one scale, each whole and uncropped, with wide empty gaps between them and round the edge, so they can be cut apart cleanly. The same light from the left and the same brush line in every picture.`, `Canvas: ${a.width} × ${a.height} px, transparent between and round the pictures; no ground and no cast shadows.`, 'Pictures:', ...cells.map((c, i) => `${i + 1}. ${c.does}`), `Include: ${list(a.include)}`, `Avoid: ${list([...a.avoid, ...SHEET_AVOID, ...shared(a, m)])}`, board(a.id) ].join('\n'); } /** The prompt for one cell of a sprite sheet, made on its own (STYLE.md §9, "One at a time"). */ export function cellPromptFor(a: Asset, cell: Cell, m: Manifest, style: string): string { const { width, height } = soloCanvas(a); return [ style, '', `Make: ${MAKE.sprite}`, ...referenceLines(a, m), `Subject: ${subjectLine(a, m, cell.does)}`, `Drawn alike: ${a.angle ?? ''}`, canvasLine(width, height, 'transparent', true), `Include: ${list(a.include)}`, `Avoid: ${list([...a.avoid, ...shared(a, m)])}`, board(`${cell.id} (one picture of ${a.id})`) ].join('\n'); }