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,8 @@
|
||||
/** The declarations cap depth: `list → struct → primitive` is the deepest a stored value goes. */
|
||||
/** Depth is capped: `list → struct → primitive` is the deepest a stored value goes. */
|
||||
export type ListValue = readonly (number | string | boolean | StructValue)[];
|
||||
|
||||
/** What a struct field may hold. A field is never itself a struct – see `ListValue`. */
|
||||
export type FieldValue = number | string | boolean | ListValue;
|
||||
/** What a struct field may hold. A field is never itself a struct – except a tagged colour. */
|
||||
export type FieldValue = number | string | boolean | ListValue | ColorItem;
|
||||
|
||||
/** Several named values travelling as one, so a bundle needs one port instead of one per part. */
|
||||
export type StructValue = { readonly [field: string]: FieldValue };
|
||||
@@ -14,6 +14,44 @@ export type PropertyBag = Record<string, PropertyValue>;
|
||||
|
||||
export const isList = (value: unknown): value is ListValue => Array.isArray(value);
|
||||
|
||||
/**
|
||||
* Inside a list a color and a texture have to say so: a list declares nothing about its items, and
|
||||
* there 0xRRGGBB is a plain number and an asset id a plain text. A field name cannot start with `$`
|
||||
* (`isValidFieldName`), so a tag can never collide with a struct item of one field.
|
||||
*/
|
||||
export const COLOR_TAG = '$color';
|
||||
export const TEXTURE_TAG = '$texture';
|
||||
|
||||
/** Indexable like any struct, so the one place that reads fields by name needs no special case. */
|
||||
export interface ColorItem {
|
||||
readonly $color: number;
|
||||
readonly [field: string]: FieldValue;
|
||||
}
|
||||
|
||||
/** A picture a sprite can wear: a texture, one of its frames, or an animation – all one id. */
|
||||
export interface TextureItem {
|
||||
readonly $texture: string;
|
||||
readonly [field: string]: FieldValue;
|
||||
}
|
||||
|
||||
const isTagged = (value: unknown, tag: string): boolean =>
|
||||
isStruct(value) && tag in value && Object.keys(value).length === 1;
|
||||
|
||||
export const isColorItem = (value: unknown): value is ColorItem => isTagged(value, COLOR_TAG);
|
||||
|
||||
export const isTextureItem = (value: unknown): value is TextureItem =>
|
||||
isTagged(value, TEXTURE_TAG) && typeof (value as TextureItem).$texture === 'string';
|
||||
|
||||
export const colorItem = (color: number): ColorItem => ({ $color: color });
|
||||
|
||||
export const textureItem = (id: string): TextureItem => ({ $texture: id });
|
||||
|
||||
/** The number behind a tagged color. */
|
||||
export const colorItemValue = (item: ColorItem): number => colorOf(item.$color, 0);
|
||||
|
||||
/** The id behind a tagged texture. */
|
||||
export const textureItemValue = (item: TextureItem): string => item.$texture;
|
||||
|
||||
/**
|
||||
* Model-level only: a live entity handle is an object too, and the graph tells the two apart by
|
||||
* the handle's brand (see `values.ts`). Nothing in a PropertyBag is ever a handle.
|
||||
@@ -28,6 +66,9 @@ export const isStruct = (value: unknown): value is StructValue =>
|
||||
export function textOf(value: PropertyValue | undefined): string {
|
||||
if (value === undefined) return '';
|
||||
if (isList(value)) return value.map((item) => textOf(item)).join(', ');
|
||||
// A tagged value reads as what it wraps, the same as the matching property does.
|
||||
if (isColorItem(value)) return String(colorItemValue(value));
|
||||
if (isTextureItem(value)) return textureItemValue(value);
|
||||
if (isStruct(value))
|
||||
return Object.entries(value)
|
||||
.map(([field, item]) => `${field}: ${textOf(item)}`)
|
||||
|
||||
Reference in new issue
Block a user