Files
feuerwerk/tools/lib/builders.mjs
T
rootandClaude Opus 5 3ed8b68ecf Describe every value kind in one table instead of spreading it over the code
A kind like colour or texture used to be spelled out in five parallel
lists, its port type, its empty value, its glyph, its label and its list
tag - 22 literal places for texture alone. core/properties/kinds.ts now
holds one row per kind and the rest is derived from it, so adding a kind
is one row. The five literal nodes collapse into literals.ts, the six
kind menus into one helper.

Number, Text, Boolean is now the one order everywhere; the variable and
port menus used to list Boolean before Text.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-12 14:47:17 +02:00

77 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 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. `fields` is the shape of a `struct`; a `list` declares nothing,
* its items each carry their own kind (a colour or a texture as `tagged`).
*/
export const variable = (key, kind, value, fields) => ({
key,
label: key,
kind,
default: value,
...(fields ? { fields } : {}),
});
/** A struct field declaration. */
export const field = (key, kind = 'number') => ({ key, kind });
/**
* A list item of a kind JSON cannot show: inside a list a colour would be a plain number and a
* texture id a plain text, so it wears its kind as a tag – `{ $color: 0xff0000 }`.
*/
export const tagged = (kind, value) => ({ [`$${kind}`]: value });