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:
1 parent
9212e61c4c
commit
8f92a06c84
96 files changed
+999
-1261
No files matched your search
@@ -10,10 +10,10 @@ import {
|
||||
import { stepKeyRepeat } from '../../core/graph/keyRepeat';
|
||||
import { behaviorLookup } from '../../core/model/behaviorPrograms';
|
||||
import { type PropertyBag, textOf } from '../../core/model/Properties';
|
||||
import { findAsset, type Project } from '../../core/model/Project';
|
||||
import { findAssetOf, type Project } from '../../core/model/Project';
|
||||
import type { Entity } from '../Entity';
|
||||
import type { World } from '../World';
|
||||
import { bodyOf, type CollisionPair, type CollisionSystem } from './CollisionSystem';
|
||||
import { bodyOf, type CollisionPair, CollisionSystem } from './CollisionSystem';
|
||||
import type { Input } from './Input';
|
||||
import type { System } from './System';
|
||||
|
||||
@@ -36,6 +36,27 @@ interface Instance {
|
||||
* Runs the graph of every behavior entity. Each instance has its own interpreter (and
|
||||
* therefore its own timers and variable state); the project is only read to find graphs.
|
||||
*/
|
||||
const ERROR_PREFIX = 'Error in behavior';
|
||||
|
||||
/** Collisions are detected first, so behaviors see this frame's enter/stay/exit events. */
|
||||
export function addGameSystems(
|
||||
world: World,
|
||||
project: Project,
|
||||
input: Input,
|
||||
shouldRun?: (entity: Entity) => boolean,
|
||||
): BehaviorSystem {
|
||||
const collisions = new CollisionSystem();
|
||||
const behaviors = new BehaviorSystem(project, input, collisions, shouldRun);
|
||||
world.addSystem(collisions);
|
||||
world.addSystem(behaviors);
|
||||
return behaviors;
|
||||
}
|
||||
|
||||
/** The behavior failure that stopped a run, if that is why it stopped. */
|
||||
export function behaviorError(world: World): string | undefined {
|
||||
return world.log.find((line) => line.startsWith(ERROR_PREFIX));
|
||||
}
|
||||
|
||||
export class BehaviorSystem implements System {
|
||||
private instances: Instance[] = [];
|
||||
private world: World | null = null;
|
||||
@@ -64,10 +85,8 @@ export class BehaviorSystem implements System {
|
||||
}
|
||||
|
||||
/**
|
||||
* One instance per behavior entity: entities that appeared (placed while playing) get an
|
||||
* interpreter and their `On start`; instances whose entity is gone are dropped. A behavior
|
||||
* that is switched off has no instance yet – it gets one, and its `On start`, the moment it
|
||||
* is switched on. That is what lets a hidden screen wake up when it is shown.
|
||||
* One instance per behavior entity. A switched-off behavior gets its instance and `On start` only when
|
||||
* switched on, which is what lets a hidden screen wake up when shown.
|
||||
*/
|
||||
private syncInstances(world: World): void {
|
||||
this.instances = this.instances.filter((i) => world.entities.includes(i.entity));
|
||||
@@ -79,8 +98,8 @@ export class BehaviorSystem implements System {
|
||||
this.instances.some((i) => i.entity === entity)
|
||||
)
|
||||
continue;
|
||||
const asset = findAsset(this.project, entity.assetId);
|
||||
if (!asset || asset.type !== 'behavior') continue;
|
||||
const asset = findAssetOf(this.project, entity.assetId, 'behavior');
|
||||
if (!asset) continue;
|
||||
const trace: Trace = { edges: new Map(), nodes: new Map() };
|
||||
const interpreter = new GraphInterpreter(asset.graph, behaviorLookup(this.project));
|
||||
interpreter.trace = {
|
||||
@@ -175,7 +194,6 @@ export class BehaviorSystem implements System {
|
||||
fire('OnCollisionExit', this.collisions.exits);
|
||||
}
|
||||
|
||||
/** Object ids of the behaviors this system is currently running. */
|
||||
runningIds(): string[] {
|
||||
return this.instances.map((i) => i.entity.objectId);
|
||||
}
|
||||
@@ -210,7 +228,7 @@ export class BehaviorSystem implements System {
|
||||
body(instance.interpreter, ctx);
|
||||
} catch (error) {
|
||||
world.log.push(
|
||||
`Error in behavior "${instance.entity.name}": ${error instanceof Error ? error.message : String(error)}`,
|
||||
`${ERROR_PREFIX} "${instance.entity.name}": ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
world.stopRequested = true;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user