Replace the property nodes with one Properties node
Get/Set property, Get/Set properties, Set enabled and Set text are gone. A single Properties node takes a fixed "object" input; every chosen property is an output that reads the current value, and one switched to Set is also an input written when the flow arrives. Exec pins only exist while at least one entry writes. The node carries a type (Sprite, Text, Collider, Camera, Container, Behavior, Any) that decides what "+ Property" offers: the fields of that type, the variables of the chosen behavior, or for Any a kind to pick and a name to type. Each port takes the default and field of its type, so a Camera width starts at 640. Switching the type keeps the ports and marks those the new type lacks. At runtime the type is only an editor aid; the node writes to whatever object it gets. Old project files are converted on load. The type is inferred from the keys: the first object type that has them all, else the one behavior that declares them all, else Any. enabled belongs to every object, so a converted Set enabled lands on Any. The jump-run and tetris seeders use Properties throughout; draw-piece switches its cell on in the same node that sets the colour. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7c63c884ef
commit
58f19a3451
36 files changed
+1040
-719
No files matched your search
@@ -2,7 +2,14 @@ import { edgesInto, edgesOutOf, type Graph, type GraphNode } from './Graph';
|
||||
import { type BehaviorLookup, NO_BEHAVIORS } from './lookup';
|
||||
import { BEHAVIOR_END, BEHAVIOR_START, resolveDef, terminalNode } from './nested';
|
||||
import type { NodeContext } from './NodeContext';
|
||||
import { type CallResult, hasExecInput, inlineValue, isEventNode, type RepeatResult } from './NodeRegistry';
|
||||
import {
|
||||
type CallResult,
|
||||
hasExecInput,
|
||||
inlineValue,
|
||||
isEventNode,
|
||||
type PortDef,
|
||||
type RepeatResult,
|
||||
} from './NodeRegistry';
|
||||
import type { Value } from './values';
|
||||
|
||||
/** How much work one pulse may do. A Repeat over a 10×20 board is 200 rounds, so this is generous. */
|
||||
@@ -150,15 +157,16 @@ export class GraphInterpreter {
|
||||
/** Resolves every data input: connected → pulled from the source, else the inline param. */
|
||||
private collectInputs(node: GraphNode, ctx: NodeContext): Record<string, Value> {
|
||||
const inputs: Record<string, Value> = {};
|
||||
for (const port of this.def(node)?.inputs ?? []) {
|
||||
if (port.type === 'exec') continue;
|
||||
const edge = edgesInto(this.frame.graph, node.id, port.key)[0];
|
||||
if (edge) inputs[port.key] = this.readOutput(edge.from.node, edge.from.port, ctx);
|
||||
else inputs[port.key] = inlineValue(node, port);
|
||||
}
|
||||
for (const port of this.def(node)?.inputs ?? [])
|
||||
if (port.type !== 'exec') inputs[port.key] = this.inputValue(node, port, ctx);
|
||||
return inputs;
|
||||
}
|
||||
|
||||
private inputValue(node: GraphNode, port: PortDef, ctx: NodeContext): Value {
|
||||
const edge = edgesInto(this.frame.graph, node.id, port.key)[0];
|
||||
return edge ? this.readOutput(edge.from.node, edge.from.port, ctx) : inlineValue(node, port);
|
||||
}
|
||||
|
||||
/** Value of one output port: from the pulse cache, or by evaluating a pure data node. */
|
||||
private readOutput(nodeId: string, port: string, ctx: NodeContext): Value {
|
||||
const cached = this.frame.outputCache.get(nodeId) ?? this.frame.dataCache.get(nodeId);
|
||||
@@ -169,7 +177,11 @@ export class GraphInterpreter {
|
||||
if (!def) return null;
|
||||
if (def.read) {
|
||||
this.trace?.onNode(nodeId);
|
||||
return def.read(ctx, source.params)[port] ?? null;
|
||||
const input = (key: string): Value => {
|
||||
const found = def.inputs.find((p) => p.key === key);
|
||||
return found ? this.inputValue(source, found, ctx) : null;
|
||||
};
|
||||
return def.read(ctx, source.params, input)[port] ?? null;
|
||||
}
|
||||
// Exec nodes that have not run in this pulse have no value yet.
|
||||
if (isEventNode(def) || hasExecInput(def) || !def.run) return null;
|
||||
|
||||
@@ -80,7 +80,7 @@ export interface NodeDef {
|
||||
*/
|
||||
declaresPorts?: 'inputs' | 'outputs' | 'both';
|
||||
/** How a declared port becomes a port; without it, named after its key and typed by its kind. */
|
||||
declaredPort?(port: DeclaredPort): PortDef;
|
||||
declaredPort?(port: DeclaredPort, node: GraphNode): PortDef;
|
||||
/**
|
||||
* Ports this node computes beyond the fixed and the declared ones – how many outputs a Sequence
|
||||
* offers, which values the behavior a call node names takes. `resolveDef` applies it.
|
||||
@@ -88,9 +88,10 @@ export interface NodeDef {
|
||||
derivePorts?(source: PortSource): DerivedShape;
|
||||
/**
|
||||
* Outputs readable at any moment, even while the node's exec input has not fired in this pulse.
|
||||
* Never cached, so a read after a write sees the new value.
|
||||
* Never cached, so a read after a write sees the new value. `input` pulls one input on demand:
|
||||
* pulling all of them would loop through an edge that feeds the node's own output back in.
|
||||
*/
|
||||
read?(ctx: NodeContext, params: PropertyBag): Record<string, Value>;
|
||||
read?(ctx: NodeContext, params: PropertyBag, input: (key: string) => Value): Record<string, Value>;
|
||||
/**
|
||||
* Event nodes have no `run` – the interpreter seeds their outputs. `def` is resolved for the node at
|
||||
* hand, the only way a node with derived ports knows how many it has.
|
||||
|
||||
+15
-13
@@ -8,8 +8,7 @@ export const BEHAVIOR_START = 'BehaviorStart';
|
||||
export const BEHAVIOR_END = 'BehaviorEnd';
|
||||
export const RUN_BEHAVIOR = 'RunBehavior';
|
||||
export const VARIABLES = 'Variables';
|
||||
export const GET_PROPERTIES = 'GetProperties';
|
||||
export const SET_PROPERTIES = 'SetProperties';
|
||||
export const PROPERTIES = 'Properties';
|
||||
|
||||
export const BEHAVIOR_PARAM = 'behavior';
|
||||
|
||||
@@ -24,7 +23,7 @@ export function declaresVariablePorts(type: string): boolean {
|
||||
|
||||
/** Nodes whose declared ports are properties of the object they are handed. */
|
||||
export function declaresPropertyPorts(type: string): boolean {
|
||||
return type === GET_PROPERTIES || type === SET_PROPERTIES;
|
||||
return type === PROPERTIES;
|
||||
}
|
||||
|
||||
/** Identifier-like, and not `exec`: that key belongs to the fixed flow port of every terminal node. */
|
||||
@@ -32,12 +31,15 @@ export function isValidPortName(name: string): boolean {
|
||||
return isValidFieldName(name) && name !== 'exec';
|
||||
}
|
||||
|
||||
/** Keys a declared port cannot take: the node's fixed ports on the side it declares (`object`). */
|
||||
/**
|
||||
* Keys a declared port cannot take: the node's fixed ports on the side it declares (`object`), and
|
||||
* its settings, which share the params bag with the typed-in values of its inputs.
|
||||
*/
|
||||
export function fixedPortKeys(def: NodeDef): string[] {
|
||||
const side = def.declaresPorts;
|
||||
const fixed =
|
||||
side === 'inputs' ? def.inputs : side === 'outputs' ? def.outputs : [...def.inputs, ...def.outputs];
|
||||
return fixed.map((p) => p.key);
|
||||
return [...fixed.map((p) => p.key), ...def.params.map((p) => p.key)];
|
||||
}
|
||||
|
||||
export function declaredOn(
|
||||
@@ -81,16 +83,16 @@ export function resolveDef(node: GraphNode, graph: Graph, lookup: BehaviorLookup
|
||||
if (!def || (!def.declaresPorts && !def.derivePorts)) return def;
|
||||
const own = (side: 'inputs' | 'outputs') =>
|
||||
declaredOn(def, node.ports ?? [], side).map((p) =>
|
||||
def.declaredPort ? def.declaredPort(p) : portDefOf(p),
|
||||
def.declaredPort ? def.declaredPort(p, node) : portDefOf(p),
|
||||
);
|
||||
const grown = def.derivePorts?.({ node, graph, behaviors: lookup }) ?? {};
|
||||
// Derived before declared: a derived exec pin belongs at the top.
|
||||
return {
|
||||
...def,
|
||||
label: grown.label ?? def.label,
|
||||
inputs: [...def.inputs, ...(grown.inputs ?? []), ...own('inputs')],
|
||||
outputs: [...def.outputs, ...(grown.outputs ?? []), ...own('outputs')],
|
||||
};
|
||||
const side = (key: 'inputs' | 'outputs') => execFirst([...def[key], ...(grown[key] ?? []), ...own(key)]);
|
||||
return { ...def, label: grown.label ?? def.label, inputs: side('inputs'), outputs: side('outputs') };
|
||||
}
|
||||
|
||||
/** A derived exec pin belongs at the top, above the fixed data ports too. */
|
||||
function execFirst(ports: PortDef[]): PortDef[] {
|
||||
return [...ports.filter((p) => p.type === 'exec'), ...ports.filter((p) => p.type !== 'exec')];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { asBoolean, asEntity } from '../../values';
|
||||
import { bool, exec, obj, withDefault } from '../shared';
|
||||
|
||||
export const SetEnabled: NodeDef = {
|
||||
type: 'SetEnabled',
|
||||
label: 'Set enabled',
|
||||
category: 'action',
|
||||
description:
|
||||
'Switches an object on or off. A disabled object is not drawn, does not collide and its behavior stops – ' +
|
||||
'and so does everything parented below it. This is how screens (title, win, lose) are shown and hidden.',
|
||||
inputs: [exec(), obj('object'), withDefault(bool('enabled'), true)],
|
||||
outputs: [exec()],
|
||||
params: [],
|
||||
run: (_ctx, inputs) => {
|
||||
const target = asEntity(inputs.object);
|
||||
if (target) target.props.enabled = asBoolean(inputs.enabled);
|
||||
return { next: 'exec' };
|
||||
},
|
||||
};
|
||||
@@ -1,28 +0,0 @@
|
||||
import { SET_PROPERTIES } from '../../nested';
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { propertyPort } from '../../propertyPorts';
|
||||
import { asEntity, writeTyped } from '../../values';
|
||||
import { exec, obj } from '../shared';
|
||||
|
||||
/**
|
||||
* The plural of Set property: one input per property picked. Like Set variables it writes every
|
||||
* property it lists each time it runs – an unconnected input writes the value typed on the node.
|
||||
*/
|
||||
export const SetProperties: NodeDef = {
|
||||
type: SET_PROPERTIES,
|
||||
label: 'Set properties',
|
||||
category: 'action',
|
||||
description: 'Writes several properties (width, color, …) of an object at once, one input per property.',
|
||||
inputs: [exec(), obj('object')],
|
||||
outputs: [exec()],
|
||||
params: [],
|
||||
declaresPorts: 'inputs',
|
||||
declaredPort: propertyPort,
|
||||
run: (_ctx, inputs, _params, def) => {
|
||||
const target = asEntity(inputs.object);
|
||||
if (target)
|
||||
for (const port of def.inputs.slice(SetProperties.inputs.length))
|
||||
writeTyped(target.props, port.key, inputs[port.key]);
|
||||
return { next: 'exec' };
|
||||
},
|
||||
};
|
||||
@@ -1,20 +0,0 @@
|
||||
import { textOf } from '../../../model/Properties';
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { asEntity, writeTyped } from '../../values';
|
||||
import { any, exec, obj, PROPERTY_PARAM } from '../shared';
|
||||
|
||||
export const SetProperty: NodeDef = {
|
||||
type: 'SetProperty',
|
||||
label: 'Set property',
|
||||
category: 'action',
|
||||
description: 'Writes a property (width, color, …) of an object.',
|
||||
inputs: [exec(), obj('object'), any('value')],
|
||||
outputs: [exec()],
|
||||
params: [PROPERTY_PARAM],
|
||||
run: (_ctx, inputs, params) => {
|
||||
const target = asEntity(inputs.object);
|
||||
const key = textOf(params.property ?? '');
|
||||
if (target && key) writeTyped(target.props, key, inputs.value);
|
||||
return { next: 'exec' };
|
||||
},
|
||||
};
|
||||
@@ -1,18 +0,0 @@
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { asEntity, asString } from '../../values';
|
||||
import { any, exec, obj } from '../shared';
|
||||
|
||||
export const SetText: NodeDef = {
|
||||
type: 'SetText',
|
||||
label: 'Set text',
|
||||
category: 'action',
|
||||
description: 'Writes the content of a text object (same as Set property "text").',
|
||||
inputs: [exec(), obj('object'), any('text')],
|
||||
outputs: [exec()],
|
||||
params: [],
|
||||
run: (_ctx, inputs) => {
|
||||
const target = asEntity(inputs.object);
|
||||
if (target) target.props.text = asString(inputs.text);
|
||||
return { next: 'exec' };
|
||||
},
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import { GET_PROPERTIES } from '../../nested';
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { propertyPort } from '../../propertyPorts';
|
||||
import { asEntity, type Value } from '../../values';
|
||||
import { obj } from '../shared';
|
||||
|
||||
/** The plural of Get property: one output per property picked, the way Get variables reads. */
|
||||
export const GetProperties: NodeDef = {
|
||||
type: GET_PROPERTIES,
|
||||
label: 'Get properties',
|
||||
category: 'data',
|
||||
description: 'Reads several properties (width, color, …) of an object at once, one output per property.',
|
||||
inputs: [obj('object')],
|
||||
outputs: [],
|
||||
params: [],
|
||||
declaresPorts: 'outputs',
|
||||
declaredPort: propertyPort,
|
||||
run: (_ctx, inputs, _params, def) => {
|
||||
const target = asEntity(inputs.object);
|
||||
const outputs: Record<string, Value> = {};
|
||||
for (const port of def.outputs) outputs[port.key] = target?.props[port.key] ?? null;
|
||||
return { outputs };
|
||||
},
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
import { textOf } from '../../../model/Properties';
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import { asEntity } from '../../values';
|
||||
import { any, obj, PROPERTY_PARAM } from '../shared';
|
||||
|
||||
export const GetProperty: NodeDef = {
|
||||
type: 'GetProperty',
|
||||
label: 'Get property',
|
||||
category: 'data',
|
||||
description: 'Reads a property (width, color, …) of an object.',
|
||||
inputs: [obj('object')],
|
||||
outputs: [any('value')],
|
||||
params: [PROPERTY_PARAM],
|
||||
run: (_ctx, inputs, params) => ({
|
||||
outputs: { value: asEntity(inputs.object)?.props[textOf(params.property ?? '')] ?? null },
|
||||
}),
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
import { PROPERTIES } from '../../nested';
|
||||
import type { NodeDef } from '../../NodeRegistry';
|
||||
import {
|
||||
OBJECT_BEHAVIOR_SETTING,
|
||||
OBJECT_TYPE_SETTING,
|
||||
propertiesTitle,
|
||||
propertyPort,
|
||||
} from '../../propertyPorts';
|
||||
import { asEntity, writeTyped } from '../../values';
|
||||
import { exec, obj } from '../shared';
|
||||
|
||||
export const Properties: NodeDef = {
|
||||
type: PROPERTIES,
|
||||
label: 'Properties',
|
||||
category: 'data',
|
||||
description:
|
||||
'Reads properties (width, color, a variable, …) of the object it is handed, at any time. Those ' +
|
||||
'switched to Set are written together when the flow arrives.',
|
||||
inputs: [obj('object')],
|
||||
outputs: [],
|
||||
params: [OBJECT_TYPE_SETTING, OBJECT_BEHAVIOR_SETTING],
|
||||
// The title names both ("Sprite properties", "Game properties").
|
||||
hiddenParams: () => [OBJECT_TYPE_SETTING.key, OBJECT_BEHAVIOR_SETTING.key],
|
||||
declaresPorts: 'both',
|
||||
declaredPort: (port, node) => propertyPort(port, node.params),
|
||||
derivePorts: ({ node, behaviors }) => {
|
||||
const label = propertiesTitle(node, behaviors);
|
||||
return (node.ports ?? []).some((p) => p.write) ? { label, inputs: [exec()], outputs: [exec()] } : { label };
|
||||
},
|
||||
read: (_ctx, _params, input) => asEntity(input('object'))?.props ?? {},
|
||||
run: (_ctx, inputs, _params, def) => {
|
||||
const target = asEntity(inputs.object);
|
||||
if (target)
|
||||
for (const port of def.inputs)
|
||||
if (port.type !== 'exec' && port.key !== 'object') writeTyped(target.props, port.key, inputs[port.key]);
|
||||
return { next: 'exec' };
|
||||
},
|
||||
};
|
||||
@@ -3,11 +3,7 @@ import { Destroy } from './action/Destroy';
|
||||
import { Log } from './action/Log';
|
||||
import { Move } from './action/Move';
|
||||
import { RestartGame } from './action/RestartGame';
|
||||
import { SetEnabled } from './action/SetEnabled';
|
||||
import { SetPosition } from './action/SetPosition';
|
||||
import { SetProperties } from './action/SetProperties';
|
||||
import { SetProperty } from './action/SetProperty';
|
||||
import { SetText } from './action/SetText';
|
||||
import { Spawn } from './action/Spawn';
|
||||
import { StopGame } from './action/StopGame';
|
||||
import { Abs } from './data/Abs';
|
||||
@@ -24,8 +20,6 @@ import { Equals } from './data/Equals';
|
||||
import { FindText } from './data/FindText';
|
||||
import { Floor } from './data/Floor';
|
||||
import { GetPosition } from './data/GetPosition';
|
||||
import { GetProperties } from './data/GetProperties';
|
||||
import { GetProperty } from './data/GetProperty';
|
||||
import { IsAsset } from './data/IsAsset';
|
||||
import { IsEnabled } from './data/IsEnabled';
|
||||
import { IsHovered } from './data/IsHovered';
|
||||
@@ -47,6 +41,7 @@ import { ObjectByName } from './data/ObjectByName';
|
||||
import { Or } from './data/Or';
|
||||
import { Owner } from './data/Owner';
|
||||
import { PackStruct } from './data/PackStruct';
|
||||
import { Properties } from './data/Properties';
|
||||
import { Parent } from './data/Parent';
|
||||
import { Random } from './data/Random';
|
||||
import { Round } from './data/Round';
|
||||
@@ -118,8 +113,7 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
|
||||
NameOf,
|
||||
IsAsset,
|
||||
IsEnabled,
|
||||
GetProperty,
|
||||
GetProperties,
|
||||
Properties,
|
||||
GetPosition,
|
||||
// data: literals and math
|
||||
NumberLiteral,
|
||||
@@ -176,10 +170,6 @@ export const BUILT_IN_NODES: readonly NodeDef[] = [
|
||||
// actions
|
||||
Move,
|
||||
SetPosition,
|
||||
SetProperty,
|
||||
SetProperties,
|
||||
SetEnabled,
|
||||
SetText,
|
||||
Spawn,
|
||||
Destroy,
|
||||
Log,
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
import type { PropertyValue } from '../../model/Properties';
|
||||
import { OBJECT_PROPERTY_SUGGESTIONS, type PropertyDef } from '../../properties/PropertySchema';
|
||||
import type { PropertyDef } from '../../properties/PropertySchema';
|
||||
import type { NodeDef, PortDef } from '../NodeRegistry';
|
||||
import { asBoolean, asNumber } from '../values';
|
||||
|
||||
/** The property a Get/Set property node names: typed freely, or picked from the built-in ones. */
|
||||
export const PROPERTY_PARAM: PropertyDef = {
|
||||
key: 'property',
|
||||
label: 'Property',
|
||||
kind: 'text',
|
||||
default: 'width',
|
||||
suggestions: OBJECT_PROPERTY_SUGGESTIONS,
|
||||
};
|
||||
|
||||
export const exec = (key = 'exec', label = ''): PortDef => ({ key, label, type: 'exec' });
|
||||
export const num = (key: string, label = key): PortDef => ({ key, label, type: 'number' });
|
||||
export const bool = (key: string, label = key): PortDef => ({ key, label, type: 'boolean' });
|
||||
|
||||
@@ -1,24 +1,72 @@
|
||||
import { OBJECT_PROPERTIES, type PropertyDef } from '../properties/PropertySchema';
|
||||
import type { DeclaredPort } from './Graph';
|
||||
import { ASSET_TYPE_LABELS } from '../model/AssetTypes';
|
||||
import { type PropertyBag, textOf } from '../model/Properties';
|
||||
import { type PropertyDef, type PropertySchema, schemaFor } from '../properties/PropertySchema';
|
||||
import type { DeclaredPort, GraphNode } from './Graph';
|
||||
import type { BehaviorLookup } from './lookup';
|
||||
import { portDefOf } from './nested';
|
||||
import { type PortDef, withInlineDefault } from './NodeRegistry';
|
||||
import { portKindOf } from './variablePorts';
|
||||
|
||||
export function objectPropertyDef(key: string): PropertyDef | undefined {
|
||||
return OBJECT_PROPERTIES.find((def) => def.key === key);
|
||||
}
|
||||
|
||||
export function propertyPortOf(def: PropertyDef): DeclaredPort {
|
||||
return { key: def.key, kind: portKindOf(def) };
|
||||
}
|
||||
/** Keys no behavior variable is likely to have: a port cannot take a setting's key (`fixedPortKeys`). */
|
||||
export const OBJECT_TYPE_PARAM = 'objectType';
|
||||
export const OBJECT_BEHAVIOR_PARAM = 'objectBehavior';
|
||||
|
||||
/**
|
||||
* A port naming a built-in property carries its def: a typed-in value starts at its default and is
|
||||
* edited with its field. A custom name, or a kind the property does not travel as, stays plain.
|
||||
* What a Properties node offers ports from. Textures and scenes are not objects in a running game,
|
||||
* so there is nothing to hand the node for them.
|
||||
*/
|
||||
export function propertyPort(port: DeclaredPort): PortDef {
|
||||
export const PROPERTY_TARGETS = [
|
||||
'any',
|
||||
'sprite',
|
||||
'text',
|
||||
'collider',
|
||||
'camera',
|
||||
'container',
|
||||
'behavior',
|
||||
] as const;
|
||||
export type PropertyTarget = (typeof PROPERTY_TARGETS)[number];
|
||||
|
||||
export function targetLabel(target: PropertyTarget): string {
|
||||
return target === 'any' ? 'Any' : ASSET_TYPE_LABELS[target];
|
||||
}
|
||||
|
||||
export const OBJECT_TYPE_SETTING: PropertyDef = {
|
||||
key: OBJECT_TYPE_PARAM,
|
||||
label: 'Type',
|
||||
kind: 'enum',
|
||||
default: 'any',
|
||||
options: PROPERTY_TARGETS.map((value) => ({ value, label: targetLabel(value) })),
|
||||
};
|
||||
|
||||
export const OBJECT_BEHAVIOR_SETTING: PropertyDef = {
|
||||
key: OBJECT_BEHAVIOR_PARAM,
|
||||
label: 'Behavior',
|
||||
kind: 'asset',
|
||||
default: '',
|
||||
assetTypes: ['behavior'],
|
||||
};
|
||||
|
||||
export function propertyTargetOf(params: PropertyBag): PropertyTarget {
|
||||
const value = textOf(params[OBJECT_TYPE_PARAM] ?? '');
|
||||
return (PROPERTY_TARGETS as readonly string[]).includes(value) ? (value as PropertyTarget) : 'any';
|
||||
}
|
||||
|
||||
/** A behavior's own variables come on top of these, from its asset. */
|
||||
export function targetProperties(target: PropertyTarget): PropertySchema {
|
||||
return target === 'any' ? [] : schemaFor(target);
|
||||
}
|
||||
|
||||
/** Carries the def its type has under that key (default, field); under Any or at another kind, none. */
|
||||
export function propertyPort(port: DeclaredPort, params: PropertyBag): PortDef {
|
||||
const plain = withInlineDefault(portDefOf(port));
|
||||
const field = objectPropertyDef(port.key);
|
||||
const field = targetProperties(propertyTargetOf(params)).find((def) => def.key === port.key);
|
||||
if (!field || portKindOf(field) !== port.kind) return plain;
|
||||
return { ...plain, field, default: field.default };
|
||||
}
|
||||
|
||||
export function propertiesTitle(node: GraphNode, behaviors: BehaviorLookup): string {
|
||||
const target = propertyTargetOf(node.params);
|
||||
if (target === 'any') return 'Properties';
|
||||
const behavior = target === 'behavior' ? behaviors(textOf(node.params[OBJECT_BEHAVIOR_PARAM] ?? '')) : null;
|
||||
return `${behavior?.name ?? targetLabel(target)} properties`;
|
||||
}
|
||||
Reference in new issue
Block a user