f24597dfdb
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.
64 lines
4.2 KiB
TypeScript
64 lines
4.2 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { checkManifest, type Asset, type Manifest } from '../src/manifest.js';
|
||
import { reviewPoints } from '../src/style.js';
|
||
import { clone, readManifest, readStyle } from './fixtures.js';
|
||
|
||
const POINTS = reviewPoints(readStyle()).length;
|
||
|
||
/** The real manifest with one asset changed. */
|
||
function withAsset(id: string, change: (a: Record<string, unknown>) => void): Manifest {
|
||
const m = clone(readManifest());
|
||
const a = m.assets.find((x) => x.id === id) as unknown as Record<string, unknown>;
|
||
change(a);
|
||
return m;
|
||
}
|
||
|
||
describe('art/manifest.json', () => {
|
||
it('passes every check', () => {
|
||
expect(checkManifest(readManifest(), POINTS)).toEqual([]);
|
||
});
|
||
|
||
it('asks for the Phase 1 pictures: the rose sheet first, then stages, care, moments, props, chair, four garden layers, the icon', () => {
|
||
const m = readManifest();
|
||
expect(m.assets[0]?.id).toBe('rose-sheet');
|
||
const pictures = m.assets.flatMap((a: Asset) => (a.cells ? a.cells.map((c) => c.id) : [a.id]));
|
||
expect(pictures).toHaveLength(25);
|
||
expect(pictures).toEqual(expect.arrayContaining(['rose-bud', 'rose-full-bloom', 'rose-waiting', 'petal-folded', 'garden-chair', 'garden-sunset', 'garden-night', 'app-icon']));
|
||
});
|
||
});
|
||
|
||
describe('checkManifest refuses', () => {
|
||
const cases: [string, Manifest, RegExp][] = [
|
||
['an id used twice', withAsset('garden-day', (a) => { a.id = 'garden-night'; }), /used twice/],
|
||
['a cell id that repeats an asset id', withAsset('care-props-sheet', (a) => { (a.cells as { id: string }[])[0]!.id = 'garden-chair'; }), /garden-chair.*used twice/],
|
||
['an id that is not lower-case words', withAsset('garden-day', (a) => { a.id = 'Garden_Day'; }), /lower-case/],
|
||
['a size no generator offers', withAsset('garden-chair', (a) => { a.width = 2048; }), /not a size image generators offer/],
|
||
['a grid whose cells do not match', withAsset('rose-stages-sheet', (a) => { a.grid = { cols: 3, rows: 1 }; }), /4 cells for a 3 × 1 grid/],
|
||
['a grid that does not divide the sheet', withAsset('care-props-sheet', (a) => { a.grid = { cols: 3, rows: 3 }; (a.cells as unknown[]).push({ id: 'x-1', does: 'x' }, { id: 'x-2', does: 'x' }, { id: 'x-3', does: 'x' }); }), /does not divide/],
|
||
['a grid on a single picture', withAsset('garden-chair', (a) => { a.grid = { cols: 1, rows: 1 }; }), /only a sprite sheet/],
|
||
['an unknown character', withAsset('app-icon', (a) => { a.character = 'fox'; }), /unknown character "fox"/],
|
||
['a shipped character sheet', withAsset('rose-sheet', (a) => { a.shipped = true; }), /never shipped/],
|
||
['a sprite on a full background', withAsset('garden-chair', (a) => { a.background = 'full'; }), /must be transparent/],
|
||
['a review point STYLE.md §7 does not have', withAsset('garden-chair', (a) => { a.checks = [0, POINTS]; }), new RegExp(`review point ${POINTS} is not in`)],
|
||
['a picture with no subject', withAsset('garden-chair', (a) => { delete a.subject; }), /no subject/],
|
||
['a picture nobody uses', withAsset('garden-chair', (a) => { a.usedBy = []; }), /usedBy is empty/],
|
||
['a name from the book in a prompt', withAsset('garden-chair', (a) => { a.subject = 'a chair for the Little Prince'; }), /"Little Prince" \(little-prince\)/],
|
||
['a medical word in a cell', withAsset('rose-care-sheet', (a) => { (a.cells as { does: string }[])[0]!.does = 'thirsty, waiting to be healed'; }), /"healed" \(medical\)/],
|
||
['the word the game never says, in the shared avoid list', (() => { const m = clone(readManifest()); (m.avoid as string[]).push('a lonely look'); return m; })(), /avoid list: "lonely"/]
|
||
];
|
||
|
||
for (const [what, manifest, message] of cases) {
|
||
it(what, () => {
|
||
expect(checkManifest(manifest, POINTS).join('\n')).toMatch(message);
|
||
});
|
||
}
|
||
|
||
it('a character whose sheet is missing or not a sheet', () => {
|
||
const m = clone(readManifest()) as { characters: Record<string, { sheet: string }> } & Manifest;
|
||
m.characters.rose!.sheet = 'garden-chair';
|
||
expect(checkManifest(m, POINTS).join('\n')).toMatch(/"garden-chair" is a sprite, not a character sheet/);
|
||
m.characters.rose!.sheet = 'nowhere';
|
||
expect(checkManifest(m, POINTS).join('\n')).toMatch(/"nowhere" is not in the manifest/);
|
||
});
|
||
});
|