- Graph: nodes.ts split into nodes/<category>/<Type>.ts (62 files) with shared.ts factories and index.ts registry; NodeContext/values/NodeRegistry separated, writeTyped() replaces duplicated typed writes - Comments: one style (JSDoc on non-obvious exports, // for decisions and traps), wrong/stale comments fixed or removed, ids.ts now real 10 base-36 chars - Core: chainOf, shared worldPosition/editorPosition core, commands/require.ts, commands/naming.ts, util/list.ts, setBagValue/toPosition/propDef; dead code removed (isBehaviorAsset, SCENE_OBJECT_SCHEMA, CommandStack.subscribe, Input.axis, setMode, titleText, World.worldPosition, unused ctor params) - Editor: Inspector split into inspector/ sections, App.ts into Editor.ts + debugHook.ts + shortcuts.ts, Viewport into items.ts + symbols.ts, shared "Add collider" action, unified type labels/swatches - UI toolkit: Widget.trackHover/onPointerRelease, drawControlBox, math helpers, Popup.openBelow, Menu/Dialog/ColorPicker/ListRow in own files, named Theme sizes - Tools: seed-demo/smoke-demo and demo-check project removed, tools/lib (harness, projects, builders), e2e.mjs as runner over tools/e2e/*.mjs sections - Tests: tests/helpers.ts replaces copied fixtures and NodeContext doubles Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
51 lines
2.2 KiB
JavaScript
51 lines
2.2 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 = '', templateId = '', editorOffset } = {}) => ({
|
|
id,
|
|
assetId,
|
|
name,
|
|
position: { x, y, z },
|
|
overrides,
|
|
parentId,
|
|
templateId,
|
|
...(editorOffset ? { editorOffset } : {}),
|
|
});
|
|
|
|
/** 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. */
|
|
export const node = (id, type, x, y, params = {}) => ({ id, type, x, y, params });
|
|
|
|
/** A behavior variable declaration. */
|
|
export const variable = (key, kind, value) => ({ key, label: key, kind, default: value });
|
|
|
|
/**
|
|
* Instantiation of container templates the way the editor does it (`instantiateContainer`):
|
|
* `templates` maps container asset ids to their template objects.
|
|
*
|
|
* expand(assetId, hostId) copies of the template, parented below `hostId`
|
|
* instantiate(id, assetId, options) the container object plus its expanded content
|
|
*
|
|
* A template object that is itself a container is expanded in turn, unless the template already
|
|
* spells its content out. Copies remember their template id.
|
|
*/
|
|
export function containerFactory(templates) {
|
|
const expand = (assetId, hostId) => {
|
|
const template = templates[assetId];
|
|
const objects = [];
|
|
for (const t of template) {
|
|
const id = `${hostId}-${t.id}`;
|
|
objects.push({ ...t, id, parentId: t.parentId ? `${hostId}-${t.parentId}` : hostId, templateId: t.id });
|
|
if (templates[t.assetId] && !template.some((o) => o.parentId === t.id)) objects.push(...expand(t.assetId, id));
|
|
}
|
|
return objects;
|
|
};
|
|
const instantiate = (id, assetId, options = {}) => [sceneObject(id, assetId, options), ...expand(assetId, id)];
|
|
return { expand, instantiate };
|
|
}
|