[art] GardenerLayers: The gardener in layered parts, painted over one guide in register, checked on accept

This commit is contained in:
2026-11-17 21:53:22 +01:00
parent 0b72ae05a2
commit 229cced136
82 changed files with 1026 additions and 83 deletions
+7 -4
View File
@@ -1,6 +1,7 @@
import { readFileSync, readdirSync } from 'node:fs';
import { describe, expect, it } from 'vitest';
import { boardData } from '../src/board.js';
import { expandLayers } from '../src/manifest.js';
import { placeholders } from '../src/placeholders.js';
import { clone, readManifest, readStyle, root } from './fixtures.js';
@@ -19,7 +20,7 @@ describe('the board data', () => {
for (const c of a.cells ?? []) expect(c).toMatchObject({ id: expect.any(String), width: expect.any(Number), height: expect.any(Number), prompt: expect.any(String) });
}
}
expect(data.checklist).toHaveLength(12);
expect(data.checklist).toHaveLength(13);
expect(data.assets.every((a) => Number.isInteger(a.phase))).toBe(true);
});
@@ -44,10 +45,12 @@ describe('the board data', () => {
});
describe('the stand-ins', () => {
it('one for every picture and every cell, at its own size', () => {
const ids = manifest.assets.flatMap((a) => [a.id, ...(a.cells ?? []).map((c) => c.id)]);
it('one for every picture and every cell, at its own size; a layer has one for its sheet only', () => {
const all = expandLayers(manifest).assets;
const ids = all.flatMap((a) => (a.over ? [a.id] : [a.id, ...(a.cells ?? []).map((c) => c.id)]));
expect([...stand.keys()].sort()).toEqual([...ids].sort());
for (const a of manifest.assets) expect(stand.get(a.id)).toContain(`viewBox="0 0 ${a.width} ${a.height}"`);
expect(stand.has('gardener-hair-braids-brown-pour')).toBe(false);
for (const a of all) expect(stand.get(a.id)).toContain(`viewBox="0 0 ${a.width} ${a.height}"`);
expect(stand.get('rose-bud')).toContain('viewBox="0 0 384 1024"');
expect(stand.get('watering-can')).toContain('viewBox="0 0 512 512"');
});
+175
View File
@@ -0,0 +1,175 @@
import { readFileSync } from 'node:fs';
import { GARDENER_OPTIONS } from '@rosea/schema';
import sharp from 'sharp';
import { describe, expect, it } from 'vitest';
import { Refused, acceptPicture, type Guide } from '../src/accept.js';
import { boardData } from '../src/board.js';
import { checkManifest, expandLayers, layerId, type Layered, type Manifest } from '../src/manifest.js';
import { placeholders } from '../src/placeholders.js';
import { reviewPoints } from '../src/style.js';
import { clone, readManifest, readStyle, root } from './fixtures.js';
const raw = readManifest();
const m = expandLayers(raw);
const POINTS = reviewPoints(readStyle()).length;
const layers = m.assets.filter((a) => a.over === 'gardener-poses-sheet');
const ids = new Set(layers.map((a) => a.id));
describe('the gardener in layered parts (STYLE.md §3b, decided by Mark 2026-11-17)', () => {
it('every look the player can choose can be stacked: a layer for every value of every choice', () => {
for (const skin of GARDENER_OPTIONS.skin) expect(ids.has(layerId('gardener', 'body', [skin])), skin).toBe(true);
for (const p of GARDENER_OPTIONS.presentation) {
for (const c of GARDENER_OPTIONS.clothes) expect(ids.has(layerId('gardener', 'clothes', [p, c])), `${p} ${c}`).toBe(true);
}
expect(ids.has('gardener-apron')).toBe(true);
for (const h of GARDENER_OPTIONS.hair) {
for (const c of GARDENER_OPTIONS.hairColour) expect(ids.has(layerId('gardener', 'hair', [h, c])), `${h} ${c}`).toBe(true);
}
for (const hat of GARDENER_OPTIONS.hat) expect(ids.has(layerId('gardener', 'hat', [hat]))).toBe(hat !== 'none');
expect(layers).toHaveLength(6 + 10 + 1 + 36 + 2);
});
it("the words name no value the app does not offer, so no layer is painted for nothing", () => {
const words = raw.layers?.[0]?.words ?? {};
for (const [axis, values] of Object.entries(words)) {
expect(Object.keys(values).sort(), axis).toEqual([...(GARDENER_OPTIONS[axis as keyof typeof GARDENER_OPTIONS] ?? [])].sort());
}
});
it("the colours in the prompts are the app's own (Gardener.svelte), so a painted look matches the one chosen", () => {
const svelte = readFileSync(`${root}packages/ui/src/scene/Gardener.svelte`, 'utf8');
const words = raw.layers?.[0]?.words ?? {};
for (const axis of ['skin', 'hairColour', 'clothes']) {
for (const [value, text] of Object.entries(words[axis] ?? {})) {
const hex = /#[0-9A-F]{6}/i.exec(text)?.[0].toLowerCase();
expect(svelte, `${axis} ${value}`).toMatch(new RegExp(`'?${value}'?: '${hex}'`));
}
}
});
it('come right after the guide, the seven of the two first looks first, then back to front', () => {
const at = m.assets.findIndex((a) => a.id === 'gardener-poses-sheet');
expect(m.assets.slice(at + 1, at + 8).map((a) => a.id)).toEqual([
'gardener-body-skin-3', 'gardener-clothes-girl-sage', 'gardener-clothes-boy-sage', 'gardener-apron',
'gardener-hair-short-brown', 'gardener-hair-braids-brown', 'gardener-hat-straw-hat'
]);
const back = (from: number): number[] => layers.slice(from).map((a) => a.part?.stack ?? -1);
for (const run of [back(0).slice(0, 7), back(7)]) expect(run).toEqual([...run].sort((x, y) => x - y));
expect(layers.find((a) => a.id === 'gardener-hat-cap')?.part).toEqual({ name: 'hat', stack: 4 });
});
it("have the guide's grid and poses, each picture named after its pose; the guide is never shipped", () => {
const guide = m.assets.find((a) => a.id === 'gardener-poses-sheet');
expect(guide?.shipped).toBe(false);
const hair = m.assets.find((a) => a.id === 'gardener-hair-curly-red');
expect(hair?.grid).toEqual(guide?.grid);
expect(hair?.cells?.map((c) => c.id)).toEqual((guide?.cells ?? []).map((c) => c.id.replace('gardener-', 'gardener-hair-curly-red-')));
expect(hair?.cells?.map((c) => c.does)).toEqual(guide?.cells?.map((c) => c.does));
});
it('expanding twice changes nothing', () => {
expect(expandLayers(m)).toEqual(m);
});
it("a layer's prompt attaches the character sheet and the guide, names only its part, and has no one-at-a-time prompts", () => {
const board = boardData(raw, readStyle());
const hair = board.assets.find((a) => a.id === 'gardener-hair-bun-auburn');
expect(hair?.attach).toEqual(['gardener-sheet', 'gardener-poses-sheet']);
expect(hair?.over).toBe('gardener-poses-sheet');
expect(hair?.prompt).toContain('Guide: attach the image gardener-poses-sheet and paint over it.');
expect(hair?.prompt).toContain("Part: only the gardener's hair: hair in a small round bun at the back of the head, auburn (#9A4A2A)");
expect(hair?.prompt).toContain('Avoid: any part of the gardener other than the one named');
// The character's whole first look would contradict a part: it is not in a layer's prompt.
expect(hair?.prompt).not.toContain('two braids, a wide straw hat');
expect(hair?.cells?.every((c) => c.prompt === '')).toBe(true);
expect(board.assets.find((a) => a.id === 'gardener-poses-sheet')?.cells?.every((c) => c.prompt !== '')).toBe(true);
});
it("each layer's stand-in draws its part only, in its own colour", () => {
const stand = placeholders(raw);
expect(stand.get('gardener-body-skin-6')).toContain('#553422');
expect(stand.get('gardener-body-skin-6')).not.toContain('#e6c98a'); // no straw hat in the body
expect(stand.get('gardener-hair-short-fair')).toContain('#d9b26a');
expect(stand.get('gardener-hair-short-fair')).not.toContain('#cf9a72'); // no skin in the hair
expect(stand.get('gardener-clothes-boy-dusk')).toContain('#5b6fa6');
expect(stand.get('gardener-hat-straw-hat')).toContain('#e6c98a');
});
});
describe('checkManifest refuses layers that cannot work', () => {
const broken = (change: (l: { -readonly [K in keyof Layered]: Layered[K] }, m: Manifest) => void): string => {
const copy = clone(raw);
change((copy.layers as Layered[])[0] as never, copy);
return checkManifest(copy, POINTS).join('\n');
};
it('a shipped guide: the app stacks the layers, so the guide must never appear', () => {
expect(broken((_, c) => { (c.assets.find((a) => a.id === 'gardener-poses-sheet') as { shipped: boolean }).shipped = true; })).toMatch(/guide "gardener-poses-sheet" is shipped/);
});
it('a guide that is missing or not a sprite sheet', () => {
expect(broken((l) => { l.over = 'nowhere'; })).toMatch(/guide "nowhere" is not in the manifest/);
expect(broken((l) => { l.over = 'gardener-sheet'; })).toMatch(/guide "gardener-sheet" is a sheet, not a sprite sheet/);
});
it('a part that names a choice it is not painted for, or a choice with no words', () => {
expect(broken((l) => { (l.parts[2] as { subject: string }).subject = 'only the apron, in {clothes}'; })).toMatch(/part apron says \{clothes\} but is not painted per clothes/);
expect(broken((l) => { delete (l.words as Record<string, unknown>)['hat']; })).toMatch(/part hat needs words for "hat"/);
});
it("a forbidden word in a layer's words", () => {
expect(broken((l) => { ((l.words as Record<string, Record<string, string>>)['hat'] ?? {})['cap'] = 'a cap to heal the heart'; })).toMatch(/"heal" \(medical\)/);
});
});
describe('art:accept and a layer (in register with the guide)', () => {
const W = 1536, H = 1024, COLS = 4, ROWS = 2;
const cw = W / COLS, ch = H / ROWS;
/** One rectangle per cell, at the given share of the cell: a figure, or a part of one. */
async function sheet(box: { x: number; y: number; w: number; h: number }): Promise<Buffer> {
const rects = Array.from({ length: COLS * ROWS }, (_, i) =>
`<rect x="${(i % COLS) * cw + box.x * cw}" y="${Math.floor(i / COLS) * ch + box.y * ch}" width="${box.w * cw}" height="${box.h * ch}" fill="#7fa07a"/>`).join('');
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${W}" height="${H}">${rects}</svg>`;
return sharp({ create: { width: W, height: H, channels: 4, background: { r: 0, g: 0, b: 0, alpha: 0 } } }).composite([{ input: Buffer.from(svg) }]).png().toBuffer();
}
const FIGURE = { x: 0.3, y: 0.15, w: 0.4, h: 0.7 };
let guide: Guide | undefined;
async function theGuide(): Promise<Guide> {
if (!guide) {
const { files } = await acceptPicture(await sheet(FIGURE), 'gardener-poses-sheet', m);
guide = new Map(files.map((f) => [f.id, f.data]));
}
return guide;
}
const refusal = async (p: Promise<unknown>): Promise<string> => {
try {
await p;
} catch (e) {
if (e instanceof Refused) return e.message;
throw e;
}
throw new Error('expected a refusal');
};
it('a part lying on the guide\'s figure is accepted and cut into its eight pictures', async () => {
const { files } = await acceptPicture(await sheet({ x: 0.33, y: 0.15, w: 0.34, h: 0.2 }), 'gardener-hair-braids-brown', m, await theGuide());
expect(files.map((f) => f.id)).toEqual((m.assets.find((a) => a.id === 'gardener-hair-braids-brown')?.cells ?? []).map((c) => c.id));
});
it('a part a little fuller than the guide (a wide hat) is still in register', async () => {
await acceptPicture(await sheet({ x: 0.25, y: 0.12, w: 0.5, h: 0.12 }), 'gardener-hat-straw-hat', m, await theGuide());
});
it('a part painted somewhere else is refused, naming the pictures', async () => {
const message = await refusal(acceptPicture(await sheet({ x: 0.75, y: 0.15, w: 0.2, h: 0.2 }), 'gardener-hair-braids-brown', m, await theGuide()));
expect(message).toMatch(/not in register with gardener-poses-sheet in gardener-hair-braids-brown-stand \(\d+ % of the cell/);
});
it('before the guide is accepted, a layer is refused', async () => {
expect(await refusal(acceptPicture(await sheet(FIGURE), 'gardener-apron', m))).toMatch(/guide gardener-poses-sheet is not in art\/final\/ yet/);
});
it('one picture of a layer, made on its own, is refused: it would not line up', async () => {
expect(await refusal(acceptPicture(await sheet(FIGURE), 'gardener-apron-pour', m, await theGuide()))).toMatch(/never one picture at a time/);
});
});
+11 -7
View File
@@ -1,13 +1,15 @@
import { describe, expect, it } from 'vitest';
import { findForbidden } from '@rosea/content';
import { boardData } from '../src/board.js';
import { expandLayers } from '../src/manifest.js';
import { cellBoxes, cutLines, soloCanvas } from '../src/prompt.js';
import { reviewPoints, stylePrompt } from '../src/style.js';
import { clone, readManifest, readStyle } from './fixtures.js';
const style = stylePrompt(readStyle());
const data = boardData(readManifest(), readStyle());
const allPrompts = data.assets.flatMap((a) => [a.prompt, ...(a.cells ?? []).map((c) => c.prompt)]);
// A layer's pictures have no prompts of their own (STYLE.md §3b): their prompt is ''.
const allPrompts = data.assets.flatMap((a) => [a.prompt, ...(a.cells ?? []).map((c) => c.prompt)]).filter((p) => p !== '');
describe('STYLE.md', () => {
it('§1 is the quoted system prompt, line breaks kept and the markers gone', () => {
@@ -23,9 +25,10 @@ describe('STYLE.md', () => {
}
});
it('§7 has the twelve review points, a point split over two lines read as one', () => {
it('§7 has the thirteen review points, a point split over two lines read as one', () => {
const points = reviewPoints(readStyle());
expect(points).toHaveLength(12);
expect(points).toHaveLength(13);
expect(points[12]).toBe('A gardener layer holds only its part, in register with the guide: stacked with the other layers of a look, it makes one child, with nothing doubled, missing or shifted.');
expect(points[8]).toBe("It reads as one young red-orange fox with a cream mask and a ringed tail, shy and gentle, and nothing like the book's sandy, long-eared fox.");
expect(points[3]).toBe('Nothing from the book: no glass dome, screen, tiny planet, desert, child or scarf, and no look of its drawings.');
});
@@ -37,18 +40,19 @@ describe('STYLE.md', () => {
});
describe('the prompts', () => {
it('every one starts with STYLE.md §1 word for word, then says what to make: 40 cards and 74 one-at-a-time prompts', () => {
expect(allPrompts).toHaveLength(40 + 74);
it('every one starts with STYLE.md §1 word for word, then says what to make: 95 cards (55 of them gardener layers) and 74 one-at-a-time prompts', () => {
expect(data.assets.filter((a) => a.over)).toHaveLength(55);
expect(allPrompts).toHaveLength(95 + 74);
for (const p of allPrompts) expect(p.startsWith(style + '\n\nMake: ')).toBe(true);
});
it('every one ends with the shared avoid list and its board id', () => {
const m = readManifest();
const m = expandLayers(readManifest());
for (const a of data.assets) {
const allowed = m.assets.find((x) => x.id === a.id)?.allow ?? [];
expect(a.prompt).toContain(m.avoid.filter((l) => !allowed.includes(l)).join('; '));
expect(a.prompt.endsWith(`\nBoard id: ${a.id}`)).toBe(true);
for (const c of a.cells ?? []) expect(c.prompt.endsWith(`\nBoard id: ${c.id} (one picture of ${a.id})`)).toBe(true);
for (const c of (a.cells ?? []).filter((x) => x.prompt !== '')) expect(c.prompt.endsWith(`\nBoard id: ${c.id} (one picture of ${a.id})`)).toBe(true);
}
});