[art] GardenerLayers: The gardener in layered parts, painted over one guide in register, checked on accept
This commit is contained in:
@@ -40,6 +40,42 @@ export interface Asset {
|
||||
readonly allow?: readonly string[];
|
||||
/** Indices into STYLE.md §7, the review points shown on its card. */
|
||||
readonly checks: readonly number[];
|
||||
/**
|
||||
* A layer of a layered character: the sprite sheet it is painted over, in register (STYLE.md §3b).
|
||||
* Its grid and cells are the guide's; it is made whole over the guide, never one picture at a time.
|
||||
*/
|
||||
readonly over?: string;
|
||||
/** For a layer: which part it is, and its place in the stack (0 at the back). */
|
||||
readonly part?: { readonly name: string; readonly stack: number };
|
||||
}
|
||||
|
||||
/** One part of a layered character: one layer sheet for each combination of its axes' values. */
|
||||
export interface LayerPart {
|
||||
readonly part: string;
|
||||
/** The choices (gardener.schema.json fields) this part is painted for, in id order. */
|
||||
readonly axes: readonly string[];
|
||||
/** Values that need no picture (no hat). */
|
||||
readonly skip?: readonly string[];
|
||||
/** The subject, with {axis} replaced by the words for each value. */
|
||||
readonly subject: string;
|
||||
}
|
||||
|
||||
/** A character drawn as stacked layers, all painted over one guide (STYLE.md §3b). */
|
||||
export interface Layered {
|
||||
readonly character: string;
|
||||
/** The guide: a sprite sheet of the whole first look in every pose, never shipped. */
|
||||
readonly over: string;
|
||||
readonly phase: number;
|
||||
/** The words each value stands for in a prompt, per axis. */
|
||||
readonly words: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
||||
/** The first looks: their layers come first, so a whole first look can be judged early. */
|
||||
readonly first: readonly Readonly<Record<string, string>>[];
|
||||
/** Back to front. */
|
||||
readonly parts: readonly LayerPart[];
|
||||
readonly include: readonly string[];
|
||||
readonly avoid: readonly string[];
|
||||
readonly allow?: readonly string[];
|
||||
readonly checks: readonly number[];
|
||||
}
|
||||
|
||||
export interface Character {
|
||||
@@ -52,6 +88,58 @@ export interface Manifest {
|
||||
/** What no picture may show, appended to every prompt (STYLE.md §4). */
|
||||
readonly avoid: readonly string[];
|
||||
readonly assets: readonly Asset[];
|
||||
/** Characters drawn as layers; expandLayers writes each out as ordinary sprite sheets. */
|
||||
readonly layers?: readonly Layered[];
|
||||
}
|
||||
|
||||
/** Every combination of the axes' values, in the order the words list them. */
|
||||
function combinations(l: Layered, part: LayerPart): Record<string, string>[] {
|
||||
let out: Record<string, string>[] = [{}];
|
||||
for (const axis of part.axes) {
|
||||
const values = Object.keys(l.words[axis] ?? {}).filter((v) => !(part.skip ?? []).includes(v));
|
||||
out = out.flatMap((c) => values.map((v) => ({ ...c, [axis]: v })));
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The id of a layer sheet: the character, the part, then each value (gardener-hair-braids-brown). */
|
||||
export const layerId = (character: string, part: string, values: readonly string[]): string => [character, part, ...values].join('-');
|
||||
|
||||
/**
|
||||
* The manifest with every layered character written out as ordinary sprite sheets, placed right
|
||||
* after their guide: the first looks' layers first, then the rest. Expanding twice changes nothing.
|
||||
*/
|
||||
export function expandLayers(m: Manifest): Manifest {
|
||||
if (!m.layers) return m;
|
||||
const assets = [...m.assets];
|
||||
for (const l of m.layers) {
|
||||
const guide = assets.find((a) => a.id === l.over);
|
||||
if (!guide) continue; // checkManifest names it
|
||||
const firsts: Asset[] = [], rest: Asset[] = [];
|
||||
l.parts.forEach((part, stack) => {
|
||||
for (const values of combinations(l, part)) {
|
||||
const id = layerId(l.character, part.part, part.axes.map((a) => values[a] ?? ''));
|
||||
const subject = part.subject.replace(/\{(\w+)\}/g, (whole, axis: string) => l.words[axis]?.[values[axis] ?? ''] ?? whole);
|
||||
const isFirst = l.first.some((f) => part.axes.every((a) => f[a] === values[a]));
|
||||
const pose = (cell: string): string => cell.replace(`${l.character}-`, '');
|
||||
const asset: Asset = {
|
||||
id, type: 'spritesheet', phase: l.phase, width: guide.width, height: guide.height, background: 'transparent',
|
||||
shipped: true, smallest: guide.smallest, character: l.character,
|
||||
usedBy: [`The ${l.character}'s ${part.part}, layer ${stack + 1} of ${l.parts.length} from the back, stacked with the others in the scene (STYLE.md §3b).`],
|
||||
purpose: `One layer of the ${l.character} (${part.part}${part.axes.length ? `: ${part.axes.map((a) => values[a]).join(', ')}` : ''}), in every pose of ${l.over}.`,
|
||||
subject, angle: guide.angle ?? '', grid: guide.grid ?? { cols: 1, rows: 1 },
|
||||
cells: (guide.cells ?? []).map((c) => ({ id: `${id}-${pose(c.id)}`, does: c.does })),
|
||||
include: l.include, avoid: l.avoid, checks: l.checks, over: l.over,
|
||||
part: { name: part.part, stack },
|
||||
...(l.allow ? { allow: l.allow } : {})
|
||||
};
|
||||
(isFirst ? firsts : rest).push(asset);
|
||||
}
|
||||
});
|
||||
assets.splice(assets.indexOf(guide) + 1, 0, ...firsts, ...rest);
|
||||
}
|
||||
const { layers: _expanded, ...plain } = m;
|
||||
return { ...plain, assets };
|
||||
}
|
||||
|
||||
/** The canvases image generators offer (STYLE.md §5). Anything else gets resized by the tool, unasked. */
|
||||
@@ -77,8 +165,25 @@ function textsOf(a: Asset): 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[] {
|
||||
export function checkManifest(raw: Manifest, checklistLength: number): string[] {
|
||||
const problems: string[] = [];
|
||||
for (const l of raw.layers ?? []) {
|
||||
const where = `layers of ${l.character}`;
|
||||
const guide = raw.assets.find((a) => a.id === l.over);
|
||||
if (!guide) problems.push(`${where}: the guide "${l.over}" is not in the manifest`);
|
||||
else if (guide.type !== 'spritesheet') problems.push(`${where}: the guide "${l.over}" is a ${guide.type}, not a sprite sheet`);
|
||||
else if (guide.shipped) problems.push(`${where}: the guide "${l.over}" is shipped; the app stacks the layers, so the guide never appears`);
|
||||
for (const part of l.parts) {
|
||||
for (const axis of part.axes) if (!l.words[axis]) problems.push(`${where}: part ${part.part} needs words for "${axis}"`);
|
||||
for (const [, axis = ''] of part.subject.matchAll(/\{(\w+)\}/g)) {
|
||||
if (!part.axes.includes(axis)) problems.push(`${where}: part ${part.part} says {${axis}} but is not painted per ${axis}`);
|
||||
}
|
||||
}
|
||||
for (const text of [...Object.values(l.words).flatMap((w) => Object.values(w)), ...l.parts.map((p) => p.subject)]) {
|
||||
for (const hit of findForbidden(text)) problems.push(`${where}: "${hit.term}" (${hit.category}) may not appear in a prompt`);
|
||||
}
|
||||
}
|
||||
const m = expandLayers(raw);
|
||||
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`);
|
||||
|
||||
Reference in New Issue
Block a user