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

+2 -1
View File
@@ -1,6 +1,7 @@
import type { NodeDef } from '../../NodeRegistry';
import { bool, normalize, num } from '../shared';
import { textOf } from '../../../model/Properties';
export const AxisInput: NodeDef = {
type: 'AxisInput',
label: 'Axis input',
@@ -15,7 +16,7 @@ export const AxisInput: NodeDef = {
{ key: 'down', label: 'Down', kind: 'key', default: 'ArrowDown' },
],
run: (ctx, _inputs, params) => {
const held = (key: string, fallback: string) => (ctx.isKeyDown(String(params[key] ?? fallback)) ? 1 : 0);
const held = (key: string, fallback: string) => (ctx.isKeyDown(textOf(params[key] ?? fallback)) ? 1 : 0);
const dx = held('right', 'ArrowRight') - held('left', 'ArrowLeft');
const dy = held('down', 'ArrowDown') - held('up', 'ArrowUp');
const { x, y, length } = normalize(dx, dy);
+2 -1
View File
@@ -2,6 +2,7 @@ import type { NodeDef } from '../../NodeRegistry';
import { asNumber } from '../../values';
import { bool, num } from '../shared';
import { textOf } from '../../../model/Properties';
const OPERATORS: Record<string, (a: number, b: number) => boolean> = {
'==': (a, b) => a === b,
'!=': (a, b) => a !== b,
@@ -30,7 +31,7 @@ export const Compare: NodeDef = {
run: (_ctx, inputs, params) => {
// The fallback matches the param's declared default, so a node with no setting behaves
// like a freshly created one.
const compare = OPERATORS[String(params.op)] ?? OPERATORS['<']!;
const compare = OPERATORS[textOf(params.op)] ?? OPERATORS['<']!;
return { outputs: { result: compare(asNumber(inputs.a), asNumber(inputs.b)) } };
},
};
+2 -1
View File
@@ -2,6 +2,7 @@ import type { NodeDef } from '../../NodeRegistry';
import { asEntity } from '../../values';
import { any, obj } from '../shared';
import { textOf } from '../../../model/Properties';
export const GetProperty: NodeDef = {
type: 'GetProperty',
label: 'Get property',
@@ -11,6 +12,6 @@ export const GetProperty: NodeDef = {
outputs: [any('value')],
params: [{ key: 'property', label: 'Property', kind: 'text', default: 'width' }],
run: (_ctx, inputs, params) => ({
outputs: { value: asEntity(inputs.object)?.props[String(params.property ?? '')] ?? null },
outputs: { value: asEntity(inputs.object)?.props[textOf(params.property ?? '')] ?? null },
}),
};
+2 -1
View File
@@ -2,6 +2,7 @@ import type { NodeDef } from '../../NodeRegistry';
import { asEntity } from '../../values';
import { assetParam, bool, obj } from '../shared';
import { textOf } from '../../../model/Properties';
export const IsAsset: NodeDef = {
type: 'IsAsset',
label: 'Is asset',
@@ -11,7 +12,7 @@ export const IsAsset: NodeDef = {
outputs: [bool('result')],
params: [assetParam],
run: (_ctx, inputs, params) => {
const assetId = String(params.asset ?? '');
const assetId = textOf(params.asset ?? '');
return { outputs: { result: Boolean(assetId) && asEntity(inputs.object)?.assetId === assetId } };
},
};
+2 -1
View File
@@ -1,6 +1,7 @@
import type { NodeDef } from '../../NodeRegistry';
import { bool, keyParam } from '../shared';
import { textOf } from '../../../model/Properties';
export const KeyIsDown: NodeDef = {
type: 'KeyIsDown',
label: 'Key is down',
@@ -9,5 +10,5 @@ export const KeyIsDown: NodeDef = {
inputs: [],
outputs: [bool('down')],
params: [keyParam],
run: (ctx, _inputs, params) => ({ outputs: { down: ctx.isKeyDown(String(params.key ?? '')) } }),
run: (ctx, _inputs, params) => ({ outputs: { down: ctx.isKeyDown(textOf(params.key ?? '')) } }),
};