A variable could only be a number, a text or a yes/no, so every set of values had to be smuggled through a string - which is where Tetris got its unreadable "03066326048763714" colours from. A list is now a value of its own, with an item kind (number, text, yes/no, colour) that decides how the inspector reads the one comma-separated line it is typed as, and eight nodes to work with: List, Fill, Count, Item at, Set item, Sub list, Join lists, Index of. Two traps came with it. An array is typeof 'object', so every place that told a value from an entity had to learn the difference, or a list would have been passed around as a game object. And a value was compared by identity in three places - with lists that marks everything as an overridden property after each reload, so those comparisons now compare contents. There is no list of objects: a list is written to the project file and an object is a live handle that no reload survives. A set of objects stays a list of names. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
1.7 KiB
JavaScript
57 lines
1.7 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('/')}`;
|
||
|
||
/** A graph edge from `from.fromPort` to `to.toPort`. */
|
||
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 start/end. */
|
||
export const node = (id, type, x, y, params = {}, ports) => ({
|
||
id,
|
||
type,
|
||
x,
|
||
y,
|
||
params,
|
||
...(ports ? { ports } : {}),
|
||
});
|
||
|
||
/** A port a behavior's start or end node declares. */
|
||
export const port = (key, kind) => ({ key, kind });
|
||
|
||
/** A behavior variable declaration. `items` is the item kind of a `list`, ignored otherwise. */
|
||
export const variable = (key, kind, value, items) => ({
|
||
key,
|
||
label: key,
|
||
kind,
|
||
default: value,
|
||
...(items ? { items } : {}),
|
||
});
|