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

+73
View File
@@ -0,0 +1,73 @@
import {
isList,
isStruct,
NO_OBJECT,
type PropertyBag,
type PropertyValue,
tagOf,
} from '../model/Properties';
import type { EntityHandle } from './NodeContext';
import type { PortDef } from './NodeRegistry';
import { isEntity, isObjectPlace, type Value, writeTyped } from './values';
/**
* During a run a bag may hold live objects – in an object variable, a struct field, a list item. None
* of it may leave the run: `World.syncToModel` writes a behavior's changed values into the scene, a
* save is written as JSON, the inspector and the test hooks show what they are handed. Each of those
* ways out passes the value through here, where every object becomes the empty one (`NO_OBJECT`).
*/
export function withoutObjects<T extends PropertyValue | undefined>(value: T): T {
return mapObjects(value, () => NO_OBJECT) as T;
}
export function bagWithoutObjects(bag: PropertyBag): PropertyBag {
const out: PropertyBag = {};
for (const [key, value] of Object.entries(bag)) out[key] = withoutObjects(value);
return out;
}
/**
* A bag's value as a graph reads it: an object destroyed since it was written is gone, so a graph
* never goes on acting on one that has left the game. Alone it reads as nothing (`null`), inside a
* list or struct as the empty object.
*/
export function liveValue(
value: PropertyValue | undefined,
isAlive: (target: EntityHandle) => boolean,
): Value {
if (value === undefined || tagOf(value) === 'object') return null;
if (isEntity(value)) return isAlive(value) ? value : null;
return mapObjects(value, (held) => (isAlive(held) ? held : NO_OBJECT)) as Value;
}
/** What `outputs` read of a bag, each value live as `liveValue` says. */
export function readLive(
bag: PropertyBag,
outputs: readonly PortDef[],
isAlive: (target: EntityHandle) => boolean,
): Record<string, Value> {
const values: Record<string, Value> = {};
for (const port of outputs) if (port.key in bag) values[port.key] = liveValue(bag[port.key], isAlive);
return values;
}
/** Writes what arrives on `port` into the bag, typed as the slot is; an object port always makes an object's place. */
export function writePort(bag: PropertyBag, port: PortDef, value: Value | undefined): void {
if (port.type === 'object' && !isObjectPlace(bag[port.key])) bag[port.key] = NO_OBJECT;
writeTyped(bag, port.key, value);
}
/** `value` with each object replaced by what `swap` says; untouched parts keep their identity. */
function mapObjects(value: unknown, swap: (held: EntityHandle) => unknown): unknown {
if (isEntity(value as Value)) return swap(value as EntityHandle);
if (isList(value)) {
const items = value.map((item) => mapObjects(item, swap));
return items.some((item, i) => item !== value[i]) ? items : value;
}
if (isStruct(value) && tagOf(value) === undefined) {
const entries = Object.entries(value);
const mapped = entries.map(([key, field]) => [key, mapObjects(field, swap)] as const);
return mapped.some(([, field], i) => field !== entries[i]![1]) ? Object.fromEntries(mapped) : value;
}
return value;
}