Consolidate duplicated editor code, trim comments, refresh README

Split GraphCanvas (1076 -> 831 lines) into EdgeLayer and graphMenus;
the port and marker menus were the same list and are now one function.
Value specs of the inspector and the list tab share valueSpecs.ts, and
the remaining copies (compound commands, type glyphs, typed asset
lookup, name rule, play/editor world setup, marquee) are merged.

Four copies had already drifted apart; merging them fixes:
- "Disconnect N links" in the port menu is one undo step, not N
- "+ Add collider" is hidden on a placed container instance, as in
  the hierarchy menu, instead of always failing
- a bool property coerced from the text "false" becomes false
- a port command on an unknown node type reports instead of crashing

Comment-only edits leave the bundle byte-identical. README corrected in
35 places (step limit, jump-run clock, suite duration, 409 body, ...).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
rootandClaude Opus 5 committed 2026-09-11 11:00:30 +02:00
1 parent 9212e61c4c
commit 8f92a06c84
96 files changed
+999 -1261

No files matched your search

+1 -2
View File
@@ -121,8 +121,7 @@ describe('assetRefChoices', () => {
});
describe('node asset params', () => {
// Guards against the old second notion of an asset reference: an enum with empty options
// that the graph inspector filled in.
// An asset param uses the asset kind, never an enum with empty options filled in by the inspector.
it('use the asset kind and offer every placeable asset', () => {
const params = BUILT_IN_NODES.flatMap((def) => def.params).filter((p) => p.key === 'asset');
expect(params.length).toBeGreaterThan(0);
+1 -2
View File
@@ -217,8 +217,7 @@ describe('move and slide', () => {
if (i > 60) expect(blockedY).toBe(true);
}
expect(crateA.y).toBeGreaterThan(240 - SKIN);
// A step larger than the obstacle used to jump clean over it: after the move nothing
// overlapped any more, so nothing pushed back and the mover was through the wall.
// A step larger than the obstacle must not jump over it: past the wall nothing overlaps to push back.
crateA.y = 0;
expect(collisions.moveAndSlide(world, crateA, 0, 5000)).toEqual({ blockedX: false, blockedY: true });
expect(crateA.y).toBeCloseTo(240, 6);
+1 -4
View File
@@ -81,10 +81,7 @@ describe('a Sequence sized by what is plugged into it', () => {
});
});
/**
* The point of a struct: a bundle crosses a behavior boundary on ONE edge. Tetris carries the same
* state today as eight parallel ports wired by hand, which is the pain this replaces.
*/
/** The point of a struct: a bundle crosses a behavior boundary on ONE edge. */
describe('a struct travelling through a nested behavior', () => {
it('goes in as one port and comes back out as its parts', () => {
const fixture = makeProject();
+14 -4
View File
@@ -4,9 +4,9 @@ import { SetOverrideCommand } from '../../src/core/commands/sceneObjectCommands'
import { sameValue, textOf } from '../../src/core/model/Properties';
import { findAsset, objectHolders, type Project } from '../../src/core/model/Project';
import { deserializeProject } from '../../src/core/store/serialize';
import { coerceValue, variableDef } from '../../src/core/properties/PropertySchema';
import { coerceField, coerceValue, variableDef } from '../../src/core/properties/PropertySchema';
import { deviatesFromAsset } from '../../src/core/properties/resolve';
import { asEntity, asStruct, writeTyped } from '../../src/core/graph';
import { asBoolean, asEntity, asStruct, writeTyped } from '../../src/core/graph';
import { fakeEntity, makeBehavior, makeSpriteScene, place, roundTrip } from '../helpers';
const findObject = (project: Project, id: string) =>
@@ -28,8 +28,7 @@ describe('a list as a value', () => {
});
it('survives inside a container instance too, where no schema is there to coerce it', () => {
// Instance edits are read from an untyped slot: the old filter kept number/string/boolean and
// dropped everything else, which would have swallowed the list without a word.
// Instance edits are read from an untyped slot, so a primitives-only filter would drop the list silently.
const loaded = deserializeProject(
{
name: 'P',
@@ -139,3 +138,14 @@ describe('a struct as a value', () => {
expect(bag.piece).toEqual({ x: 1 });
});
});
describe('a yes/no written as text', () => {
it('reads its spelling the same in a property, a struct field and a graph', () => {
const spellings = ['false', ' No ', '0', '', 'true', 'yes'];
const expected = [false, false, false, false, true, true];
const def = variableDef('on', 'boolean', true);
expect(spellings.map((s) => coerceValue(def, s))).toEqual(expected);
expect(spellings.map((s) => coerceField(s, 'boolean'))).toEqual(expected);
expect(spellings.map((s) => asBoolean(s))).toEqual(expected);
});
});
+8
View File
@@ -261,6 +261,14 @@ describe('declared ports', () => {
expect(runOnStart(fixture, caller, { result: 0 }).ctx.variables.result).toBe(6);
});
it('a node of an unknown type is refused with a CommandError, which the editor turns into a notice', () => {
const fixture = makeProject();
const behavior = makeBehavior(fixture);
const ports = [{ key: 'a', kind: 'number' as const }];
behavior.graph.nodes.push({ id: 'n', type: 'NoSuchNode', x: 0, y: 0, params: {}, ports });
expect(() => new RemovePortCommand(behavior.id, 'n', 'a').execute(fixture.project)).toThrow(CommandError);
});
it('removing one takes the edges hanging on it, in both graphs, and undo brings them back', () => {
const fixture = makeProject();
const callee = doubler(fixture);
+8 -8
View File
@@ -55,7 +55,7 @@ const pointer = (overrides: Partial<NodeContext['pointer']>): Partial<NodeContex
});
const CASES: Record<string, Case[]> = {
// --- flow ------------------------------------------------------------------------------------
// flow
Branch: [
{ name: 'true takes then', inputs: { condition: true }, next: 'then' },
@@ -103,7 +103,7 @@ const CASES: Record<string, Case[]> = {
},
],
// --- variables -------------------------------------------------------------------------------
// variables
GetVariable: [
{ name: 'reads a variable', params: { variable: 'speed' }, outputs: { value: 100 } },
@@ -151,7 +151,7 @@ const CASES: Record<string, Case[]> = {
},
],
// --- references and properties ----------------------------------------------------------------
// references and properties
Self: [{ name: 'outputs the behavior object', outputs: { object: fakeContext().self } }],
Owner: [
@@ -237,7 +237,7 @@ const CASES: Record<string, Case[]> = {
},
],
// --- literals and math -------------------------------------------------------------------------
// literals and math
Number: [
{ name: 'outputs its setting', params: { value: 7.5 }, outputs: { value: 7.5 } },
@@ -306,7 +306,7 @@ const CASES: Record<string, Case[]> = {
},
],
// --- text and comparison -----------------------------------------------------------------------
// text and comparison
ToText: [
{ name: 'formats with decimals', inputs: { value: 12.345, decimals: 1 }, outputs: { text: '12.3' } },
@@ -334,7 +334,7 @@ const CASES: Record<string, Case[]> = {
outputs: { text: 'b' },
},
],
// --- lists -----------------------------------------------------------------------------------
// lists
List: [
{ name: 'hands out the list it was given', params: { value: [1, 2, 3] }, outputs: { value: [1, 2, 3] } },
@@ -461,7 +461,7 @@ const CASES: Record<string, Case[]> = {
{ name: '"0" as text counts as false', inputs: { value: '0' }, outputs: { result: true } },
],
// --- vectors and input --------------------------------------------------------------------------
// vectors and input
Length: [
{ name: '3-4-5 triangle', inputs: { x: 3, y: 4 }, outputs: { result: 5 } },
@@ -585,7 +585,7 @@ const CASES: Record<string, Case[]> = {
},
],
// --- actions --------------------------------------------------------------------------------------
// actions
Move: [
{
-4
View File
@@ -7,7 +7,6 @@ import {
deviatesFromTemplate,
inheritedValue,
isModified,
isOverridden,
resolveAssetProps,
resolveSceneObjectProps,
} from '../../src/core/properties/resolve';
@@ -70,8 +69,6 @@ describe('resolve', () => {
object.overrides.color = 0x0000ff;
expect(resolveSceneObjectProps(sprite, object).color).toBe(0x0000ff);
expect(isOverridden(object, 'color')).toBe(true);
expect(isOverridden(object, 'width')).toBe(false);
expect(inheritedValue(sprite, 'color')).toBe(0x00ff00);
});
@@ -92,7 +89,6 @@ describe('resolve', () => {
expect(deviatesFromAsset(object, sprite, 'width')).toBe(false); // no override at all
object.overrides.width = 250; // same value as the asset → not a deviation
expect(isOverridden(object, 'width')).toBe(true);
expect(deviatesFromAsset(object, sprite, 'width')).toBe(false);
object.overrides.width = 300;
+1 -1
View File
@@ -68,7 +68,7 @@ describe('cycle-safe walks in the runtime', () => {
expect(worldPositionOf(b)).toEqual({ x: 3, y: 30, z: 0 });
});
// Guards `travelsWith`: before the shared iterator it walked parents without a seen-set and hung here.
// Guards `travelsWith`: a parent walk without a seen-set hangs here.
it('moveAndSlide terminates when a collider sits in a cyclic parent chain', () => {
const f = makeSpriteScene();
const moverId = place(f, f.spriteId, { x: 0, y: 0 });