Let structs and lists hold objects across behavior runs (#238)
game-maker / gate (push) Successful in 3m28s
game-maker / suite (push) Successful in 10m14s

An object could only live in a dedicated object variable, kept in slots
beside the variable bag. Struct fields and list items could not hold
one, so a spawned object packed into a struct or list was lost. This
replaces the slots with one mechanism for all three places.

- "No object" has one resting form everywhere: {"$object": ""}. A
  running game can tell an object slot from an empty text that way.
- During play the object handle lives directly in the value, also
  nested in structs and lists. objectSlots.ts and the special paths for
  Keep and Properties are gone.
- liveObjects.ts strips objects to (null) at every exit: overrides the
  editor run writes back to the scene, saved values of persistent
  Variables assets, live values in the inspector, and the world
  snapshot of the test hooks (objects as names there).
- A destroyed object reads as (null) through isAlive, alone, in a
  struct field or as a list item.
- "+ Field" and "+ Item" offer Object. The inspector and the list tab
  show a fixed (null) row without input.
- Lists from Raycast all stay objects when written to a variable.
  Before they turned into names.
- A struct that only changes by an object writes no override. A list
  that grows by an object writes [(null)], its length really changed.

Found on the way: CI at 98211a8 failed only in e2e 21d. #237 added
asset to the field kinds without updating that fixed expectation. 21d
now expects ...,animation,asset,object,struct.

No project on the server has object variables, so no old data is
affected.

Tests:
- ./check.sh: 169 files, 2475 tests, CHECK EXIT 0.
- e2e 6, 21, 23, 32: ALL PASSED, 213 checks.
- object-variable.test.ts rewritten: variable, struct field and list
  item over several frames, destroyed objects, nothing in scene, file
  or save, editor run reload, Keep.
- New e2e 21d-ii adds an Object item by click. 21d and 23k updated.
- 7 counter-probes, each fails 1 to 9 tests. Originals back via cmp.
- Not tested on its own: stripping of inspector live values and the
  names in the test snapshot, the "+ Field -> Object" menu by click.
- e2e check total 1407, only calculated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
adminandClaude Opus 5.5 committed 2026-09-26 21:12:44 +02:00
1 parent 98211a8d54
commit 7979b8ff19
24 files changed
+510 -193

No files matched your search

+10 -12
View File
@@ -7,6 +7,7 @@ import {
type ListValue,
type PropertyBag,
type PropertyValue,
NO_OBJECT,
type StructValue,
textOf,
} from '../model/Properties';
@@ -86,12 +87,13 @@ type Extras<K extends FlatKind> = K extends 'number'
: unknown;
/**
* The definition of a flat kind: its default is a value of that kind, as the table says.
* The definition of a flat kind: its default is a value of that kind, as the table says. Not an
* object's: that default is no value of the kind but its tagged place (`ObjectDef`).
* `shownWith` names a switch on the same bag; the inspector shows the row only while it is on
* (see `isRowShown`), everything else – graph, defaults, files – always has it.
*/
export type FlatDef<K extends FlatKind = FlatKind> = {
[P in K]: {
[P in Exclude<K, 'object'>]: {
key: string;
label: string;
kind: P;
@@ -100,7 +102,7 @@ export type FlatDef<K extends FlatKind = FlatKind> = {
initial?: ValueOf<P>;
shownWith?: string;
} & Extras<P>;
}[K];
}[Exclude<K, 'object'>];
/** The value a new asset starts with, which is also what Reset goes back to. */
export function initialOf(def: PropertyDef): PropertyValue {
@@ -161,9 +163,7 @@ export type PropertyDef =
| FlatDef
/**
* A list declares nothing about its items: each one carries its own kind (see `listItems.ts`),
* and the graph types a list as a list, so one `list` port fits them all. There is no `object`
* item kind: a list is stored in the project file, and an object is a live handle that no reload
* survives.
* and the graph types a list as a list, so one `list` port fits them all.
*/
| { key: string; label: string; kind: 'list'; default: ListValue }
/**
@@ -177,10 +177,7 @@ export type PropertyDef =
default: StructValue;
fields: readonly StructFieldDef[];
}
/**
* An object variable holds a live handle, which no file and no save can keep: the bag carries only
* this empty placeholder, and the handle sits beside it for the run (see `graph/objectSlots.ts`).
*/
/** An object variable holds a live handle during a run, and nothing at rest (`NO_OBJECT`). */
| ObjectDef;
export interface ObjectDef {
@@ -190,8 +187,7 @@ export interface ObjectDef {
default: typeof NO_OBJECT;
}
/** What an object variable stores – always nothing, since an object exists only while the game runs. */
export const NO_OBJECT = '';
export { NO_OBJECT };
export interface PrimitiveFieldDef {
key: string;
@@ -769,6 +765,7 @@ export function variableDef(
/** The empty value of a kind, so a field that is not there yet still has one. */
export function emptyFieldValue(field: StructFieldDef): FieldValue {
if (field.kind === 'object') return NO_OBJECT;
return field.kind === 'list' ? [] : emptyOf(field.kind);
}
@@ -811,5 +808,6 @@ export function coerceValue(def: PropertyDef, value: PropertyValue): PropertyVal
/** A struct field as its declaration promises. A list field takes only a list – see `ListFieldDef`. */
export function coerceFieldValue(value: PropertyValue, field: StructFieldDef): FieldValue {
if (field.kind === 'object') return NO_OBJECT;
return field.kind === 'list' ? flatListOf(value) : coerceField(value, field.kind);
}