A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(mcp): a driver can wire a button, and an unknown component is refused
yhh78ef9859f672
diff --git a/desktop/scripts/editor-mcp-tools.mjs b/desktop/scripts/editor-mcp-tools.mjsindex 1d7276c4f..1bb0d6094 100644--- a/desktop/scripts/editor-mcp-tools.mjs+++ b/desktop/scripts/editor-mcp-tools.mjs@@ -104,6 +104,16 @@ export const TOOLS = [description: 'Remove a component from an entity by schema name. Undoable.',schema: obj({ entity: { type: 'number' }, component: { type: 'string' } }, ['entity', 'component']),method: 'removeComponent', args: (i) => [i.entity, i.component] },+ { name: 'get_event_bindings',+ description: "An entity's authored event wires: rows of { event, action, arg?, params?, target?, guard?, once?, enabled? } — the data form of \"when this button is clicked, run that action\".",+ schema: obj({ entity: { type: 'number' } }, ['entity']),+ method: 'getEventBindings', args: (i) => [i.entity] },+ { name: 'set_event_bindings', write: true,+ description: 'Replace an entity\'s authored event wires in ONE undo step (an empty list unwires it). This is how a button gets behaviour without code: `[{"event":"click","action":"panel.open","params":{"prefab":"assets/prefabs/Shop.esprefab"}}]`. '+ + '`action` is any name in the action registry — the engine\'s built-ins (property.set, ui.setVisible, fsm.fire…) or one the project registered — and `target` names another entity to run it on (nearest-first from this one). '+ + 'EventBinding has no Add Component entry; this is its door.',+ schema: obj({ entity: { type: 'number' }, rows: { type: 'object', description: 'array of wire rows' } }, ['entity', 'rows']),+ method: 'setEventBindings', args: (i) => [i.entity, i.rows] },{ name: 'set_entity_xy', write: true,description: 'Move an entity to a world position (x, y) — converts to parent-local under the hood (undoable).',schema: obj({ id: { type: 'number' }, x: { type: 'number' }, y: { type: 'number' } }, ['id', 'x', 'y']),diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.tsindex 5946312cb..8a7abf506 100644--- a/desktop/src/engine/EditorControlSurface.ts+++ b/desktop/src/engine/EditorControlSurface.ts@@ -23,10 +23,10 @@ import type {InspectorFieldValue,SceneNode,} from '@/types';-import type { SceneData, PrefabData, SubsystemStatus } from 'esengine';+import type { SceneData, PrefabData, SubsystemStatus, EventBindingRow } from 'esengine';import { Material, Sprite, Renderer } from 'esengine';import { EngineHost } from './EngineHost';-import { isRequiredEmpty } from './schema';+import { isRequiredEmpty, componentByName, userSchema } from './schema';import { ViewportController } from './ViewportController';import { PerfMonitor, type PerfSnapshot, type FrameSample, type SessionCapture } from './PerfMonitor';import type { SceneCommandsImpl, EditorTransaction } from './SceneCommands';@@ -373,10 +373,35 @@ export class EditorControlSurfaceImpl {}this.s.commands.setField(entity, component, key, declared, coerceFieldValue(declared, key, value, field?.options));}- /** Add a component (by schema name) to an entity — the Details "Add Component" door. */+ /**+ * Add a component (by schema name) to an entity — the Details "Add Component" door.+ *+ * A name with no schema is REFUSED rather than skipped: the add already needs the+ * schema for its default data, so an unknown name simply produced nothing, and a+ * caller that then wrote a field got "component X is not on entity" about a+ * component it believed it had just added.+ */addComponent(entity: EntityId, component: string): void {+ if (!componentByName(component) && !userSchema(component)) {+ throw new Error(+ `no component schema named "${component}" — the editor cannot add it. `+ + 'Authored-wire components (EventBinding) have their own doors: setEventBindings.',+ );+ }this.s.commands.addComponent(entity, component);}+ /** An entity's authored event wires (EventBinding rows). */+ getEventBindings(entity: EntityId): EventBindingRow[] {+ return this.s.commands.eventBindings(entity);+ }+ /**+ * Replace an entity's authored event wires in one undo step — the data form of+ * "when this button is clicked, run that action". The Details Events section adds+ * them one at a time; an importer converting a whole panel's wiring wants the list.+ */+ setEventBindings(entity: EntityId, rows: readonly EventBindingRow[]): void {+ this.s.commands.setEventBindings(entity, rows);+ }/** Remove a component from an entity. */removeComponent(entity: EntityId, component: string): void {this.s.commands.removeComponent(entity, component);diff --git a/desktop/src/engine/SceneCommands.ts b/desktop/src/engine/SceneCommands.tsindex 4ed034bd8..4c4bf004c 100644--- a/desktop/src/engine/SceneCommands.ts+++ b/desktop/src/engine/SceneCommands.ts@@ -1800,6 +1800,19 @@ export class SceneCommandsImpl {this.writeEventRows(id, 'Remove Event Wire', this.eventRowsOf(id).filter((_, i) => i !== index));}+ /** Replace an entity's whole wire list in ONE undo step — for a caller that+ * authored the rows elsewhere (an importer converting another engine's button+ * wiring), where appending them one at a time would be N undo steps of a thing+ * the user did once. An empty list drops the component. */+ setEventBindings(id: EntityId, rows: readonly EventBindingRow[]): void {+ this.writeEventRows(id, 'Set Event Wires', rows.map((r) => ({ ...r })));+ }++ /** An entity's authored wires (a copy). */+ eventBindings(id: EntityId): EventBindingRow[] {+ return this.eventRowsOf(id).map((r) => ({ ...r }));+ }+/** Set (or clear, with undefined) one gear binding's page-change transition. Undoable. */setGearTween(id: EntityId, controller: string, component: string, property: string, tween?: GearTween): void {const cur = this.gearBindingsOf(id);