[art] GardenerLayers: The gardener in layered parts, painted over one guide in register, checked on accept
This commit is contained in:
@@ -96,9 +96,53 @@ async function rgba(input: Buffer): Promise<{ px: Buffer; width: number; height:
|
||||
return { px: data, width: info.width, height: info.height };
|
||||
}
|
||||
|
||||
export async function acceptPicture(input: Buffer, id: string, m: Manifest): Promise<Accepted> {
|
||||
/** Where a cell's drawing lies, as shares of the cell (0–1), or null when nothing is drawn. */
|
||||
interface Extent {
|
||||
readonly x0: number;
|
||||
readonly y0: number;
|
||||
readonly x1: number;
|
||||
readonly y1: number;
|
||||
}
|
||||
|
||||
function extent(px: Buffer, width: number, x0: number, y0: number, x1: number, y1: number): Extent | null {
|
||||
let lx = Infinity, ly = Infinity, hx = -Infinity, hy = -Infinity;
|
||||
for (let y = y0; y < y1; y++) {
|
||||
for (let x = x0; x < x1; x++) {
|
||||
if ((px[(y * width + x) * 4 + 3] ?? 0) < ALPHA) continue;
|
||||
lx = Math.min(lx, x); hx = Math.max(hx, x); ly = Math.min(ly, y); hy = Math.max(hy, y);
|
||||
}
|
||||
}
|
||||
if (lx === Infinity) return null;
|
||||
const w = x1 - x0, h = y1 - y0;
|
||||
return { x0: (lx - x0) / w, y0: (ly - y0) / h, x1: (hx + 1 - x0) / w, y1: (hy + 1 - y0) / h };
|
||||
}
|
||||
|
||||
/**
|
||||
* How far a layer may reach past its guide's figure, as a share of the cell: hair and a hat may
|
||||
* be a little fuller than the guide's braids and straw hat, never somewhere else.
|
||||
*/
|
||||
export const REGISTER = 0.08;
|
||||
|
||||
/** The guide's cells, as accepted into art/final/: cell id → its WebP. */
|
||||
export type Guide = ReadonlyMap<string, Buffer>;
|
||||
|
||||
async function guideExtent(guide: Guide, cell: string): Promise<Extent | null> {
|
||||
const file = guide.get(cell);
|
||||
if (!file) return null;
|
||||
const { px, width, height } = await rgba(file);
|
||||
return extent(px, width, 0, 0, width, height);
|
||||
}
|
||||
|
||||
export async function acceptPicture(input: Buffer, id: string, m: Manifest, guide?: Guide): Promise<Accepted> {
|
||||
const target = findTarget(m, id);
|
||||
const a = target.asset;
|
||||
if (a.over && target.cell) {
|
||||
throw new Refused(`${id}: a layer is painted whole over its guide (${a.over}), never one picture at a time; the parts would not line up. Accept ${a.id} whole.`);
|
||||
}
|
||||
const guideCells = a.over && a.grid ? (m.assets.find((g) => g.id === a.over)?.cells ?? []) : [];
|
||||
if (a.over && guideCells.some((c) => !guide?.has(c.id))) {
|
||||
throw new Refused(`${id}: its guide ${a.over} is not in art/final/ yet. Accept the guide first: every layer is checked against it.`);
|
||||
}
|
||||
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)})`);
|
||||
@@ -137,6 +181,18 @@ export async function acceptPicture(input: Buffer, id: string, m: Manifest): Pro
|
||||
});
|
||||
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.`);
|
||||
if (a.over && guide) {
|
||||
// In register: each picture's part lies on the guide's figure in the same cell (STYLE.md §3b).
|
||||
const off: string[] = [];
|
||||
for (const [i, r] of regions.entries()) {
|
||||
const mine = extent(px, width, r.left, r.top, r.left + r.width, r.top + r.height);
|
||||
const under = await guideExtent(guide, guideCells[i]?.id ?? '');
|
||||
if (!mine || !under) continue;
|
||||
const out = Math.max(under.x0 - mine.x0, under.y0 - mine.y0, mine.x1 - under.x1, mine.y1 - under.y1);
|
||||
if (out > REGISTER) off.push(`${r.id} (${Math.round(out * 100)} % of the cell outside the guide's figure)`);
|
||||
}
|
||||
if (off.length) throw new Refused(`${id}: not in register with ${a.over} in ${off.join(', ')}. Paint it over the guide again; 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);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 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 { checkManifest, expandLayers, type Asset, type Background, type Manifest } from './manifest.js';
|
||||
import { attachments, cellPromptFor, cellSize, promptFor } from './prompt.js';
|
||||
import { reviewPoints, stylePrompt } from './style.js';
|
||||
|
||||
@@ -31,6 +31,8 @@ export interface BoardAsset {
|
||||
readonly prompt: string;
|
||||
readonly grid?: { readonly cols: number; readonly rows: number };
|
||||
readonly cells?: readonly BoardCell[];
|
||||
/** A layer: the guide it is painted over. Made whole, never one picture at a time (STYLE.md §3b). */
|
||||
readonly over?: string;
|
||||
}
|
||||
|
||||
export interface BoardData {
|
||||
@@ -40,11 +42,12 @@ export interface BoardData {
|
||||
}
|
||||
|
||||
/** The board's data, or the manifest's problems. Nothing half-checked reaches the board. */
|
||||
export function boardData(m: Manifest, styleMarkdown: string): BoardData {
|
||||
export function boardData(raw: Manifest, styleMarkdown: string): BoardData {
|
||||
const style = stylePrompt(styleMarkdown);
|
||||
const checklist = reviewPoints(styleMarkdown);
|
||||
const problems = checkManifest(m, checklist.length);
|
||||
const problems = checkManifest(raw, checklist.length);
|
||||
if (problems.length > 0) throw new Error(`art/manifest.json:\n ${problems.join('\n ')}`);
|
||||
const m = expandLayers(raw);
|
||||
|
||||
const assets = m.assets.map((a): BoardAsset => {
|
||||
const base = {
|
||||
@@ -57,9 +60,11 @@ export function boardData(m: Manifest, styleMarkdown: string): BoardData {
|
||||
return {
|
||||
...base,
|
||||
grid: a.grid,
|
||||
// A layer's pictures have no prompts of their own: made one at a time, they would not line up.
|
||||
cells: (a.cells ?? []).map((c) => ({
|
||||
id: c.id, type: 'pose', width, height, background: a.background, prompt: cellPromptFor(a, c, m, style)
|
||||
}))
|
||||
id: c.id, type: 'pose', width, height, background: a.background, prompt: a.over ? '' : cellPromptFor(a, c, m, style)
|
||||
})),
|
||||
...(a.over ? { over: a.over } : {})
|
||||
};
|
||||
});
|
||||
return { generatedFrom: 'art/manifest.json, art/STYLE.md §1 and §7', checklist, assets };
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
/**
|
||||
* `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.
|
||||
* and every cell is written; for one cell made on its own, `<id>` is the cell. A layer
|
||||
* (STYLE.md §3b) is checked against its guide's cells, which must already be in art/final/.
|
||||
*/
|
||||
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
||||
import { existsSync, 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';
|
||||
import { Refused, acceptPicture, findTarget } from './accept.js';
|
||||
import { expandLayers, type Manifest } from './manifest.js';
|
||||
|
||||
const root = fileURLToPath(new URL('../../../', import.meta.url));
|
||||
const [id, file] = process.argv.slice(2);
|
||||
@@ -16,10 +17,16 @@ if (!id || !file) {
|
||||
process.exit(2);
|
||||
}
|
||||
|
||||
const manifest = JSON.parse(readFileSync(join(root, 'art/manifest.json'), 'utf8')) as Manifest;
|
||||
const manifest = expandLayers(JSON.parse(readFileSync(join(root, 'art/manifest.json'), 'utf8')) as Manifest);
|
||||
const dir = join(root, 'art/final');
|
||||
try {
|
||||
const { files, notes } = await acceptPicture(readFileSync(file), id, manifest);
|
||||
const dir = join(root, 'art/final');
|
||||
const over = findTarget(manifest, id).asset.over;
|
||||
const guide = new Map<string, Buffer>();
|
||||
for (const c of manifest.assets.find((a) => a.id === over)?.cells ?? []) {
|
||||
const path = join(dir, `${c.id}.webp`);
|
||||
if (existsSync(path)) guide.set(c.id, readFileSync(path));
|
||||
}
|
||||
const { files, notes } = await acceptPicture(readFileSync(file), id, manifest, over ? guide : undefined);
|
||||
mkdirSync(dir, { recursive: true });
|
||||
for (const f of files) {
|
||||
const path = join(dir, `${f.id}.webp`);
|
||||
|
||||
@@ -40,6 +40,42 @@ export interface Asset {
|
||||
readonly allow?: readonly string[];
|
||||
/** Indices into STYLE.md §7, the review points shown on its card. */
|
||||
readonly checks: readonly number[];
|
||||
/**
|
||||
* A layer of a layered character: the sprite sheet it is painted over, in register (STYLE.md §3b).
|
||||
* Its grid and cells are the guide's; it is made whole over the guide, never one picture at a time.
|
||||
*/
|
||||
readonly over?: string;
|
||||
/** For a layer: which part it is, and its place in the stack (0 at the back). */
|
||||
readonly part?: { readonly name: string; readonly stack: number };
|
||||
}
|
||||
|
||||
/** One part of a layered character: one layer sheet for each combination of its axes' values. */
|
||||
export interface LayerPart {
|
||||
readonly part: string;
|
||||
/** The choices (gardener.schema.json fields) this part is painted for, in id order. */
|
||||
readonly axes: readonly string[];
|
||||
/** Values that need no picture (no hat). */
|
||||
readonly skip?: readonly string[];
|
||||
/** The subject, with {axis} replaced by the words for each value. */
|
||||
readonly subject: string;
|
||||
}
|
||||
|
||||
/** A character drawn as stacked layers, all painted over one guide (STYLE.md §3b). */
|
||||
export interface Layered {
|
||||
readonly character: string;
|
||||
/** The guide: a sprite sheet of the whole first look in every pose, never shipped. */
|
||||
readonly over: string;
|
||||
readonly phase: number;
|
||||
/** The words each value stands for in a prompt, per axis. */
|
||||
readonly words: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
||||
/** The first looks: their layers come first, so a whole first look can be judged early. */
|
||||
readonly first: readonly Readonly<Record<string, string>>[];
|
||||
/** Back to front. */
|
||||
readonly parts: readonly LayerPart[];
|
||||
readonly include: readonly string[];
|
||||
readonly avoid: readonly string[];
|
||||
readonly allow?: readonly string[];
|
||||
readonly checks: readonly number[];
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
@@ -52,6 +88,58 @@ export interface Manifest {
|
||||
/** What no picture may show, appended to every prompt (STYLE.md §4). */
|
||||
readonly avoid: readonly string[];
|
||||
readonly assets: readonly Asset[];
|
||||
/** Characters drawn as layers; expandLayers writes each out as ordinary sprite sheets. */
|
||||
readonly layers?: readonly Layered[];
|
||||
}
|
||||
|
||||
/** Every combination of the axes' values, in the order the words list them. */
|
||||
function combinations(l: Layered, part: LayerPart): Record<string, string>[] {
|
||||
let out: Record<string, string>[] = [{}];
|
||||
for (const axis of part.axes) {
|
||||
const values = Object.keys(l.words[axis] ?? {}).filter((v) => !(part.skip ?? []).includes(v));
|
||||
out = out.flatMap((c) => values.map((v) => ({ ...c, [axis]: v })));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The id of a layer sheet: the character, the part, then each value (gardener-hair-braids-brown). */
|
||||
export const layerId = (character: string, part: string, values: readonly string[]): string => [character, part, ...values].join('-');
|
||||
|
||||
/**
|
||||
* The manifest with every layered character written out as ordinary sprite sheets, placed right
|
||||
* after their guide: the first looks' layers first, then the rest. Expanding twice changes nothing.
|
||||
*/
|
||||
export function expandLayers(m: Manifest): Manifest {
|
||||
if (!m.layers) return m;
|
||||
const assets = [...m.assets];
|
||||
for (const l of m.layers) {
|
||||
const guide = assets.find((a) => a.id === l.over);
|
||||
if (!guide) continue; // checkManifest names it
|
||||
const firsts: Asset[] = [], rest: Asset[] = [];
|
||||
l.parts.forEach((part, stack) => {
|
||||
for (const values of combinations(l, part)) {
|
||||
const id = layerId(l.character, part.part, part.axes.map((a) => values[a] ?? ''));
|
||||
const subject = part.subject.replace(/\{(\w+)\}/g, (whole, axis: string) => l.words[axis]?.[values[axis] ?? ''] ?? whole);
|
||||
const isFirst = l.first.some((f) => part.axes.every((a) => f[a] === values[a]));
|
||||
const pose = (cell: string): string => cell.replace(`${l.character}-`, '');
|
||||
const asset: Asset = {
|
||||
id, type: 'spritesheet', phase: l.phase, width: guide.width, height: guide.height, background: 'transparent',
|
||||
shipped: true, smallest: guide.smallest, character: l.character,
|
||||
usedBy: [`The ${l.character}'s ${part.part}, layer ${stack + 1} of ${l.parts.length} from the back, stacked with the others in the scene (STYLE.md §3b).`],
|
||||
purpose: `One layer of the ${l.character} (${part.part}${part.axes.length ? `: ${part.axes.map((a) => values[a]).join(', ')}` : ''}), in every pose of ${l.over}.`,
|
||||
subject, angle: guide.angle ?? '', grid: guide.grid ?? { cols: 1, rows: 1 },
|
||||
cells: (guide.cells ?? []).map((c) => ({ id: `${id}-${pose(c.id)}`, does: c.does })),
|
||||
include: l.include, avoid: l.avoid, checks: l.checks, over: l.over,
|
||||
part: { name: part.part, stack },
|
||||
...(l.allow ? { allow: l.allow } : {})
|
||||
};
|
||||
(isFirst ? firsts : rest).push(asset);
|
||||
}
|
||||
});
|
||||
assets.splice(assets.indexOf(guide) + 1, 0, ...firsts, ...rest);
|
||||
}
|
||||
const { layers: _expanded, ...plain } = m;
|
||||
return { ...plain, assets };
|
||||
}
|
||||
|
||||
/** The canvases image generators offer (STYLE.md §5). Anything else gets resized by the tool, unasked. */
|
||||
@@ -77,8 +165,25 @@ function textsOf(a: Asset): 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[] {
|
||||
export function checkManifest(raw: Manifest, checklistLength: number): string[] {
|
||||
const problems: string[] = [];
|
||||
for (const l of raw.layers ?? []) {
|
||||
const where = `layers of ${l.character}`;
|
||||
const guide = raw.assets.find((a) => a.id === l.over);
|
||||
if (!guide) problems.push(`${where}: the guide "${l.over}" is not in the manifest`);
|
||||
else if (guide.type !== 'spritesheet') problems.push(`${where}: the guide "${l.over}" is a ${guide.type}, not a sprite sheet`);
|
||||
else if (guide.shipped) problems.push(`${where}: the guide "${l.over}" is shipped; the app stacks the layers, so the guide never appears`);
|
||||
for (const part of l.parts) {
|
||||
for (const axis of part.axes) if (!l.words[axis]) problems.push(`${where}: part ${part.part} needs words for "${axis}"`);
|
||||
for (const [, axis = ''] of part.subject.matchAll(/\{(\w+)\}/g)) {
|
||||
if (!part.axes.includes(axis)) problems.push(`${where}: part ${part.part} says {${axis}} but is not painted per ${axis}`);
|
||||
}
|
||||
}
|
||||
for (const text of [...Object.values(l.words).flatMap((w) => Object.values(w)), ...l.parts.map((p) => p.subject)]) {
|
||||
for (const hit of findForbidden(text)) problems.push(`${where}: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
}
|
||||
const m = expandLayers(raw);
|
||||
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`);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* 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 { expandLayers, type Asset, type Manifest } from './manifest.js';
|
||||
import { cellBoxes, cellSize } from './prompt.js';
|
||||
|
||||
const C = {
|
||||
@@ -334,28 +334,103 @@ function planet(W: number, H: number, id: string): string {
|
||||
|
||||
type Pose = 'stand' | 'walk' | 'pour' | 'pull' | 'sweep' | 'carry' | 'reach' | 'sit';
|
||||
|
||||
/** The gardener's stand-in in a 120 × 200 box, feet on the bottom edge, facing right (STYLE.md §3b). */
|
||||
function gardener(pose: Pose, boy = false): string {
|
||||
const skin = '#cf9a72', hair = '#7a4b2e', cloth = C.leaf, apron = '#efe4d2';
|
||||
/** A gardener's look for a stand-in: the player's choices (gardener.schema.json), as colours and shapes. */
|
||||
interface StandLook {
|
||||
readonly boy: boolean;
|
||||
readonly skin: string;
|
||||
readonly hair: string;
|
||||
readonly hairColour: string;
|
||||
readonly clothes: string;
|
||||
readonly hat: string;
|
||||
}
|
||||
|
||||
/** The first look, the girl (STYLE.md §3b), in the colours the app's code drawing uses. */
|
||||
const FIRST: StandLook = { boy: false, skin: '#cf9a72', hair: 'braids', hairColour: '#7a4b2e', clothes: C.leaf, hat: 'straw-hat' };
|
||||
const APRON = '#efe4d2';
|
||||
/** The boy's first look: short hair, the same colours. */
|
||||
const BOY: StandLook = { ...FIRST, boy: true, hair: 'short' };
|
||||
|
||||
/** The parts a layered gardener is stacked from, back to front (STYLE.md §3b). */
|
||||
type Part = 'body' | 'clothes' | 'apron' | 'hair' | 'hat';
|
||||
|
||||
/** Hair in each style, in one colour; drawn round a head at (61, 66), r 20. */
|
||||
function hairOf(style: string, c: string): string {
|
||||
const cap = `<path d="M41 62 Q 61 36 81 62 Q 61 52 41 62 Z" fill="${c}" ${ink(2)}/>`;
|
||||
const strand = (d: string, w = 7): string => `<path d="${d}" stroke="${c}" stroke-width="${w}" fill="none" stroke-linecap="round"/>`;
|
||||
switch (style) {
|
||||
case 'curly': return [44, 52, 61, 70, 78].map((x, i) => `<circle cx="${x}" cy="${i % 2 ? 46 : 50}" r="9" fill="${c}" ${ink(2)}/>`).join('');
|
||||
case 'ponytail': return `${cap}${strand('M42 58 q -14 8 -10 30', 9)}`;
|
||||
case 'braids': return `${cap}${strand('M44 58 v 30')}${strand('M78 58 v 30')}`;
|
||||
case 'bob': return `${cap}${strand('M42 56 v 22', 9)}${strand('M80 56 v 22', 9)}`;
|
||||
case 'bun': return `${cap}<circle cx="38" cy="56" r="10" fill="${c}" ${ink(2)}/>`;
|
||||
default: return cap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The gardener's stand-in in a 120 × 200 box, feet on the bottom edge, facing right (STYLE.md §3b).
|
||||
* With `only`, just that part, in the same place, so the parts' stand-ins stack into the whole figure.
|
||||
*/
|
||||
function gardener(pose: Pose, look: StandLook = FIRST, only?: Part): string {
|
||||
const draw = (part: Part, svg: string): string => (only === undefined || only === part ? svg : '');
|
||||
const { skin, clothes: cloth, boy } = look;
|
||||
const lean = { stand: 0, walk: 4, pour: 10, pull: 28, sweep: 18, carry: 6, reach: 14, sit: 0 }[pose];
|
||||
const arm = { stand: 8, walk: -12, pour: -70, pull: -150, sweep: -40, carry: -80, reach: -95, sit: -30 }[pose];
|
||||
const legs = pose === 'sit'
|
||||
? `<path d="M52 160 h26 v34 M62 160 h26 v34" stroke="${boy ? cloth : skin}" stroke-width="12" fill="none" stroke-linecap="round"/>`
|
||||
: `<path d="M52 196 V 150 M70 196 V 150" stroke="${boy ? cloth : skin}" stroke-width="${boy ? 14 : 10}" stroke-linecap="round"/>`;
|
||||
const body = boy
|
||||
const legs = (colour: string, width: number): string => pose === 'sit'
|
||||
? `<path d="M52 160 h26 v34 M62 160 h26 v34" stroke="${colour}" stroke-width="${width + 2}" fill="none" stroke-linecap="round"/>`
|
||||
: `<path d="M52 196 V 150 M70 196 V 150" stroke="${colour}" stroke-width="${width}" stroke-linecap="round"/>`;
|
||||
const shirt = boy
|
||||
? `<path d="M44 92 Q 42 130 46 152 H 76 Q 80 130 78 92 Z" fill="${cloth}" ${ink(4)}/>`
|
||||
: `<path d="M44 92 Q 36 136 34 156 H 88 Q 86 136 78 92 Z" fill="${cloth}" ${ink(4)}/>`;
|
||||
const held = pose === 'pour' ? `<rect x="84" y="128" width="26" height="20" rx="6" fill="${C.leaf}" ${ink(3)} transform="rotate(30 97 138)"/>`
|
||||
: pose === 'carry' ? Array.from({ length: 4 }, (_, i) => `<path d="M${80 + i * 8} 150 v -40" stroke="${C.wood}" stroke-width="6" stroke-linecap="round"/>`).join('') : '';
|
||||
const braids = boy ? '' : `<path d="M44 58 v 30 M78 58 v 30" stroke="${hair}" stroke-width="7" stroke-linecap="round"/>`;
|
||||
return `${legs}<path d="M44 198 h18 M64 198 h18" ${ink(7)} stroke-linecap="round"/>
|
||||
<g transform="rotate(${lean} 61 150)">${body}<path d="M50 100 H 72 V 146 Q 61 152 50 146 Z" fill="${apron}" ${ink(3)}/>
|
||||
<path d="M44 98 l -8 40" stroke="${skin}" stroke-width="9" stroke-linecap="round"/>
|
||||
<g transform="rotate(${arm} 78 98)"><path d="M78 98 l 4 40" stroke="${skin}" stroke-width="9" stroke-linecap="round"/></g>${held}
|
||||
${braids}<circle cx="61" cy="66" r="20" fill="${skin}" ${ink(4)}/>
|
||||
<path d="M41 62 Q 61 36 81 62 Q 61 52 41 62 Z" fill="${hair}"/>
|
||||
<ellipse cx="61" cy="50" rx="34" ry="7" fill="#e6c98a" ${ink(3)}/><path d="M47 50 Q 61 28 75 50 Z" fill="#e6c98a" ${ink(3)}/>
|
||||
<circle cx="66" cy="66" r="2.5" fill="${C.ink}"/><circle cx="74" cy="66" r="2.5" fill="${C.ink}"/><path d="M66 76 q 4 3 8 0" fill="none" ${ink(2.5)}/></g>`;
|
||||
const hat = look.hat === 'cap'
|
||||
? `<path d="M43 56 Q 61 30 79 56 Z" fill="${APRON}" ${ink(3)}/><path d="M76 54 h 18" ${ink(5)} stroke-linecap="round"/>`
|
||||
: look.hat === 'straw-hat' ? `<ellipse cx="61" cy="50" rx="34" ry="7" fill="#e6c98a" ${ink(3)}/><path d="M47 50 Q 61 28 75 50 Z" fill="#e6c98a" ${ink(3)}/>` : '';
|
||||
return draw('body', legs(skin, 10)) + draw('clothes', boy ? legs(cloth, 14) : '') +
|
||||
draw('apron', `<path d="M44 198 h18 M64 198 h18" ${ink(7)} stroke-linecap="round"/>`) +
|
||||
`<g transform="rotate(${lean} 61 150)">` +
|
||||
draw('body', `<path d="M44 98 l -8 40" stroke="${skin}" stroke-width="9" stroke-linecap="round"/>
|
||||
<g transform="rotate(${arm} 78 98)"><path d="M78 98 l 4 40" stroke="${skin}" stroke-width="9" stroke-linecap="round"/></g>
|
||||
<circle cx="61" cy="66" r="20" fill="${skin}" ${ink(4)}/>
|
||||
<circle cx="66" cy="66" r="2.5" fill="${C.ink}"/><circle cx="74" cy="66" r="2.5" fill="${C.ink}"/><path d="M66 76 q 4 3 8 0" fill="none" ${ink(2.5)}/>`) +
|
||||
draw('clothes', shirt) +
|
||||
draw('apron', `<path d="M50 100 H 72 V 146 Q 61 152 50 146 Z" fill="${APRON}" ${ink(3)}/>`) +
|
||||
draw('hair', hairOf(look.hair, look.hairColour)) +
|
||||
draw('hat', hat) +
|
||||
'</g>';
|
||||
}
|
||||
|
||||
/** The first colour code in a prompt's words (the manifest names each colour once, for prompts and stand-ins). */
|
||||
const hexIn = (words: string | undefined, fallback: string): string => /#[0-9A-Fa-f]{6}/.exec(words ?? '')?.[0].toLowerCase() ?? fallback;
|
||||
|
||||
/** A layer sheet's stand-in look: the first look, changed by the values in its id. */
|
||||
function layerLook(a: Asset, m: Manifest): StandLook {
|
||||
const l = m.layers?.find((x) => x.over === a.over);
|
||||
const words = l?.words ?? {};
|
||||
const has = (axis: string): string | undefined => Object.keys(words[axis] ?? {}).find((v) => a.id.includes(`-${v}`));
|
||||
const presentation = has('presentation');
|
||||
const hair = ['curly', 'ponytail', 'braids', 'bob', 'bun', 'short'].find((s) => a.id.startsWith(`${a.character ?? ''}-hair-${s}-`));
|
||||
return {
|
||||
boy: presentation === 'boy',
|
||||
skin: hexIn(words['skin']?.[has('skin') ?? ''], FIRST.skin),
|
||||
hair: hair ?? FIRST.hair,
|
||||
hairColour: hexIn(words['hairColour']?.[a.id.slice(`${a.character ?? ''}-hair-${hair ?? ''}-`.length)], FIRST.hairColour),
|
||||
clothes: hexIn(words['clothes']?.[has('clothes') ?? ''], FIRST.clothes),
|
||||
hat: a.id.endsWith('-cap') ? 'cap' : 'straw-hat'
|
||||
};
|
||||
}
|
||||
|
||||
/** A layer sheet's stand-in: only its part, in every pose of the guide, where the guide has it. */
|
||||
function layerSheet(a: Asset, m: Manifest): string {
|
||||
const g = a.grid ?? { cols: 1, rows: 1 };
|
||||
const look = layerLook(a, m);
|
||||
const part = (a.part?.name ?? 'body') as Part;
|
||||
return cellBoxes(a.width, a.height, g.cols, g.rows)
|
||||
.map((b, i) => {
|
||||
const pose = (a.cells?.[i]?.id ?? '').split('-').at(-1) as Pose;
|
||||
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}">${fit(gardener(pose, look, part), 120, 200, w, h)}</svg>`;
|
||||
})
|
||||
.join('');
|
||||
}
|
||||
|
||||
const GARDENER_POSES: Record<string, Pose> = {
|
||||
@@ -404,7 +479,7 @@ function single(a: Asset): string {
|
||||
if (a.character === 'gardener') {
|
||||
// The girl along the top, the boy along the bottom; the side and back views are flipped stand-ins.
|
||||
const row = (boy: boolean, y: number): string =>
|
||||
[0, 1, 2, 3].map((i) => `<g transform="translate(${90 + i * 360} ${y}) scale(${i === 3 ? '-2' : '2'} 2) translate(${i === 3 ? -120 : 0} 0)">${gardener('stand', boy)}</g>`).join('');
|
||||
[0, 1, 2, 3].map((i) => `<g transform="translate(${90 + i * 360} ${y}) scale(${i === 3 ? '-2' : '2'} 2) translate(${i === 3 ? -120 : 0} 0)">${gardener('stand', boy ? BOY : FIRST)}</g>`).join('');
|
||||
return `<rect width="${W}" height="${H}" fill="${C.paper}"/>${row(false, 40)}${row(true, 560)}`;
|
||||
}
|
||||
if (a.character === 'fox') {
|
||||
@@ -497,10 +572,17 @@ const wrap = (id: string, W: number, H: number, body: string): string =>
|
||||
` <!-- 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> {
|
||||
/**
|
||||
* Every stand-in the board and the app may show: one per asset and one per sprite-sheet cell. A
|
||||
* layer (STYLE.md §3b) has one for its sheet only: its pictures are never made or shown alone.
|
||||
*/
|
||||
export function placeholders(raw: Manifest): Map<string, string> {
|
||||
const out = new Map<string, string>();
|
||||
for (const a of m.assets) {
|
||||
for (const a of expandLayers(raw).assets) {
|
||||
if (a.over) {
|
||||
out.set(a.id, wrap(a.id, a.width, a.height, layerSheet(a, raw)));
|
||||
continue;
|
||||
}
|
||||
out.set(a.id, wrap(a.id, a.width, a.height, single(a)));
|
||||
if (a.type === 'spritesheet') {
|
||||
const { width, height } = cellSize(a);
|
||||
|
||||
@@ -87,7 +87,8 @@ function characterOf(a: Asset, m: Manifest): { name: string; sheet: string; desc
|
||||
/** The reference pictures to attach when making `a`. */
|
||||
export function attachments(a: Asset, m: Manifest): string[] {
|
||||
const c = characterOf(a, m);
|
||||
return c && c.sheet !== a.id ? [c.sheet] : [];
|
||||
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. */
|
||||
@@ -125,7 +126,34 @@ export function promptFor(a: Asset, m: Manifest, style: string): string {
|
||||
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'}`;
|
||||
|
||||
Reference in New Issue
Block a user