[art] GardenerLayers: The gardener in layered parts, painted over one guide in register, checked on accept
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user