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>
72 lines
2.4 KiB
JavaScript
72 lines
2.4 KiB
JavaScript
/**
|
||
* Small factories for writing project documents by hand (the seed scripts). They produce the
|
||
* exact shape `src/core/store/serialize.ts` reads; optional fields get their defaults.
|
||
*/
|
||
|
||
/** A scene object (also a container template entry). Position defaults to the origin. */
|
||
export const sceneObject = (
|
||
id,
|
||
assetId,
|
||
{ name = '', x = 0, y = 0, z = 0, overrides = {}, parentId = '', instanceEdits, editorOffset } = {},
|
||
) => ({
|
||
id,
|
||
assetId,
|
||
name,
|
||
position: { x, y, z },
|
||
overrides,
|
||
parentId,
|
||
...(instanceEdits ? { instanceEdits } : {}),
|
||
...(editorOffset ? { editorOffset } : {}),
|
||
});
|
||
|
||
/**
|
||
* The id an object of a placed container resolves to: `<instance>~<template ids>`. A placed
|
||
* container stores nothing but itself, so this is how its content is addressed – in the editor,
|
||
* in a running game and in the check scripts alike (see `src/core/model/instance.ts`).
|
||
*/
|
||
export const instanceChild = (instanceId, ...templatePath) => `${instanceId}~${templatePath.join('/')}`;
|
||
|
||
export const edge = (id, from, fromPort, to, toPort) => ({
|
||
id,
|
||
from: { node: from, port: fromPort },
|
||
to: { node: to, port: toPort },
|
||
});
|
||
|
||
/** A graph node; `params` holds settings and inline input values alike. `ports` only on the types that declare them. */
|
||
export const node = (id, type, x, y, params = {}, ports) => ({
|
||
id,
|
||
type,
|
||
x,
|
||
y,
|
||
params,
|
||
...(ports ? { ports } : {}),
|
||
});
|
||
|
||
/** A port a node declares: an input of a start node, a field of a struct, a variable read by `Variables`. */
|
||
export const port = (key, kind) => ({ key, kind });
|
||
|
||
/** A variable a `Variables` node writes as well as reads. */
|
||
export const written = (key, kind) => ({ key, kind, write: true });
|
||
|
||
/** The settings of a `Properties` node: the object type it offers ports from, and for `behavior` which one. */
|
||
export const propertiesOf = (objectType, objectBehavior) => ({
|
||
objectType,
|
||
...(objectBehavior ? { objectBehavior } : {}),
|
||
});
|
||
|
||
/**
|
||
* A behavior variable declaration. `items` is the item kind of a `list`, `fields` the shape of a
|
||
* `struct` – or of the items of a `list` whose items are structs.
|
||
*/
|
||
export const variable = (key, kind, value, items, fields) => ({
|
||
key,
|
||
label: key,
|
||
kind,
|
||
default: value,
|
||
...(items ? { items } : {}),
|
||
...(fields ? { fields } : {}),
|
||
});
|
||
|
||
/** A struct field declaration, and the same shape a list of structs declares for its items. */
|
||
export const field = (key, kind = 'number') => ({ key, kind });
|