[art-prep] ArtBoard: Build prompts, stand-ins and the art board from the manifest, and accept pictures into art/final
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.
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
/**
|
||||
* art/manifest.json: every picture the game needs, and the checks that keep the
|
||||
* list honest before a single prompt is written (docs/ART.md §2).
|
||||
*/
|
||||
import { findForbidden } from '@rosea/content';
|
||||
|
||||
export type Background = 'full' | 'transparent';
|
||||
export type AssetType = 'sheet' | 'spritesheet' | 'sprite' | 'layer' | 'icon';
|
||||
|
||||
export interface Cell {
|
||||
readonly id: string;
|
||||
/** What this one picture shows, finishing the sentence "Cell n: …". */
|
||||
readonly does: string;
|
||||
}
|
||||
|
||||
export interface Asset {
|
||||
readonly id: string;
|
||||
readonly type: AssetType;
|
||||
readonly width: number;
|
||||
readonly height: number;
|
||||
readonly background: Background;
|
||||
/** False for a reference that never appears in the app (a character sheet). */
|
||||
readonly shipped: boolean;
|
||||
/** The smallest size, in px across, the app ever shows it; null when it is only shown large. */
|
||||
readonly smallest: number | null;
|
||||
readonly character?: string;
|
||||
readonly usedBy: readonly string[];
|
||||
readonly purpose: string;
|
||||
readonly subject?: string;
|
||||
readonly setting?: string;
|
||||
readonly composition?: string;
|
||||
readonly angle?: string;
|
||||
readonly grid?: { readonly cols: number; readonly rows: number };
|
||||
readonly cells?: readonly Cell[];
|
||||
readonly include: readonly string[];
|
||||
readonly avoid: readonly string[];
|
||||
/** Indices into STYLE.md §7, the review points shown on its card. */
|
||||
readonly checks: readonly number[];
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
readonly sheet: string;
|
||||
readonly description: string;
|
||||
}
|
||||
|
||||
export interface Manifest {
|
||||
readonly characters: Readonly<Record<string, Character>>;
|
||||
/** What no picture may show, appended to every prompt (STYLE.md §4). */
|
||||
readonly avoid: readonly string[];
|
||||
readonly assets: readonly Asset[];
|
||||
}
|
||||
|
||||
/** The canvases image generators offer (STYLE.md §5). Anything else gets resized by the tool, unasked. */
|
||||
export const GENERATOR_SIZES: readonly (readonly [number, number])[] = [
|
||||
[1024, 1024],
|
||||
[1536, 1024],
|
||||
[1024, 1536]
|
||||
];
|
||||
|
||||
const ID = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
||||
const TYPES: readonly AssetType[] = ['sheet', 'spritesheet', 'sprite', 'layer', 'icon'];
|
||||
|
||||
/** Every text a prompt is built from, so the forbidden-names check reads all of it. */
|
||||
function textsOf(a: Asset): string[] {
|
||||
return [
|
||||
a.purpose, a.subject, a.setting, a.composition, a.angle,
|
||||
...a.usedBy, ...a.include, ...a.avoid,
|
||||
...(a.cells ?? []).flatMap((c) => [c.id, c.does])
|
||||
].filter((t): t is string => typeof t === '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[] {
|
||||
const problems: string[] = [];
|
||||
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`);
|
||||
if (seen.has(id)) problems.push(`${where}: id "${id}" is used twice; each picture needs its own`);
|
||||
seen.add(id);
|
||||
};
|
||||
|
||||
for (const [name, c] of Object.entries(m.characters)) {
|
||||
const sheet = m.assets.find((a) => a.id === c.sheet);
|
||||
if (!sheet) problems.push(`character ${name}: its sheet "${c.sheet}" is not in the manifest`);
|
||||
else if (sheet.type !== 'sheet') problems.push(`character ${name}: "${c.sheet}" is a ${sheet.type}, not a character sheet`);
|
||||
}
|
||||
|
||||
for (const a of m.assets) {
|
||||
claim(a.id, a.id);
|
||||
if (!TYPES.includes(a.type)) problems.push(`${a.id}: unknown type "${a.type}"`);
|
||||
if (!GENERATOR_SIZES.some(([w, h]) => w === a.width && h === a.height)) {
|
||||
problems.push(`${a.id}: ${a.width} × ${a.height} is not a size image generators offer (${GENERATOR_SIZES.map(([w, h]) => `${w} × ${h}`).join(', ')})`);
|
||||
}
|
||||
if (a.purpose.trim() === '') problems.push(`${a.id}: no purpose`);
|
||||
if (a.usedBy.length === 0) problems.push(`${a.id}: usedBy is empty; say where it appears`);
|
||||
if (a.character !== undefined && !(a.character in m.characters)) problems.push(`${a.id}: unknown character "${a.character}"`);
|
||||
if (a.type === 'sheet' && a.shipped) problems.push(`${a.id}: a character sheet is a reference and never shipped`);
|
||||
if ((a.type === 'layer' || a.type === 'sprite' || a.type === 'spritesheet') && a.background !== 'transparent') {
|
||||
problems.push(`${a.id}: a ${a.type} sits over other pictures, so its background must be transparent`);
|
||||
}
|
||||
if (a.type !== 'spritesheet' && (a.subject ?? '').trim() === '') problems.push(`${a.id}: no subject`);
|
||||
for (const i of a.checks) {
|
||||
if (!Number.isInteger(i) || i < 0 || i >= checklistLength) problems.push(`${a.id}: review point ${i} is not in STYLE.md §7`);
|
||||
}
|
||||
|
||||
if (a.type === 'spritesheet') {
|
||||
const g = a.grid;
|
||||
const cells = a.cells ?? [];
|
||||
if (!g) problems.push(`${a.id}: a sprite sheet needs a grid`);
|
||||
else {
|
||||
if (cells.length !== g.cols * g.rows) problems.push(`${a.id}: ${cells.length} cells for a ${g.cols} × ${g.rows} grid`);
|
||||
if (a.width % g.cols !== 0 || a.height % g.rows !== 0) problems.push(`${a.id}: ${a.width} × ${a.height} does not divide into ${g.cols} × ${g.rows} whole-pixel cells`);
|
||||
}
|
||||
if ((a.angle ?? '').trim() === '') problems.push(`${a.id}: a sprite sheet needs an angle, so every cell is drawn alike`);
|
||||
for (const c of cells) {
|
||||
claim(c.id, `${a.id} cell`);
|
||||
if (c.does.trim() === '') problems.push(`${a.id}: cell ${c.id} does not say what it shows`);
|
||||
}
|
||||
} else if (a.grid || a.cells) {
|
||||
problems.push(`${a.id}: only a sprite sheet has a grid and cells`);
|
||||
}
|
||||
|
||||
for (const text of textsOf(a)) {
|
||||
for (const hit of findForbidden(text)) problems.push(`${a.id}: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
}
|
||||
|
||||
for (const [name, c] of Object.entries(m.characters)) {
|
||||
for (const hit of findForbidden(c.description)) problems.push(`character ${name}: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
for (const text of m.avoid) {
|
||||
for (const hit of findForbidden(text)) problems.push(`avoid list: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
return problems;
|
||||
}
|
||||
Reference in New Issue
Block a user