Let a value be a bundle of named fields

PropertyValue was number | string | boolean | list. A struct joins it, which
costs two things the typechecker found rather than I did.

An object on a data edge used to mean a live entity, so asEntity would have
taken a struct for one and asString would have read .name off it. EntityHandle
now carries a symbol brand – a symbol so no field name can impersonate it, and
it never serializes, which suits a thing that exists only while the game runs.
It is built in exactly one place.

String(value) would have written a struct as [object Object] at 39 call sites.
They go through textOf(), which is identical for primitives.

normalizeGraph dropped everything but primitives from node params, so the List
node lost its value on every save ([3,1,4] round-tripped to undefined).
Variables were spared: they have a schema, params have none.
This commit is contained in:
root committed 2026-09-10 08:14:18 +02:00
1 parent 3b3f374e10
commit 2cf788eedd
34 files changed
+284 -82

No files matched your search

+3
View File
@@ -1,3 +1,4 @@
import type { ENTITY_HANDLE } from '../core/graph/NodeContext';
import type { AssetType } from '../core/model/AssetTypes';
import type { PropertyBag } from '../core/model/Properties';
@@ -8,6 +9,8 @@ import type { PropertyBag } from '../core/model/Properties';
* editor panels can show and edit them while playing.
*/
export interface Entity {
/** What tells a graph this object is a live entity and not a struct value. */
readonly [ENTITY_HANDLE]: true;
id: string;
/** Scene object this entity was instantiated from (for selection highlighting). */
objectId: string;
+2 -1
View File
@@ -1,4 +1,4 @@
import { isHandleEnabled, type PointerState, worldPositionOf } from '../core/graph';
import { ENTITY_HANDLE, isHandleEnabled, type PointerState, worldPositionOf } from '../core/graph';
import { newId } from '../core/ids';
import type { Asset } from '../core/model/Asset';
import { isPlaceableType } from '../core/model/AssetTypes';
@@ -118,6 +118,7 @@ export class World {
let entity = this.findByObjectId(object.id);
if (!entity) {
entity = {
[ENTITY_HANDLE]: true,
id: `e-${object.id}`,
objectId: object.id,
assetId: asset.id,
+3 -3
View File
@@ -9,7 +9,7 @@ import {
} from '../../core/graph';
import { stepKeyRepeat } from '../../core/graph/keyRepeat';
import { behaviorLookup } from '../../core/model/behaviorPrograms';
import type { PropertyBag } from '../../core/model/Properties';
import { type PropertyBag, textOf } from '../../core/model/Properties';
import { findAsset, type Project } from '../../core/model/Project';
import type { Entity } from '../Entity';
import type { World } from '../World';
@@ -95,7 +95,7 @@ export class BehaviorSystem implements System {
update(world: World, dt: number): void {
this.syncInstances(world);
const keyOf = (node: { params: PropertyBag }) => String(node.params.key ?? '');
const keyOf = (node: { params: PropertyBag }) => textOf(node.params.key ?? '');
for (const instance of this.instances) {
if (!world.entities.includes(instance.entity)) continue; // destroyed during play
if (!isHandleEnabled(instance.entity)) continue; // switched off (itself or a parent)
@@ -136,7 +136,7 @@ export class BehaviorSystem implements System {
* in `nodeState`, so two nodes on the same key repeat on their own schedules.
*/
private fireKeyDown(i: GraphInterpreter, ctx: NodeContext, node: GraphNode, dt: number): void {
const key = String(node.params.key ?? '');
const key = textOf(node.params.key ?? '');
const stored = i.nodeState.get(node.id);
const { state, fires } = stepKeyRepeat(
stored ? { held: stored.held ?? 0, repeats: stored.repeats ?? 0 } : null,