Drop the per-list item declaration; every item carries its own kind
A list no longer says what its items are. ListDef.items, ListDef.fields,
ListFieldDef.items and SetListItemsCommand are gone; the single seam is
src/core/properties/listItems.ts. JSON already tells number, text, boolean
and struct apart, so only two kinds need a tag: {"$color": n} and the new
{"$texture": id}. Field names cannot start with "$", so a tag never
collides with a struct field. On a data link a texture item arrives as
its bare id; the graph has no images.
List tab: the mark in front of each row is the kind picker, "+ Item"
asks for the kind, both are ordinary value edits (one undo step). A list
inside a struct field only offers the flat kinds because the depth rule
forbids a struct item there (ListAccess.kinds); the menu used to offer
it and silently do nothing.
Legacy lists that declared items: 'color' are tagged on load.
Actor demo: the four walk animations and four standing frames live in
two list variables of texture items indexed by facing (Item at), so the
graph can be rebuilt in the editor. The stand frames get their grid ids
back; 44 nodes instead of 46.
Also: the user's edits to on-start-during-play.md and the new note
reseed-because-of-list.md.
Verified: check.sh 794 tests, full e2e 631 checks, smokes 24/19/20.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
e147dd6d21
commit
11c900c998
34 files changed
+1218
-640
No files matched your search
@@ -1,8 +1,6 @@
|
||||
import type { DeclaredPortKind } from '../../core/graph';
|
||||
import type { PropertyValue } from '../../core/model/Properties';
|
||||
import {
|
||||
FIELD_KINDS,
|
||||
LIST_ITEM_KINDS,
|
||||
type ListItemKind,
|
||||
type PropertyDef,
|
||||
STRUCT_FIELD_KINDS,
|
||||
@@ -11,8 +9,18 @@ import {
|
||||
type StructFieldKind,
|
||||
type VariableKind,
|
||||
} from '../../core/properties/PropertySchema';
|
||||
import { Button, Dropdown, HStack, Label, Menu, Spacer, TextField, Theme, type Widget } from '../../ui';
|
||||
import type { ListDef } from '../list/slot';
|
||||
import {
|
||||
Button,
|
||||
Dropdown,
|
||||
HStack,
|
||||
Label,
|
||||
Menu,
|
||||
type MenuItem,
|
||||
Spacer,
|
||||
TextField,
|
||||
Theme,
|
||||
type Widget,
|
||||
} from '../../ui';
|
||||
import {
|
||||
addValue,
|
||||
attachRowActions,
|
||||
@@ -38,6 +46,7 @@ const KIND_MARKS: Record<ShownKind, string> = {
|
||||
boolean: '✓',
|
||||
text: 'Aa',
|
||||
color: '◧',
|
||||
texture: '▦',
|
||||
list: '≡',
|
||||
struct: '⊞',
|
||||
object: '◇',
|
||||
@@ -48,19 +57,12 @@ export const KIND_LABELS: Record<ShownKind, string> = {
|
||||
boolean: 'Boolean',
|
||||
text: 'Text',
|
||||
color: 'Color',
|
||||
texture: 'Texture',
|
||||
list: 'List',
|
||||
struct: 'Struct',
|
||||
object: 'Object',
|
||||
};
|
||||
|
||||
const LIST_ITEM_LABELS: Record<ListItemKind, string> = {
|
||||
number: 'Numbers',
|
||||
boolean: 'Booleans',
|
||||
text: 'Texts',
|
||||
color: 'Colors',
|
||||
struct: 'Structs',
|
||||
};
|
||||
|
||||
/** Variables are `PropertyDef`s, so the kind is typed wide; only the shown kinds ever reach it. */
|
||||
export function kindMark(kind: string): string {
|
||||
return (KIND_MARKS as Partial<Record<string, string>>)[kind] ?? '?';
|
||||
@@ -70,7 +72,6 @@ export function kindMark(kind: string): string {
|
||||
export interface VariableEditing {
|
||||
rename: (next: string) => void;
|
||||
remove: () => void;
|
||||
setItems: (items: ListItemKind) => void;
|
||||
renameField: (field: StructFieldDef, next: string) => void;
|
||||
removeField: (field: StructFieldDef) => void;
|
||||
addField: (kind: StructFieldKind) => void;
|
||||
@@ -95,7 +96,7 @@ export function buildVariable(
|
||||
): FieldRow {
|
||||
const { edit, actions } = options;
|
||||
const name = nameCell(def.key, 0, edit && ((next) => edit.rename(next)));
|
||||
const head = gridRow(0, markOf(def, edit), name);
|
||||
const head = gridRow(0, markLabel(kindMark(def.kind)), name);
|
||||
let setValue: (next: PropertyValue) => void = () => {};
|
||||
if (def.kind === 'struct') {
|
||||
head.add(new Spacer(), 1);
|
||||
@@ -108,7 +109,6 @@ export function buildVariable(
|
||||
host.body.add(head);
|
||||
|
||||
if (def.kind === 'struct') setValue = structFieldRows(host, def, value, handlers, edit);
|
||||
if (def.kind === 'list' && def.items === 'struct' && edit) itemShapeRows(host, def, edit);
|
||||
|
||||
return {
|
||||
row: head,
|
||||
@@ -147,24 +147,6 @@ function structFieldRows(
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The item shape of a list of structs: names and kinds only (primitives, see `ListFieldDef`). The
|
||||
* values are edited in the List tab, one row per item, which is why there is no value column.
|
||||
*/
|
||||
function itemShapeRows(host: InspectorHost, def: ListDef, edit: VariableEditing): void {
|
||||
for (const field of def.fields ?? []) {
|
||||
const row = fieldRow(field, edit);
|
||||
row.add(new Spacer(), 1);
|
||||
row.add(removeButton(() => edit.removeField(field)));
|
||||
host.body.add(row);
|
||||
}
|
||||
const foot = new HStack({ gap: Theme.gap, align: 'center' });
|
||||
foot.minHeight = Theme.rowHeight;
|
||||
foot.add(new Spacer(), 1);
|
||||
foot.add(addFieldMenu(FIELD_KINDS, edit));
|
||||
host.body.add(foot);
|
||||
}
|
||||
|
||||
function fieldRow(field: StructFieldDef, edit: VariableEditing | undefined): HStack {
|
||||
const name = nameCell(field.key, 1, edit && ((next) => edit.renameField(field, next)));
|
||||
return gridRow(1, markLabel(KIND_MARKS[field.kind]), name);
|
||||
@@ -192,19 +174,14 @@ function nameCell(text: string, depth: number, rename: ((next: string) => void)
|
||||
: new Label(text, { style: 'muted', width, padding: Theme.fieldPadding });
|
||||
}
|
||||
|
||||
function markOf(def: PropertyDef, edit: VariableEditing | undefined): Widget {
|
||||
if (def.kind !== 'list') return markLabel(kindMark(def.kind));
|
||||
const glyph = `≡${KIND_MARKS[def.items]}`;
|
||||
return edit ? itemKindPicker(glyph, def.items, edit) : markLabel(glyph);
|
||||
}
|
||||
|
||||
export function markLabel(glyph: string): Label {
|
||||
return new Label(glyph, { style: 'small', align: 'center', width: MARK_WIDTH });
|
||||
}
|
||||
|
||||
/**
|
||||
* A kind mark that can be clicked. The label may take the button's whole width: the column is
|
||||
* sized for its widest glyph, and the usual inset would cut `≡Aa` to `≡A…`.
|
||||
* A kind mark that can be clicked – the List tab's way of saying what an item holds. The label may
|
||||
* take the button's whole width: the column is sized for its widest glyph, and the usual inset
|
||||
* would cut `Aa` to `A…`.
|
||||
*/
|
||||
class MarkButton extends Button {
|
||||
protected override labelSlot(): number {
|
||||
@@ -212,20 +189,10 @@ class MarkButton extends Button {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* On the asset, the mark of a list doubles as the chooser for what it holds – it is the one place
|
||||
* that already says it. Changing it runs every value through the new declaration.
|
||||
*/
|
||||
function itemKindPicker(glyph: string, current: ListItemKind, edit: VariableEditing): Button {
|
||||
/** The mark of a kind, as a button that offers the others. */
|
||||
export function markPicker(glyph: string, items: MenuItem[]): Button {
|
||||
const picker = new MarkButton(glyph, { variant: 'ghost', width: MARK_WIDTH, style: 'small' });
|
||||
picker.onClick = () => {
|
||||
new Menu(
|
||||
LIST_ITEM_KINDS.filter((items) => items !== current).map((items) => ({
|
||||
label: LIST_ITEM_LABELS[items],
|
||||
onSelect: () => edit.setItems(items),
|
||||
})),
|
||||
).openBelow(picker);
|
||||
};
|
||||
picker.onClick = () => new Menu(items).openBelow(picker);
|
||||
return picker;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user