365 lines
23 KiB
TypeScript
365 lines
23 KiB
TypeScript
/**
|
||
* 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',
|
||
fox: '#bc4a22',
|
||
cream: '#f3e3c8',
|
||
foxLeg: '#5a3a33',
|
||
strawberry: '#d2554e',
|
||
blueberry: '#5b6fa6',
|
||
raspberry: '#c2456a',
|
||
blackberry: '#3f2e4a',
|
||
hip: '#d0632e'
|
||
} 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;
|
||
}
|
||
|
||
interface FoxLook {
|
||
readonly pose: 'sit' | 'stand' | 'lie' | 'curl';
|
||
readonly eyes: 'open' | 'half' | 'closed';
|
||
/** Faces right instead of left. */
|
||
readonly right?: boolean;
|
||
/** The head turned back over the shoulder. */
|
||
readonly back?: boolean;
|
||
/** Seen from behind: no face. */
|
||
readonly behind?: boolean;
|
||
readonly petal?: boolean;
|
||
readonly fluffed?: boolean;
|
||
/** Degrees the head tilts. */
|
||
readonly tilt?: number;
|
||
}
|
||
|
||
/** The fox in a 300 × 240 box, facing left unless `right`, feet on the bottom edge. */
|
||
function fox(look: FoxLook): string {
|
||
const ink = `stroke="${C.ink}" stroke-width="4"`;
|
||
const leg = (x: number, y0: number, y1: number): string => `<path d="M${x} ${y0} V ${y1}" stroke="${C.foxLeg}" stroke-width="14" stroke-linecap="round"/>`;
|
||
const thick = look.fluffed ? 8 : 0;
|
||
const tail = (d: string): string =>
|
||
`<path d="${d}" fill="none" stroke="${C.ink}" stroke-width="${38 + thick}" stroke-linecap="round"/>` +
|
||
`<path d="${d}" fill="none" stroke="${C.fox}" stroke-width="${30 + thick}" stroke-linecap="round"/>` +
|
||
`<path d="${d}" fill="none" stroke="${C.foxLeg}" stroke-width="${32 + thick}" stroke-dasharray="6 26" opacity=".45"/>`;
|
||
const head = (x: number, y: number, r: number): string => {
|
||
const k = look.back ? -1 : 1;
|
||
const ears = [-0.55, 0.35].map((o) => `<path d="M${x + o * r * k - 12} ${y - r * 0.6} l12 -${r * 0.9} l12 ${r * 0.9}z" fill="${C.fox}" ${ink}/>`).join('');
|
||
if (look.behind) return ears + `<circle cx="${x}" cy="${y}" r="${r}" fill="${C.fox}" ${ink}/>`;
|
||
const eye = (ex: number): string =>
|
||
look.eyes === 'open'
|
||
? `<circle cx="${ex}" cy="${y - 4}" r="4" fill="${C.ink}"/>`
|
||
: `<path d="M${ex - 6} ${y - 4} q6 ${look.eyes === 'half' ? 4 : 6} 12 0" fill="${look.eyes === 'half' ? C.ink : 'none'}" stroke="${C.ink}" stroke-width="3" stroke-linecap="round"/>`;
|
||
const snout = x - k * r * 0.75;
|
||
return ears + `<g transform="rotate(${look.tilt ?? 0} ${x} ${y})"><circle cx="${x}" cy="${y}" r="${r}" fill="${C.fox}" ${ink}/>
|
||
<ellipse cx="${snout + k * 6}" cy="${y + r * 0.35}" rx="${r * 0.55}" ry="${r * 0.38}" fill="${C.cream}" ${ink}/>
|
||
<circle cx="${x - k * 12}" cy="${y - r * 0.45}" r="5" fill="${C.cream}"/><circle cx="${x + k * 10}" cy="${y - r * 0.45}" r="5" fill="${C.cream}"/>
|
||
${eye(x - k * 13)}${eye(x + k * 9)}<circle cx="${snout - k * 6}" cy="${y + r * 0.3}" r="5" fill="${C.ink}"/>
|
||
${look.petal ? `<ellipse cx="${snout - k * 10}" cy="${y + r * 0.75}" rx="16" ry="9" fill="${C.cream}" ${ink}/>` : ''}</g>`;
|
||
};
|
||
let body: string;
|
||
switch (look.pose) {
|
||
case 'sit':
|
||
body = tail('M185 215 Q 250 205 240 150') + `<ellipse cx="160" cy="150" rx="50" ry="64" fill="${C.fox}" ${ink}/>`
|
||
+ `<ellipse cx="148" cy="160" rx="24" ry="38" fill="${C.cream}"/>` + leg(140, 175, 225) + leg(168, 175, 225)
|
||
+ head(look.back ? 175 : 145, 72, 38);
|
||
break;
|
||
case 'stand':
|
||
body = tail('M235 120 Q 280 110 290 60') + leg(110, 140, 225) + leg(130, 140, 225) + leg(200, 140, 225) + leg(220, 140, 225)
|
||
+ `<ellipse cx="165" cy="128" rx="80" ry="38" fill="${C.fox}" ${ink}/>` + head(look.back ? 215 : 80, 98, 34);
|
||
break;
|
||
case 'lie':
|
||
body = tail('M250 205 Q 285 215 290 180') + `<ellipse cx="170" cy="192" rx="92" ry="30" fill="${C.fox}" ${ink}/>`
|
||
+ leg(70, 215, 222) + head(72, 178, 32);
|
||
break;
|
||
case 'curl':
|
||
body = `<circle cx="150" cy="160" r="66" fill="${C.fox}" ${ink}/>` + tail('M205 200 Q 170 235 110 205') + head(125, 168, 30);
|
||
break;
|
||
}
|
||
return look.right ? `<g transform="translate(300 0) scale(-1 1)">${body}</g>` : body;
|
||
}
|
||
|
||
const FOXES: Record<string, FoxLook> = {
|
||
'fox-watching': { pose: 'sit', eyes: 'open', back: true },
|
||
'fox-curious': { pose: 'stand', eyes: 'open', tilt: -14 },
|
||
'fox-sitting': { pose: 'sit', eyes: 'half' },
|
||
'fox-resting': { pose: 'lie', eyes: 'half' },
|
||
'fox-petted': { pose: 'sit', eyes: 'closed', tilt: -18 },
|
||
'fox-brushed': { pose: 'sit', eyes: 'half', fluffed: true, tilt: 8 },
|
||
'fox-eating': { pose: 'stand', eyes: 'closed', tilt: -30 },
|
||
'fox-asleep': { pose: 'curl', eyes: 'closed' },
|
||
'fox-trotting': { pose: 'stand', eyes: 'open' },
|
||
'fox-leading': { pose: 'stand', eyes: 'open', right: true, back: true },
|
||
'fox-carrying-petal': { pose: 'stand', eyes: 'half', petal: true },
|
||
'fox-visiting': { pose: 'sit', eyes: 'half', tilt: 16 }
|
||
};
|
||
|
||
/** 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"/>`
|
||
};
|
||
|
||
const berries = (fill: string, at: readonly (readonly [number, number])[], r: number, leaves = 1): string =>
|
||
Array.from({ length: leaves }, (_, i) => `<ellipse cx="${80 + i * 40}" cy="58" rx="30" ry="13" fill="${C.leaf}" stroke="${C.ink}" stroke-width="4" transform="rotate(${i ? 25 : -25} ${80 + i * 40} 58)"/>`).join('')
|
||
+ `<path d="M100 40 V 80" stroke="${C.moss}" stroke-width="5"/>`
|
||
+ at.map(([x, y]) => `<circle cx="${x}" cy="${y}" r="${r}" fill="${fill}" stroke="${C.ink}" stroke-width="4"/>`).join('');
|
||
|
||
const bush = (extra: string): string =>
|
||
[[60, 120, 50], [140, 120, 50], [100, 80, 56], [100, 140, 46]].map(([x, y, r]) => `<circle cx="${x}" cy="${y}" r="${r}" fill="${C.leaf}" stroke="${C.ink}" stroke-width="4"/>`).join('')
|
||
+ `<path d="M70 70 q30 -14 60 0 M50 120 q20 -10 40 0 M115 125 q20 -10 40 0" fill="none" stroke="${C.moss}" stroke-width="4"/>` + extra;
|
||
|
||
/** The fox's food and the bush, each in a 200 × 200 box like PROPS. */
|
||
const MORE_PROPS: Record<string, string> = {
|
||
'wild-strawberries': berries(C.strawberry, [[70, 120], [110, 140], [140, 105]], 22, 2),
|
||
blueberries: berries(C.blueberry, [[70, 120], [100, 140], [130, 120], [85, 95], [118, 95]], 16, 2),
|
||
raspberries: berries(C.raspberry, [[72, 120], [110, 138], [138, 108]], 22),
|
||
blackberries: berries(C.blackberry, [[72, 120], [110, 138], [138, 108]], 22),
|
||
'rose-hips': `<circle cx="100" cy="115" r="80" fill="${C.lamp}" opacity=".3"/><path d="M100 30 V 70 M100 70 L 70 90 M100 70 L 130 90" stroke="${C.moss}" stroke-width="5" fill="none"/>`
|
||
+ [[70, 125], [130, 125]].map(([x, y]) => `<ellipse cx="${x}" cy="${y}" rx="24" ry="34" fill="${C.hip}" stroke="${C.ink}" stroke-width="4"/><path d="M${(x ?? 0) - 8} ${(y ?? 0) + 34} l8 10 l8 -10" fill="${C.foxLeg}"/>`).join(''),
|
||
'leaf-plate': `<path d="M20 110 Q 100 10 185 100 Q 100 190 20 110z" fill="${C.leaf}" stroke="${C.ink}" stroke-width="5"/><path d="M20 110 Q 100 100 185 100" fill="none" stroke="${C.moss}" stroke-width="5"/>`,
|
||
'bush-resting': bush(''),
|
||
'bush-flowering': bush([[55, 100], [100, 60], [145, 105], [90, 135], [125, 150]].map(([x, y]) => `<circle cx="${x}" cy="${y}" r="9" fill="${C.paper}" stroke="${C.ink}" stroke-width="3"/><circle cx="${x}" cy="${y}" r="3" fill="${C.amber}"/>`).join('')),
|
||
'bush-ripe': bush([[60, 105], [138, 108], [100, 70]].map(([x, y]) => `<ellipse cx="${x}" cy="${y}" rx="20" ry="15" fill="${C.lamp}" stroke="${C.moss}" stroke-width="3"/>`).join('')),
|
||
'fox-brush': `<path d="M30 110 Q 30 70 100 70 Q 170 70 170 110z" fill="${C.wood}" stroke="${C.ink}" stroke-width="5"/>`
|
||
+ Array.from({ length: 12 }, (_, i) => `<path d="M${40 + i * 11} 112 v26" stroke="${C.cream}" stroke-width="6" stroke-linecap="round"/>`).join('')
|
||
};
|
||
|
||
const meadow = (path: string): string =>
|
||
`<ellipse cx="100" cy="200" rx="92" ry="190" fill="${C.meadow}" stroke="${C.ink}" stroke-width="3" stroke-dasharray="10 8"/>${path}`;
|
||
const lantern = (lit: boolean): string =>
|
||
(lit ? `<circle cx="140" cy="170" r="60" fill="${C.lamp}" opacity=".45"/>` : '')
|
||
+ `<path d="M60 390 V 80 Q 60 40 100 40 Q 140 40 140 80 V 110" fill="none" stroke="${C.wood}" stroke-width="14" stroke-linecap="round"/>`
|
||
+ `<rect x="115" y="130" width="50" height="72" rx="8" fill="${lit ? C.lamp : '#e8eef0'}" stroke="${C.ink}" stroke-width="5"/>`
|
||
+ `<path d="M115 130 l25 -18 l25 18" fill="${C.foxLeg}" stroke="${C.ink}" stroke-width="4"/>`
|
||
+ `<rect x="133" y="160" width="14" height="30" fill="${C.paper}" stroke="${C.ink}" stroke-width="3"/>`
|
||
+ (lit ? `<path d="M140 160 q-8 -12 0 -22 q8 10 0 22z" fill="${C.amber}" stroke="${C.ink}" stroke-width="2"/>` : '');
|
||
|
||
/** Tall things, each in a 200 × 400 box: the path stretches and the lanterns. */
|
||
const TALL: Record<string, string> = {
|
||
'path-prints': meadow([340, 290, 240, 190, 140, 95, 55].map((y, i) => `<ellipse cx="${100 + (i % 2 ? 12 : -12) * (1 - i / 9)}" cy="${y}" rx="${9 - i}" ry="${7 - i * 0.7}" fill="${C.soil}"/>`).join('')),
|
||
'path-trail': meadow(`<path d="M92 385 Q 120 260 96 160 T 100 15" fill="none" stroke="#c8d8a8" stroke-width="22" stroke-linecap="round"/><path d="M92 385 Q 120 260 96 160 T 100 15" fill="none" stroke="${C.soil}" stroke-width="5" stroke-dasharray="4 18"/>`),
|
||
'path-road': meadow(`<path d="M60 388 Q 110 260 88 160 T 92 15 L 108 15 Q 120 120 112 170 T 140 388z" fill="${C.soil}" stroke="${C.ink}" stroke-width="4"/>`
|
||
+ [[52, 360], [148, 360], [70, 260], [130, 255], [80, 160], [118, 150], [88, 70], [110, 65]].map(([x, y]) => `<circle cx="${x}" cy="${y}" r="7" fill="#c9bcae" stroke="${C.ink}" stroke-width="2"/>`).join('')),
|
||
'lantern-unlit': lantern(false),
|
||
'lantern-lit': lantern(true)
|
||
};
|
||
|
||
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': {
|
||
if (a.character === 'fox') {
|
||
const views: FoxLook[] = [{ pose: 'sit', eyes: 'half' }, { pose: 'stand', eyes: 'half' }, { pose: 'stand', eyes: 'half', tilt: -8 }, { pose: 'sit', eyes: 'half', behind: true }];
|
||
const figures = views.map((l, i) => `<g transform="translate(${30 + i * 375} 60) scale(1.15)">${fox(l)}</g>`).join('');
|
||
const heads: FoxLook[] = [{ pose: 'sit', eyes: 'half' }, { pose: 'sit', eyes: 'open', tilt: -14 }, { pose: 'sit', eyes: 'closed' }];
|
||
// Close-ups: only the head, cropped by a nested viewBox.
|
||
const close = heads.map((l, i) => `<svg x="${200 + i * 400}" y="620" width="320" height="320" viewBox="90 10 120 120">${fox(l)}</svg>`).join('');
|
||
return `<rect width="${W}" height="${H}" fill="${C.paper}"/>${figures}${close}`;
|
||
}
|
||
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(drawing(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);
|
||
}
|
||
}
|
||
|
||
/** A stand-in drawing by id. A picture with none fails the build rather than showing an empty box. */
|
||
function drawing(from: Record<string, string>, id: string): string {
|
||
const d = from[id];
|
||
if (d === undefined) throw new Error(`tools/art-prep/src/placeholders.ts has no stand-in drawing for "${id}"`);
|
||
return d;
|
||
}
|
||
|
||
/** 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);
|
||
const pose = FOXES[id];
|
||
if (pose) return fit(fox(pose), 300, 240, W, H);
|
||
if (id in TALL) return fit(drawing(TALL, id), 200, 400, W, H);
|
||
return fit(drawing({ ...PROPS, ...MORE_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;
|
||
}
|