[art-prep] ArtBoard: Build prompts, stand-ins and the art board from the manifest, and accept pictures into art/final
tools/art-prep reads art/STYLE.md (draft) and art/manifest.json (25 Phase 1 pictures), refuses forbidden words in any prompt, writes 29 stand-ins and the board files, and cuts and encodes accepted pictures as WebP within budget.
This commit is contained in:
@@ -0,0 +1,166 @@
|
||||
/**
|
||||
* The last step of the pipeline (docs/ART.md §3, step 6): a picture Mark accepted on the
|
||||
* board becomes optimised WebP in art/final/. A sprite sheet is cut along its grid here.
|
||||
* It refuses rather than guesses: a sheet with an empty cell or a painted background is
|
||||
* refused whole, because a cut that "mostly worked" ships a broken picture.
|
||||
*/
|
||||
import sharp from 'sharp';
|
||||
import type { Asset, Manifest } from './manifest.js';
|
||||
import { cellSize, cutLines } from './prompt.js';
|
||||
|
||||
/** Bytes per final file (docs/ART.md §4). The app precaches every one. */
|
||||
export const BUDGET: Record<Asset['type'] | 'cell', number> = {
|
||||
sheet: 400_000,
|
||||
spritesheet: 0, // never written whole: its cells are
|
||||
layer: 350_000,
|
||||
icon: 120_000,
|
||||
sprite: 120_000,
|
||||
cell: 120_000
|
||||
};
|
||||
|
||||
const QUALITIES = [82, 72, 62];
|
||||
const ALPHA = 16;
|
||||
|
||||
export interface FinalFile {
|
||||
readonly id: string;
|
||||
readonly data: Buffer;
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
}
|
||||
|
||||
export interface Accepted {
|
||||
readonly files: readonly FinalFile[];
|
||||
/** Things Mark or Claude should know, none of them a reason to refuse. */
|
||||
readonly notes: readonly string[];
|
||||
}
|
||||
|
||||
export class Refused extends Error {
|
||||
override readonly name = 'Refused';
|
||||
}
|
||||
|
||||
interface Target {
|
||||
readonly asset: Asset;
|
||||
/** Set when `id` names one cell of a sprite sheet, made on its own. */
|
||||
readonly cell?: string;
|
||||
}
|
||||
|
||||
export function findTarget(m: Manifest, id: string): Target {
|
||||
for (const asset of m.assets) {
|
||||
if (asset.id === id) return { asset };
|
||||
if (asset.cells?.some((c) => c.id === id)) return { asset, cell: id };
|
||||
}
|
||||
throw new Refused(`"${id}" is not a picture in art/manifest.json`);
|
||||
}
|
||||
|
||||
async function encode(img: sharp.Sharp, budget: number, id: string): Promise<{ data: Buffer; width: number; height: number }> {
|
||||
for (const quality of QUALITIES) {
|
||||
const { data, info } = await img.clone().webp({ quality, alphaQuality: 90, effort: 5 }).toBuffer({ resolveWithObject: true });
|
||||
if (data.length <= budget) return { data, width: info.width, height: info.height };
|
||||
}
|
||||
throw new Refused(`${id}: over its budget of ${Math.round(budget / 1000)} KB even at WebP quality ${QUALITIES.at(-1)}. Ask for a simpler picture, or raise the budget in docs/ART.md §4 with a reason.`);
|
||||
}
|
||||
|
||||
interface Coverage {
|
||||
readonly drawn: number;
|
||||
readonly seeThrough: number;
|
||||
readonly touches: boolean;
|
||||
}
|
||||
|
||||
/** How much of a region is drawn, and whether the drawing reaches its edge (two pixels or more). */
|
||||
function coverage(px: Buffer, width: number, x0: number, y0: number, x1: number, y1: number): Coverage {
|
||||
let drawn = 0, edge = 0;
|
||||
for (let y = y0; y < y1; y++) {
|
||||
for (let x = x0; x < x1; x++) {
|
||||
if ((px[(y * width + x) * 4 + 3] ?? 0) >= ALPHA) {
|
||||
drawn++;
|
||||
if (x === x0 || x === x1 - 1 || y === y0 || y === y1 - 1) edge++;
|
||||
}
|
||||
}
|
||||
}
|
||||
const area = (x1 - x0) * (y1 - y0);
|
||||
return { drawn: drawn / area, seeThrough: Math.round(100 * (1 - drawn / area)), touches: edge >= 2 };
|
||||
}
|
||||
|
||||
/** The largest region of the given shape in the middle of a width × height picture. */
|
||||
function middle(width: number, height: number, shape: number): sharp.Region {
|
||||
if (width / height > shape) {
|
||||
const w = Math.round(height * shape);
|
||||
return { left: Math.floor((width - w) / 2), top: 0, width: w, height };
|
||||
}
|
||||
const h = Math.round(width / shape);
|
||||
return { left: 0, top: Math.floor((height - h) / 2), width, height: h };
|
||||
}
|
||||
|
||||
async function rgba(input: Buffer): Promise<{ px: Buffer; width: number; height: number }> {
|
||||
const { data, info } = await sharp(input).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
|
||||
return { px: data, width: info.width, height: info.height };
|
||||
}
|
||||
|
||||
export async function acceptPicture(input: Buffer, id: string, m: Manifest): Promise<Accepted> {
|
||||
const target = findTarget(m, id);
|
||||
const a = target.asset;
|
||||
const notes: string[] = [];
|
||||
const { px, width, height } = await rgba(input).catch((e: unknown) => {
|
||||
throw new Refused(`${id}: the file could not be read as a picture (${String(e)})`);
|
||||
});
|
||||
|
||||
if (a.type === 'spritesheet') {
|
||||
const { width: cw, height: ch } = cellSize(a);
|
||||
const fitCell = (img: sharp.Sharp): sharp.Sharp =>
|
||||
img.resize(cw, ch, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 }, withoutEnlargement: true });
|
||||
|
||||
if (target.cell) {
|
||||
const corners = [[0, 0], [width - 1, 0], [0, height - 1], [width - 1, height - 1]] as const;
|
||||
if (corners.some(([x, y]) => (px[(y * width + x) * 4 + 3] ?? 0) >= ALPHA)) {
|
||||
throw new Refused(`${id}: the background is not transparent. Ask for a transparent PNG.`);
|
||||
}
|
||||
if (coverage(px, width, 0, 0, width, height).touches) notes.push(`${id}: the drawing touches the edge; something may be cut off.`);
|
||||
const out = await encode(fitCell(sharp(input)), BUDGET.cell, id);
|
||||
return { files: [{ id, ...out }], notes };
|
||||
}
|
||||
|
||||
const g = a.grid ?? { cols: 1, rows: 1 };
|
||||
if (Math.abs(width / height - a.width / a.height) > 0.02) {
|
||||
notes.push(`${id}: made at ${width} × ${height}, not ${a.width} × ${a.height}; cut by its ${g.cols} × ${g.rows} grid anyway.`);
|
||||
}
|
||||
const xs = cutLines(width, g.cols), ys = cutLines(height, g.rows);
|
||||
const cells = a.cells ?? [];
|
||||
const empty: string[] = [], painted: string[] = [];
|
||||
const regions = cells.map((c, i) => {
|
||||
const col = i % g.cols, row = Math.floor(i / g.cols);
|
||||
const x0 = xs[col] ?? 0, x1 = xs[col + 1] ?? width, y0 = ys[row] ?? 0, y1 = ys[row + 1] ?? height;
|
||||
const cov = coverage(px, width, x0, y0, x1, y1);
|
||||
if (cov.drawn < 0.005) empty.push(c.id);
|
||||
else if (cov.seeThrough < 5) painted.push(c.id);
|
||||
else if (cov.touches) notes.push(`${c.id}: the drawing touches its cell's edge; a neighbour may spill in.`);
|
||||
return { id: c.id, left: x0, top: y0, width: x1 - x0, height: y1 - y0 };
|
||||
});
|
||||
if (empty.length) throw new Refused(`${id}: nothing drawn in ${empty.join(', ')}. The whole sheet is refused.`);
|
||||
if (painted.length) throw new Refused(`${id}: painted on a background in ${painted.join(', ')}. The whole sheet is refused.`);
|
||||
const files: FinalFile[] = [];
|
||||
for (const r of regions) {
|
||||
const out = await encode(fitCell(sharp(input).extract({ left: r.left, top: r.top, width: r.width, height: r.height })), BUDGET.cell, r.id);
|
||||
files.push({ id: r.id, ...out });
|
||||
}
|
||||
return { files, notes };
|
||||
}
|
||||
|
||||
if (a.background === 'transparent') {
|
||||
// A garden layer is opaque below its horizon: only the top edge must be clear.
|
||||
const row = a.type === 'layer' ? coverage(px, width, 0, 0, width, 1).drawn : null;
|
||||
const corners = [[0, 0], [width - 1, 0], [0, height - 1], [width - 1, height - 1]] as const;
|
||||
const clear = row === null ? corners.every(([x, y]) => (px[(y * width + x) * 4 + 3] ?? 0) < ALPHA) : row < 0.02;
|
||||
if (!clear) throw new Refused(`${id}: the ${a.type === 'layer' ? 'sky' : 'background'} is not transparent. Ask for a transparent PNG.`);
|
||||
}
|
||||
if (Math.abs(width / height - a.width / a.height) > 0.02) {
|
||||
notes.push(`${id}: made at ${width} × ${height}, not ${a.width} × ${a.height}; ${a.background === 'full' ? 'cropped from the middle' : 'fitted inside with clear edges'}.`);
|
||||
}
|
||||
if (width < a.width) notes.push(`${id}: only ${width} px wide; kept at that size, never blown up.`);
|
||||
// Never blown up, so the shape comes first: a full picture is cropped from the middle to the
|
||||
// target shape, then only ever shrunk. Resizing with cover would skip the crop on a small one.
|
||||
const img = a.background === 'full'
|
||||
? sharp(input).extract(middle(width, height, a.width / a.height)).resize(a.width, a.height, { fit: 'inside', withoutEnlargement: true })
|
||||
: sharp(input).resize(a.width, a.height, { fit: 'contain', background: { r: 0, g: 0, b: 0, alpha: 0 }, withoutEnlargement: true });
|
||||
const out = await encode(img, BUDGET[a.type], id);
|
||||
return { files: [{ id, ...out }], notes };
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* The art board's data: every picture with its prompt, built from art/manifest.json and
|
||||
* art/STYLE.md (docs/ART.md §3). `pnpm art:board` writes it next to the board page and
|
||||
* refreshes art/placeholders/; Claude publishes the folder as the art board artifact.
|
||||
*/
|
||||
import { checkManifest, type Asset, type Background, type Manifest } from './manifest.js';
|
||||
import { attachments, cellPromptFor, cellSize, promptFor } from './prompt.js';
|
||||
import { reviewPoints, stylePrompt } from './style.js';
|
||||
|
||||
export interface BoardCell {
|
||||
readonly id: string;
|
||||
readonly type: 'pose';
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly background: Background;
|
||||
readonly prompt: string;
|
||||
}
|
||||
|
||||
export interface BoardAsset {
|
||||
readonly id: string;
|
||||
readonly type: Asset['type'];
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly background: Background;
|
||||
readonly shipped: boolean;
|
||||
readonly usedBy: readonly string[];
|
||||
readonly checks: readonly number[];
|
||||
readonly smallest: number | null;
|
||||
readonly attach: readonly string[];
|
||||
readonly prompt: string;
|
||||
readonly grid?: { readonly cols: number; readonly rows: number };
|
||||
readonly cells?: readonly BoardCell[];
|
||||
}
|
||||
|
||||
export interface BoardData {
|
||||
readonly generatedFrom: string;
|
||||
readonly checklist: readonly string[];
|
||||
readonly assets: readonly BoardAsset[];
|
||||
}
|
||||
|
||||
/** The board's data, or the manifest's problems. Nothing half-checked reaches the board. */
|
||||
export function boardData(m: Manifest, styleMarkdown: string): BoardData {
|
||||
const style = stylePrompt(styleMarkdown);
|
||||
const checklist = reviewPoints(styleMarkdown);
|
||||
const problems = checkManifest(m, checklist.length);
|
||||
if (problems.length > 0) throw new Error(`art/manifest.json:\n ${problems.join('\n ')}`);
|
||||
|
||||
const assets = m.assets.map((a): BoardAsset => {
|
||||
const base = {
|
||||
id: a.id, type: a.type, width: a.width, height: a.height, background: a.background,
|
||||
shipped: a.shipped, usedBy: a.usedBy, checks: a.checks, smallest: a.smallest,
|
||||
attach: attachments(a, m), prompt: promptFor(a, m, style)
|
||||
};
|
||||
if (a.type !== 'spritesheet' || !a.grid) return base;
|
||||
const { width, height } = cellSize(a);
|
||||
return {
|
||||
...base,
|
||||
grid: a.grid,
|
||||
cells: (a.cells ?? []).map((c) => ({
|
||||
id: c.id, type: 'pose', width, height, background: a.background, prompt: cellPromptFor(a, c, m, style)
|
||||
}))
|
||||
};
|
||||
});
|
||||
return { generatedFrom: 'art/manifest.json, art/STYLE.md §1 and §7', checklist, assets };
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* `pnpm art:accept <id> <file>` — moves a picture Mark accepted on the art board into
|
||||
* art/final/ as WebP (docs/ART.md §3, step 6). For a sprite sheet, `<id>` is the sheet
|
||||
* and every cell is written; for one cell made on its own, `<id>` is the cell.
|
||||
*/
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { join, relative } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { Refused, acceptPicture } from './accept.js';
|
||||
import type { Manifest } from './manifest.js';
|
||||
|
||||
const root = fileURLToPath(new URL('../../../', import.meta.url));
|
||||
const [id, file] = process.argv.slice(2);
|
||||
if (!id || !file) {
|
||||
console.error('Usage: pnpm art:accept <id> <file> (the id from art/manifest.json, the picture downloaded from the board)');
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const manifest = JSON.parse(readFileSync(join(root, 'art/manifest.json'), 'utf8')) as Manifest;
|
||||
try {
|
||||
const { files, notes } = await acceptPicture(readFileSync(file), id, manifest);
|
||||
const dir = join(root, 'art/final');
|
||||
mkdirSync(dir, { recursive: true });
|
||||
for (const f of files) {
|
||||
const path = join(dir, `${f.id}.webp`);
|
||||
writeFileSync(path, f.data);
|
||||
console.log(`${relative(root, path).replace(/\\/g, '/')} ${f.width} × ${f.height} ${(f.data.length / 1000).toFixed(1)} KB`);
|
||||
}
|
||||
for (const n of notes) console.log(`note: ${n}`);
|
||||
} catch (e) {
|
||||
if (e instanceof Refused) {
|
||||
console.error(`refused: ${e.message}`);
|
||||
process.exit(1);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* `pnpm art:board` — writes the art board's files to tools/art-prep/dist/board/ and
|
||||
* refreshes the stand-ins in art/placeholders/ (docs/ART.md §3).
|
||||
*/
|
||||
import { mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { PRODUCT_NAME } from '@rosea/schema';
|
||||
import { boardData } from './board.js';
|
||||
import type { Manifest } from './manifest.js';
|
||||
import { placeholders } from './placeholders.js';
|
||||
|
||||
const root = fileURLToPath(new URL('../../../', import.meta.url));
|
||||
const manifest = JSON.parse(readFileSync(join(root, 'art/manifest.json'), 'utf8')) as Manifest;
|
||||
const style = readFileSync(join(root, 'art/STYLE.md'), 'utf8');
|
||||
|
||||
const data = boardData(manifest, style);
|
||||
const stand = placeholders(manifest);
|
||||
|
||||
// art/placeholders/ holds exactly the stand-ins the manifest asks for: a removed picture loses its stand-in too.
|
||||
const placeDir = join(root, 'art/placeholders');
|
||||
mkdirSync(placeDir, { recursive: true });
|
||||
for (const f of readdirSync(placeDir)) if (f.endsWith('.svg') && !stand.has(f.slice(0, -4))) rmSync(join(placeDir, f));
|
||||
for (const [id, svg] of stand) writeFileSync(join(placeDir, `${id}.svg`), svg);
|
||||
|
||||
const out = join(root, 'tools/art-prep/dist/board');
|
||||
rmSync(out, { recursive: true, force: true });
|
||||
mkdirSync(join(out, 'placeholders'), { recursive: true });
|
||||
for (const [id, svg] of stand) writeFileSync(join(out, 'placeholders', `${id}.svg`), svg);
|
||||
writeFileSync(join(out, 'board-data.json'), JSON.stringify(data));
|
||||
const page = readFileSync(join(root, 'tools/art-prep/board/index.html'), 'utf8').replaceAll('%PRODUCT_NAME%', PRODUCT_NAME);
|
||||
writeFileSync(join(out, 'index.html'), page);
|
||||
|
||||
const pictures = data.assets.reduce((n, a) => n + (a.cells ? a.cells.length : 1), 0);
|
||||
console.log(`art:board: ${data.assets.length} cards, ${pictures} pictures, ${stand.size} stand-ins -> tools/art-prep/dist/board/`);
|
||||
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* art/manifest.json: every picture the game needs, and the checks that keep the
|
||||
* list honest before a single prompt is written (docs/ART.md §2).
|
||||
*/
|
||||
import { findForbidden } from '@rosea/content';
|
||||
|
||||
export type Background = 'full' | 'transparent';
|
||||
export type AssetType = 'sheet' | 'spritesheet' | 'sprite' | 'layer' | 'icon';
|
||||
|
||||
export interface Cell {
|
||||
readonly id: string;
|
||||
/** What this one picture shows, finishing the sentence "Cell n: …". */
|
||||
readonly does: string;
|
||||
}
|
||||
|
||||
export interface Asset {
|
||||
readonly id: string;
|
||||
readonly type: AssetType;
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly background: Background;
|
||||
/** False for a reference that never appears in the app (a character sheet). */
|
||||
readonly shipped: boolean;
|
||||
/** The smallest size, in px across, the app ever shows it; null when it is only shown large. */
|
||||
readonly smallest: number | null;
|
||||
readonly character?: string;
|
||||
readonly usedBy: readonly string[];
|
||||
readonly purpose: string;
|
||||
readonly subject?: string;
|
||||
readonly setting?: string;
|
||||
readonly composition?: string;
|
||||
readonly angle?: string;
|
||||
readonly grid?: { readonly cols: number; readonly rows: number };
|
||||
readonly cells?: readonly Cell[];
|
||||
readonly include: readonly string[];
|
||||
readonly avoid: readonly string[];
|
||||
/** Indices into STYLE.md §7, the review points shown on its card. */
|
||||
readonly checks: readonly number[];
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
readonly sheet: string;
|
||||
readonly description: string;
|
||||
}
|
||||
|
||||
export interface Manifest {
|
||||
readonly characters: Readonly<Record<string, Character>>;
|
||||
/** What no picture may show, appended to every prompt (STYLE.md §4). */
|
||||
readonly avoid: readonly string[];
|
||||
readonly assets: readonly Asset[];
|
||||
}
|
||||
|
||||
/** The canvases image generators offer (STYLE.md §5). Anything else gets resized by the tool, unasked. */
|
||||
export const GENERATOR_SIZES: readonly (readonly [number, number])[] = [
|
||||
[1024, 1024],
|
||||
[1536, 1024],
|
||||
[1024, 1536]
|
||||
];
|
||||
|
||||
const ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
||||
const TYPES: readonly AssetType[] = ['sheet', 'spritesheet', 'sprite', 'layer', 'icon'];
|
||||
|
||||
/** Every text a prompt is built from, so the forbidden-names check reads all of it. */
|
||||
function textsOf(a: Asset): string[] {
|
||||
return [
|
||||
a.purpose, a.subject, a.setting, a.composition, a.angle,
|
||||
...a.usedBy, ...a.include, ...a.avoid,
|
||||
...(a.cells ?? []).flatMap((c) => [c.id, c.does])
|
||||
].filter((t): t is string => typeof t === 'string');
|
||||
}
|
||||
|
||||
/**
|
||||
* Problems with the manifest, each naming the asset. An empty list is a pass.
|
||||
* `checklistLength` is the number of review points in STYLE.md §7.
|
||||
*/
|
||||
export function checkManifest(m: Manifest, checklistLength: number): string[] {
|
||||
const problems: string[] = [];
|
||||
const seen = new Set<string>();
|
||||
const claim = (id: string, where: string): void => {
|
||||
if (!ID.test(id)) problems.push(`${where}: id "${id}" must be lower-case words joined by hyphens`);
|
||||
if (seen.has(id)) problems.push(`${where}: id "${id}" is used twice; each picture needs its own`);
|
||||
seen.add(id);
|
||||
};
|
||||
|
||||
for (const [name, c] of Object.entries(m.characters)) {
|
||||
const sheet = m.assets.find((a) => a.id === c.sheet);
|
||||
if (!sheet) problems.push(`character ${name}: its sheet "${c.sheet}" is not in the manifest`);
|
||||
else if (sheet.type !== 'sheet') problems.push(`character ${name}: "${c.sheet}" is a ${sheet.type}, not a character sheet`);
|
||||
}
|
||||
|
||||
for (const a of m.assets) {
|
||||
claim(a.id, a.id);
|
||||
if (!TYPES.includes(a.type)) problems.push(`${a.id}: unknown type "${a.type}"`);
|
||||
if (!GENERATOR_SIZES.some(([w, h]) => w === a.width && h === a.height)) {
|
||||
problems.push(`${a.id}: ${a.width} × ${a.height} is not a size image generators offer (${GENERATOR_SIZES.map(([w, h]) => `${w} × ${h}`).join(', ')})`);
|
||||
}
|
||||
if (a.purpose.trim() === '') problems.push(`${a.id}: no purpose`);
|
||||
if (a.usedBy.length === 0) problems.push(`${a.id}: usedBy is empty; say where it appears`);
|
||||
if (a.character !== undefined && !(a.character in m.characters)) problems.push(`${a.id}: unknown character "${a.character}"`);
|
||||
if (a.type === 'sheet' && a.shipped) problems.push(`${a.id}: a character sheet is a reference and never shipped`);
|
||||
if ((a.type === 'layer' || a.type === 'sprite' || a.type === 'spritesheet') && a.background !== 'transparent') {
|
||||
problems.push(`${a.id}: a ${a.type} sits over other pictures, so its background must be transparent`);
|
||||
}
|
||||
if (a.type !== 'spritesheet' && (a.subject ?? '').trim() === '') problems.push(`${a.id}: no subject`);
|
||||
for (const i of a.checks) {
|
||||
if (!Number.isInteger(i) || i < 0 || i >= checklistLength) problems.push(`${a.id}: review point ${i} is not in STYLE.md §7`);
|
||||
}
|
||||
|
||||
if (a.type === 'spritesheet') {
|
||||
const g = a.grid;
|
||||
const cells = a.cells ?? [];
|
||||
if (!g) problems.push(`${a.id}: a sprite sheet needs a grid`);
|
||||
else {
|
||||
if (cells.length !== g.cols * g.rows) problems.push(`${a.id}: ${cells.length} cells for a ${g.cols} × ${g.rows} grid`);
|
||||
if (a.width % g.cols !== 0 || a.height % g.rows !== 0) problems.push(`${a.id}: ${a.width} × ${a.height} does not divide into ${g.cols} × ${g.rows} whole-pixel cells`);
|
||||
}
|
||||
if ((a.angle ?? '').trim() === '') problems.push(`${a.id}: a sprite sheet needs an angle, so every cell is drawn alike`);
|
||||
for (const c of cells) {
|
||||
claim(c.id, `${a.id} cell`);
|
||||
if (c.does.trim() === '') problems.push(`${a.id}: cell ${c.id} does not say what it shows`);
|
||||
}
|
||||
} else if (a.grid || a.cells) {
|
||||
problems.push(`${a.id}: only a sprite sheet has a grid and cells`);
|
||||
}
|
||||
|
||||
for (const text of textsOf(a)) {
|
||||
for (const hit of findForbidden(text)) problems.push(`${a.id}: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [name, c] of Object.entries(m.characters)) {
|
||||
for (const hit of findForbidden(c.description)) problems.push(`character ${name}: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
for (const text of m.avoid) {
|
||||
for (const hit of findForbidden(text)) problems.push(`avoid list: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
@@ -0,0 +1,217 @@
|
||||
/**
|
||||
* Claude's stand-ins (CLAUDE.md §2, art/placeholders/): plain SVG shapes that test form and
|
||||
* layout until a real picture is accepted. They are deliberately simple. A stand-in that
|
||||
* looked finished would hide that the real picture is still missing.
|
||||
*/
|
||||
import type { Asset, Manifest } from './manifest.js';
|
||||
import { cellBoxes, cellSize } from './prompt.js';
|
||||
|
||||
const C = {
|
||||
rose: '#c85a6e',
|
||||
petal: '#f2b5be',
|
||||
blush: '#e8899b',
|
||||
leaf: '#7fa07a',
|
||||
moss: '#4f6e52',
|
||||
ink: '#3a2730',
|
||||
paper: '#fbf6f1',
|
||||
soil: '#8a6248',
|
||||
wood: '#b98a5a',
|
||||
meadow: '#a9c48e',
|
||||
amber: '#f2b860',
|
||||
coral: '#e9846a',
|
||||
night: '#2e3561',
|
||||
lamp: '#f4d58d'
|
||||
} as const;
|
||||
|
||||
type Eyes = 'open' | 'half' | 'closed' | 'down' | 'squeeze';
|
||||
type Mouth = 'smile' | 'small' | 'open' | 'puff';
|
||||
|
||||
interface RoseLook {
|
||||
readonly stage: 'bud' | 'opening' | 'half' | 'full';
|
||||
readonly eyes: Eyes;
|
||||
readonly mouth: Mouth;
|
||||
readonly blush?: boolean;
|
||||
/** Degrees the bloom leans from the stem top; negative is left. */
|
||||
readonly tilt?: number;
|
||||
readonly leaves?: 'normal' | 'down' | 'up' | 'raised';
|
||||
readonly back?: boolean;
|
||||
readonly drops?: boolean;
|
||||
readonly bend?: number;
|
||||
}
|
||||
|
||||
/** The rose in a 200 × 520 box: bloom near the top, stem down to the bottom edge. */
|
||||
function rose(look: RoseLook): string {
|
||||
const r = { bud: 30, opening: 44, half: 58, full: 74 }[look.stage];
|
||||
const bend = look.bend ?? 0;
|
||||
const stem = `<path d="M100 520 Q ${100 + bend} 340 ${100 + bend * 1.6} 170" fill="none" stroke="${C.moss}" stroke-width="9" stroke-linecap="round"/>`;
|
||||
const thorns = [430, 300, 220]
|
||||
.map((y, i) => `<path d="M${100 + (bend * (520 - y)) / 350 + (i % 2 ? 4 : -4)} ${y} l${i % 2 ? 12 : -12} -6 l${i % 2 ? -10 : 10} -6z" fill="${C.moss}"/>`)
|
||||
.join('');
|
||||
const leafRot = { normal: [-35, 35, -30], down: [10, -10, 15], up: [-60, 60, -55], raised: [-35, 80, -30] }[look.leaves ?? 'normal'];
|
||||
const leaf = (x: number, y: number, dir: number, rot: number): string =>
|
||||
`<ellipse cx="${x + dir * 30}" cy="${y}" rx="34" ry="14" fill="${C.leaf}" stroke="${C.ink}" stroke-width="3" transform="rotate(${rot} ${x} ${y})"/>`;
|
||||
const leaves = leaf(100, 400, -1, leafRot[0] ?? 0) + leaf(100 + bend * 0.5, 330, 1, leafRot[1] ?? 0) + leaf(100 + bend, 250, -1, leafRot[2] ?? 0);
|
||||
|
||||
const count = look.stage === 'opening' ? 5 : 8;
|
||||
const petals =
|
||||
look.stage === 'bud'
|
||||
? `<path d="M100 ${130 - r * 1.6} C ${100 + r} ${130 - r}, ${100 + r} ${130 + r * 0.6}, 100 ${130 + r * 0.7} C ${100 - r} ${130 + r * 0.6}, ${100 - r} ${130 - r}, 100 ${130 - r * 1.6}z" fill="${C.rose}" stroke="${C.ink}" stroke-width="3"/>
|
||||
<path d="M70 ${150} q30 20 60 0 l-8 18 h-44z" fill="${C.leaf}" stroke="${C.ink}" stroke-width="3"/>`
|
||||
: Array.from({ length: count }, (_, i) => {
|
||||
const a = (i / count) * Math.PI * 2;
|
||||
return `<circle cx="${(100 + Math.cos(a) * r * 0.55).toFixed(1)}" cy="${(130 + Math.sin(a) * r * 0.55).toFixed(1)}" r="${(r * 0.55).toFixed(1)}" fill="${C.rose}" stroke="${C.ink}" stroke-width="3"/>`;
|
||||
}).join('') + `<circle cx="100" cy="130" r="${(r * 0.62).toFixed(1)}" fill="${C.petal}" stroke="${C.ink}" stroke-width="3"/>`;
|
||||
|
||||
const eye = (x: number): string => {
|
||||
const y = 124;
|
||||
switch (look.eyes) {
|
||||
case 'open': return `<circle cx="${x}" cy="${y}" r="4.5" fill="${C.ink}"/>`;
|
||||
case 'half': return `<path d="M${x - 6} ${y} q6 5 12 0" fill="${C.ink}" stroke="${C.ink}" stroke-width="3"/>`;
|
||||
case 'closed': return `<path d="M${x - 6} ${y} q6 6 12 0" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||||
case 'down': return `<path d="M${x - 6} ${y + 3} q6 4 12 0" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||||
case 'squeeze': return `<path d="M${x - 6} ${y - 4} l12 4 l-12 4" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||||
}
|
||||
};
|
||||
const mouth = {
|
||||
smile: `<path d="M93 142 q7 7 14 0" fill="none" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`,
|
||||
small: `<path d="M96 144 h8" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`,
|
||||
open: `<ellipse cx="100" cy="145" rx="6" ry="5" fill="${C.ink}"/>`,
|
||||
puff: `<circle cx="100" cy="145" r="4" fill="${C.ink}"/><circle cx="84" cy="140" r="7" fill="${C.blush}" opacity=".7"/><circle cx="116" cy="140" r="7" fill="${C.blush}" opacity=".7"/>`
|
||||
}[look.mouth];
|
||||
const blush = look.blush ? `<circle cx="82" cy="138" r="8" fill="${C.blush}"/><circle cx="118" cy="138" r="8" fill="${C.blush}"/>` : '';
|
||||
const face = look.back ? '' : eye(91) + eye(109) + mouth + blush;
|
||||
const drops = look.drops
|
||||
? [[64, 92], [138, 104], [120, 70]].map(([x, y]) => `<path d="M${x} ${y} q5 9 0 12 q-5 -3 0 -12z" fill="#9cc3d8" stroke="${C.ink}" stroke-width="2"/>`).join('')
|
||||
: '';
|
||||
const bloom = `<g transform="translate(${bend * 1.6} 0) rotate(${look.tilt ?? 0} 100 170)">${petals}${face}${drops}</g>`;
|
||||
return stem + thorns + leaves + bloom;
|
||||
}
|
||||
|
||||
/** Place a drawing made in a w × h box centred in the target, filling about 76 %. */
|
||||
function fit(body: string, w: number, h: number, W: number, H: number, fill = 0.76): string {
|
||||
const s = Math.min((W * fill) / w, (H * fill) / h);
|
||||
return `<g transform="translate(${((W - w * s) / 2).toFixed(1)} ${((H - h * s) / 2).toFixed(1)}) scale(${s.toFixed(4)})">${body}</g>`;
|
||||
}
|
||||
|
||||
const ROSES: Record<string, RoseLook> = {
|
||||
'rose-bud': { stage: 'bud', eyes: 'closed', mouth: 'small' },
|
||||
'rose-opening': { stage: 'opening', eyes: 'half', mouth: 'small' },
|
||||
'rose-half-bloom': { stage: 'half', eyes: 'half', mouth: 'smile' },
|
||||
'rose-full-bloom': { stage: 'full', eyes: 'half', mouth: 'smile', tilt: -4 },
|
||||
'rose-thirsty': { stage: 'full', eyes: 'down', mouth: 'small', tilt: 14, leaves: 'down' },
|
||||
'rose-overwatered': { stage: 'full', eyes: 'squeeze', mouth: 'puff', leaves: 'down', drops: true },
|
||||
'rose-windblown': { stage: 'full', eyes: 'squeeze', mouth: 'small', bend: 22, tilt: 18, leaves: 'up' },
|
||||
'rose-blushing': { stage: 'full', eyes: 'closed', mouth: 'smile', blush: true, leaves: 'raised' },
|
||||
'rose-sleepy': { stage: 'half', eyes: 'closed', mouth: 'smile', tilt: 10 },
|
||||
'rose-speaking': { stage: 'full', eyes: 'open', mouth: 'open', leaves: 'raised' },
|
||||
'rose-waiting': { stage: 'half', eyes: 'down', mouth: 'small', tilt: -18, leaves: 'down' },
|
||||
'rose-watching-sunset': { stage: 'full', eyes: 'open', mouth: 'small', back: true, tilt: -10 }
|
||||
};
|
||||
|
||||
/** The care things, each in a 200 × 200 box. */
|
||||
const PROPS: Record<string, string> = {
|
||||
'watering-can': `<rect x="50" y="80" width="90" height="80" rx="18" fill="${C.leaf}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M60 80 q35 -55 70 0" fill="none" stroke="${C.ink}" stroke-width="7"/>
|
||||
<path d="M52 110 L12 70" stroke="${C.ink}" stroke-width="10" stroke-linecap="round"/><circle cx="12" cy="68" r="10" fill="${C.leaf}" stroke="${C.ink}" stroke-width="4"/>`,
|
||||
windbreak: Array.from({ length: 9 }, (_, i) => `<path d="M${30 + i * 18} ${150 - Math.sin((i / 8) * Math.PI) * 18} v-${90 - Math.sin((i / 8) * Math.PI) * 10}" stroke="${C.wood}" stroke-width="12" stroke-linecap="round"/>`).join('')
|
||||
+ `<path d="M24 100 Q100 75 176 100" fill="none" stroke="${C.soil}" stroke-width="6"/><path d="M24 128 Q100 103 176 128" fill="none" stroke="${C.soil}" stroke-width="6"/>
|
||||
<path d="M30 150 v30 M170 150 v30" stroke="${C.soil}" stroke-width="8" stroke-linecap="round"/>`,
|
||||
'weed-clump': [60, 100, 140].map((x, i) => `<path d="M${x} 140 l-18 -${60 + i * 12} l14 12 l4 -${30 + i * 6} l8 24 l12 -20 l-6 ${60 + i * 8}z" fill="${C.leaf}" stroke="${C.ink}" stroke-width="4"/>`).join('')
|
||||
+ `<path d="M70 140 q10 30 -6 44 M100 140 q-4 26 10 40 M130 140 q8 22 -2 38" fill="none" stroke="${C.soil}" stroke-width="4"/>`,
|
||||
'fallen-petals': [[60, 110, -20], [110, 90, 25], [140, 130, 60]].map(([x, y, r]) => `<ellipse cx="${x}" cy="${y}" rx="34" ry="22" fill="${C.rose}" stroke="${C.ink}" stroke-width="4" transform="rotate(${r} ${x} ${y})"/>`).join(''),
|
||||
'petal-folded': `<circle cx="100" cy="100" r="86" fill="${C.lamp}" opacity=".35"/><path d="M100 30 C 170 60, 160 160, 100 170 C 40 160, 30 60, 100 30z" fill="${C.rose}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M100 30 C 120 90, 120 130, 100 170" fill="none" stroke="${C.petal}" stroke-width="6"/>`,
|
||||
'petal-open': `<path d="M100 20 C 190 50, 190 160, 100 182 C 10 160, 10 50, 100 20z" fill="${C.petal}" stroke="${C.ink}" stroke-width="5"/>`,
|
||||
'garden-chair': `<rect x="60" y="40" width="80" height="70" rx="8" fill="${C.wood}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M70 55 h60 M70 75 h60 M70 95 h60" stroke="${C.soil}" stroke-width="4"/>
|
||||
<path d="M50 110 h100 l-10 24 h-80z" fill="${C.petal}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<path d="M62 134 v46 M138 134 v46 M80 134 v36 M120 134 v36" stroke="${C.wood}" stroke-width="9" stroke-linecap="round"/>`
|
||||
};
|
||||
|
||||
function garden(W: number, H: number, time: 'morning' | 'day' | 'sunset' | 'night'): string {
|
||||
const tint = {
|
||||
morning: { field: '#b8d1a0', far: '#c9dbe0', wall: '#b4a596', light: '#ffffff' },
|
||||
day: { field: C.meadow, far: '#b9cfa8', wall: '#a8957f', light: '#fff6d8' },
|
||||
sunset: { field: '#c9b07a', far: '#d9a98a', wall: '#a07b62', light: C.amber },
|
||||
night: { field: '#3c4a6a', far: '#46557a', wall: '#3a4466', light: C.lamp }
|
||||
}[time];
|
||||
const h = Math.round(H * 0.4);
|
||||
const bedY = Math.round(H * 0.72);
|
||||
return `<path d="M0 ${h} Q ${W * 0.3} ${h - 18} ${W * 0.55} ${h - 6} T ${W} ${h + 4} V ${H} H 0z" fill="${tint.far}"/>
|
||||
<path d="M0 ${h + 90} Q ${W * 0.5} ${h + 50} ${W} ${h + 110} V ${H} H 0z" fill="${tint.field}"/>
|
||||
<path d="M${W * 0.12} ${bedY - 70} Q ${W * 0.5} ${bedY - 150} ${W * 0.88} ${bedY - 70}" fill="none" stroke="${tint.wall}" stroke-width="44" stroke-linecap="round"/>
|
||||
<ellipse cx="${W / 2}" cy="${bedY}" rx="${W * 0.3}" ry="${H * 0.05}" fill="${C.soil}" stroke="${C.ink}" stroke-width="5"/>
|
||||
<circle cx="${time === 'sunset' ? 80 : W - 80}" cy="${h + 60}" r="26" fill="${tint.light}" opacity=".8"/>
|
||||
<path d="M0 ${h} H ${W}" stroke="${C.ink}" stroke-width="3" stroke-dasharray="14 10"/>`;
|
||||
}
|
||||
|
||||
function single(a: Asset): string {
|
||||
const { width: W, height: H } = a;
|
||||
switch (a.type) {
|
||||
case 'sheet': {
|
||||
const looks: RoseLook[] = [
|
||||
{ stage: 'full', eyes: 'half', mouth: 'smile' },
|
||||
{ stage: 'full', eyes: 'half', mouth: 'smile', tilt: -12 },
|
||||
{ stage: 'full', eyes: 'half', mouth: 'small', tilt: -20 },
|
||||
{ stage: 'full', eyes: 'half', mouth: 'small', back: true }
|
||||
];
|
||||
const figures = looks.map((l, i) => `<g transform="translate(${60 + i * 360} 40) scale(1.15)">${rose(l)}</g>`).join('');
|
||||
const heads: RoseLook[] = [
|
||||
{ stage: 'full', eyes: 'half', mouth: 'smile' },
|
||||
{ stage: 'half', eyes: 'closed', mouth: 'smile' },
|
||||
{ stage: 'full', eyes: 'closed', mouth: 'smile', blush: true }
|
||||
];
|
||||
// Close-ups: only the bloom, cropped by a nested viewBox.
|
||||
const close = heads.map((l, i) => `<svg x="${200 + i * 400}" y="660" width="320" height="320" viewBox="10 40 180 180">${rose(l)}</svg>`).join('');
|
||||
return `<rect width="${W}" height="${H}" fill="${C.paper}"/>${figures}${close}`;
|
||||
}
|
||||
case 'sprite':
|
||||
return fit(PROPS[a.id] ?? '', 200, 200, W, H, 0.7);
|
||||
case 'layer': {
|
||||
const time = (['morning', 'day', 'sunset', 'night'] as const).find((t) => a.id.endsWith(t)) ?? 'day';
|
||||
return garden(W, H, time);
|
||||
}
|
||||
case 'icon':
|
||||
return `<rect width="${W}" height="${H}" fill="${C.coral}"/><rect y="${H / 2}" width="${W}" height="${H / 2}" fill="${C.amber}" opacity=".6"/>
|
||||
<svg x="${W * 0.15}" y="${H * 0.12}" width="${W * 0.7}" height="${H * 0.76}" viewBox="0 30 200 230">${rose({ stage: 'full', eyes: 'half', mouth: 'smile', blush: true })}</svg>`;
|
||||
case 'spritesheet':
|
||||
return sheet(a);
|
||||
}
|
||||
}
|
||||
|
||||
/** One cell's drawing, sized to the cell it ships at. */
|
||||
function cellBody(id: string, W: number, H: number): string {
|
||||
const look = ROSES[id];
|
||||
if (look) return fit(rose(look), 200, 520, W, H);
|
||||
return fit(PROPS[id] ?? '', 200, 200, W, H, 0.7);
|
||||
}
|
||||
|
||||
function sheet(a: Asset): string {
|
||||
const g = a.grid ?? { cols: 1, rows: 1 };
|
||||
return cellBoxes(a.width, a.height, g.cols, g.rows)
|
||||
.map((b, i) => {
|
||||
const c = a.cells?.[i];
|
||||
if (!c) return '';
|
||||
const w = b.x1 - b.x0, h = b.y1 - b.y0;
|
||||
return `<svg x="${b.x0}" y="${b.y0}" width="${w}" height="${h}" viewBox="0 0 ${w} ${h}">${cellBody(c.id, w, h)}</svg>`;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
const wrap = (id: string, W: number, H: number, body: string): string =>
|
||||
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${W} ${H}" width="${W}" height="${H}">\n` +
|
||||
` <!-- Stand-in for ${id} (art/placeholders, CLAUDE.md §2): form and layout only, not art. Built by tools/art-prep. -->\n` +
|
||||
` ${body.replace(/\s*\n\s*/g, ' ')}\n</svg>\n`;
|
||||
|
||||
/** Every stand-in the board and the app may show: one per asset and one per sprite-sheet cell. */
|
||||
export function placeholders(m: Manifest): Map<string, string> {
|
||||
const out = new Map<string, string>();
|
||||
for (const a of m.assets) {
|
||||
out.set(a.id, wrap(a.id, a.width, a.height, single(a)));
|
||||
if (a.type === 'spritesheet') {
|
||||
const { width, height } = cellSize(a);
|
||||
for (const c of a.cells ?? []) out.set(c.id, wrap(c.id, width, height, cellBody(c.id, width, height)));
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
/**
|
||||
* 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 };
|
||||
}
|
||||
|
||||
const KIND: Record<Asset['type'], string> = {
|
||||
sheet: 'character sheet',
|
||||
spritesheet: 'sprite sheet',
|
||||
sprite: 'single picture',
|
||||
layer: 'garden layer',
|
||||
icon: 'app icon'
|
||||
};
|
||||
|
||||
const bg = (b: Asset['background']): string => (b === 'transparent' ? 'transparent background' : 'full background');
|
||||
const list = (items: readonly string[]): string => items.join('; ');
|
||||
|
||||
/** Extra things a sprite sheet must never have, so it can be cut cleanly. */
|
||||
const SHEET_AVOID = [
|
||||
'grid lines, cell borders or frames',
|
||||
'a background colour or paper behind the drawings',
|
||||
'ground or cast shadows',
|
||||
'drawings touching or overlapping',
|
||||
'cropped petals, leaves or stems'
|
||||
];
|
||||
|
||||
/** The character the picture shows, with the sheet to attach, or the sheet's own description. */
|
||||
function subjectLine(a: Asset, m: Manifest, subject: string): string {
|
||||
const c = a.character === undefined ? undefined : m.characters[a.character];
|
||||
if (!c) return subject;
|
||||
if (c.sheet === a.id) return `${subject} ${c.description}`;
|
||||
return `${subject} Attach the character sheet ${c.sheet} as the reference picture and match it exactly. ${c.description}`.trim();
|
||||
}
|
||||
|
||||
/** The reference pictures to attach when making `a`. */
|
||||
export function attachments(a: Asset, m: Manifest): string[] {
|
||||
const c = a.character === undefined ? undefined : m.characters[a.character];
|
||||
return c && c.sheet !== a.id ? [c.sheet] : [];
|
||||
}
|
||||
|
||||
function canvasLine(width: number, height: number): string {
|
||||
const mx = Math.round(width * 0.15), my = Math.round(height * 0.15);
|
||||
return `Canvas: ${width} × ${height} px, fully transparent background. One subject, centred on (${width / 2}, ${height / 2}), whole and uncropped, filling about 70 % of the canvas: everything inside x ${mx}–${width - mx}, y ${my}–${height - my}, nothing touching an edge. No background colour or paper behind it, no ground, no cast shadow.`;
|
||||
}
|
||||
|
||||
/** 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,
|
||||
'',
|
||||
`Asset: ${a.id}`,
|
||||
`Purpose: ${a.purpose}`,
|
||||
`Subject: ${subjectLine(a, m, a.subject ?? '')}`
|
||||
];
|
||||
if (a.setting) lines.push(`Setting: ${a.setting}`);
|
||||
if (a.type === 'sprite') lines.push(canvasLine(a.width, a.height));
|
||||
if (a.composition) lines.push(`Composition: ${a.composition}`);
|
||||
lines.push(
|
||||
`Size: ${a.width} × ${a.height} px, ${bg(a.background)} (STYLE.md §5, ${KIND[a.type]})`,
|
||||
`Must include: ${list(a.include)}`,
|
||||
`Must avoid: ${list([...a.avoid, ...m.avoid])}`
|
||||
);
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function sheetPrompt(a: Asset, m: Manifest, style: string): string {
|
||||
const g = a.grid ?? { cols: 1, rows: 1 };
|
||||
const cells = a.cells ?? [];
|
||||
const { width: cw, height: ch } = cellSize(a);
|
||||
const boxes = cellBoxes(a.width, a.height, g.cols, g.rows);
|
||||
const margin = Math.round(SAFE_MARGIN * Math.min(cw, ch));
|
||||
const xs = cutLines(a.width, g.cols).slice(1, -1);
|
||||
const ys = cutLines(a.height, g.rows).slice(1, -1);
|
||||
const cuts = [
|
||||
xs.length ? `Cut lines down the image at x = ${xs.join(', ')}.` : '',
|
||||
ys.length ? `Cut lines across the image at y = ${ys.join(', ')}.` : ''
|
||||
].filter(Boolean).join(' ');
|
||||
|
||||
return [
|
||||
style,
|
||||
'',
|
||||
`Asset: ${a.id}`,
|
||||
`Kind: a sprite sheet. One image holding ${cells.length} separate pictures on a clean grid; it is cut apart along the grid and each cell becomes its own picture in the app. The sheet itself is never shown.`,
|
||||
`Purpose: ${a.purpose}`,
|
||||
`Subject: ${subjectLine(a, m, '') || 'Each cell holds its own thing, described in the cell list below.'}`,
|
||||
`Angle and scale: ${a.angle ?? ''}`,
|
||||
`Canvas: ${a.width} × ${a.height} px, transparent background: a size image generators offer, and the size the grid below is measured on. The app divides the image into ${g.cols} × ${g.rows} equal cells whatever its size.`,
|
||||
`Layout: a clean grid of ${g.cols} column${g.cols === 1 ? '' : 's'} × ${g.rows} row${g.rows === 1 ? '' : 's'} of equal, invisible cells, each ${cw} × ${ch} px, read like a book (left to right, top row first). One subject per cell, centred in its cell, whole and uncropped, with generous empty gutters, so nothing touches the edge of its cell or reaches into a neighbour. No grid lines, borders, frames, numbers, labels or captions anywhere. Fully transparent background between and around the subjects: no paper colour, no ground, no cast shadows. The same light from the left, the same outline weight and the same gouache texture in every cell.`,
|
||||
`Cells (${cells.length}, in reading order):`,
|
||||
...cells.map((c, i) => {
|
||||
const b = boxes[i];
|
||||
return `${i + 1}. ${c.id} (row ${(b?.row ?? 0) + 1}, column ${(b?.col ?? 0) + 1}): ${c.does}`;
|
||||
}),
|
||||
`Grid in pixels:`,
|
||||
`- ${cuts} The lines are never drawn: they are where the scissors go.`,
|
||||
`- Each drawing stays whole inside its own safe box, at least ${margin} px clear of every edge of its cell, so a band of at least ${margin * 2} px of empty transparency runs along every cut line and round the outside. Nothing crosses a cut line: no petal, leaf, stem, shadow or sparkle.`,
|
||||
...cells.map((c, i) => {
|
||||
const b = boxes[i];
|
||||
if (!b) return '';
|
||||
return `- Cell ${i + 1}, ${c.id}: starts at (${b.x0}, ${b.y0}), ends at (${b.x1}, ${b.y1}); centre the drawing on (${b.cx}, ${b.cy}); safe box x ${b.safe.x0}–${b.safe.x1}, y ${b.safe.y0}–${b.safe.y1}.`;
|
||||
}).filter(Boolean),
|
||||
`- One scale for the whole sheet: the largest drawing fills its safe box and every other cell is drawn at that same scale, centred on its cell's centre.`,
|
||||
`- If the tool makes the image another size, keep the same ${g.cols} × ${g.rows} division into equal cells and scale every number above by the same factor.`,
|
||||
`Size: generate at ${a.width} × ${a.height} px (see Canvas); each cell ships at up to ${cw} × ${ch} px, transparent (STYLE.md §5 and §9).`,
|
||||
`Must include: ${list(a.include)}`,
|
||||
`Must avoid: ${list([...a.avoid, ...SHEET_AVOID, ...m.avoid])}`
|
||||
].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,
|
||||
'',
|
||||
`Asset: ${cell.id} (one picture of ${a.id}, made on its own)`,
|
||||
'Kind: a single picture on a transparent background; it becomes one picture in the app.',
|
||||
`Purpose: ${a.purpose}`,
|
||||
`Subject: ${subjectLine(a, m, '') || 'Each cell holds its own thing, described in the cell list below.'}`,
|
||||
`Angle and scale: ${a.angle ?? ''}`,
|
||||
`This picture: ${cell.does}`,
|
||||
canvasLine(width, height),
|
||||
`Must include: ${list(a.include)}`,
|
||||
`Must avoid: ${list([...a.avoid, ...m.avoid])}`
|
||||
].join('\n');
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
* Reads art/STYLE.md: §1, the system prompt every picture starts with, and §7, the
|
||||
* review points. The file is the only copy of both, so Mark edits one place.
|
||||
*/
|
||||
|
||||
function section(markdown: string, n: number): string {
|
||||
const text = markdown.replace(/\r\n?/g, '\n');
|
||||
const start = text.search(new RegExp(`^## ${n}\\.`, 'm'));
|
||||
if (start < 0) throw new Error(`art/STYLE.md has no "## ${n}." section`);
|
||||
const rest = text.slice(start);
|
||||
const end = rest.slice(1).search(/^## /m);
|
||||
return end < 0 ? rest : rest.slice(0, end + 1);
|
||||
}
|
||||
|
||||
/** §1: the quoted paragraph, line breaks kept, the `> ` markers removed. */
|
||||
export function stylePrompt(markdown: string): string {
|
||||
const lines = section(markdown, 1)
|
||||
.split('\n')
|
||||
.filter((l) => l.startsWith('>'))
|
||||
.map((l) => l.replace(/^>\s?/, ''));
|
||||
if (lines.length === 0) throw new Error('art/STYLE.md §1 has no quoted system prompt');
|
||||
return lines.join('\n').trim();
|
||||
}
|
||||
|
||||
/** §7: the numbered review points, each joined into one line. */
|
||||
export function reviewPoints(markdown: string): string[] {
|
||||
const points: string[] = [];
|
||||
for (const line of section(markdown, 7).split('\n')) {
|
||||
const item = /^(\d+)\.\s+(.*)$/.exec(line);
|
||||
if (item) {
|
||||
if (Number(item[1]) !== points.length) throw new Error(`art/STYLE.md §7: point ${item[1]} is out of order`);
|
||||
points.push((item[2] ?? '').trim());
|
||||
} else if (/^\s+\S/.test(line) && points.length > 0) {
|
||||
points[points.length - 1] += ' ' + line.trim();
|
||||
}
|
||||
}
|
||||
if (points.length === 0) throw new Error('art/STYLE.md §7 has no review points');
|
||||
return points;
|
||||
}
|
||||
Reference in New Issue
Block a user