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
fix(editor): two questions about a component that had no honest answer
yhh993c4ec130e8
diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex 95ec308f1..5085be88b 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -176,7 +176,9 @@ export const TOOLS = [schema: obj({ clientX: { type: 'number' }, clientY: { type: 'number' } }, ['clientX', 'clientY']),method: 'pick', args: (i) => [i.clientX, i.clientY] },{ name: 'set_run_mode',- description: 'Enter or leave play mode (playing=true runs gameplay; Stop rebuilds the edit World).',+ description: 'Run gameplay against the EDIT World (Stop rebuilds it from the model). This is the headless host\'s play; '+ + "in the editor app the project's scripts live in the play realm and not in this World, so there it refuses and names toggle_play — "+ + 'which is the one to reach for when the question is "does the game work".',schema: obj({ playing: { type: 'boolean' }, paused: { type: 'boolean' } }, ['playing']),method: 'setRunMode', args: (i) => [i.playing, i.paused] },{ name: 'step',diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.tsindex 535e9e660..8009ec230 100644--- a/desktop/src/engine/EditorControlSurface.ts+++ b/desktop/src/engine/EditorControlSurface.ts@@ -314,6 +314,21 @@ export class EditorControlSurfaceImpl {* boundary: EngineHost handles the pure engine flip, the session the rebuild.*/setRunMode(playing: boolean, paused = false): boolean {+ // In the EDITOR APP this door cannot do what its name promises. The game's+ // scripts are bundled into the play realm, never into the edit World this+ // flips, so "playing" here starts a world with no gameplay in it — and the+ // honest `false` it returned (it means "no Stop rebuild happened", not+ // "failed") reads as a refusal, so a caller retries, then reaches for+ // toggle_play, and by then both notions of play are half-on. Say which door+ // it is. The headless host has no realm and keeps this one.+ if (typeof window !== 'undefined' && '__estellaEditor' in window) {+ throw new Error(+ 'set_run_mode drives the edit World, which does not have the project\'s game scripts — '+ + "in the editor they are bundled into the play realm. Use toggle_play to run the game "+ + '(get_play_state reports it, screenshot sees it), and step() to advance the edit World '+ + 'a frame without playing.',+ );+ }const wasStop = EngineHost.setRunMode(playing, paused);if (wasStop) this.s.reconciler.rebuildWorld();return wasStop;@@ -616,6 +631,20 @@ export class EditorControlSurfaceImpl {if (!component) {return modelAddableComponentEntries({ id: 0, name: '', parent: null, children: [], components: [] });}+ // A name nothing declares used to answer `[]` — which reads as "that component+ // has no fields", not "there is no such component". A driver that asked about+ // the component it was ABOUT to write took the empty list for a description+ // and carried on. Refuse in the same words the add door uses, so the two+ // answers about one missing schema cannot disagree.+ if (!componentByName(component) && !userSchema(component)) {+ throw new Error(+ `no component schema named "${component}" — nothing declares it, so there are no fields to `+ + "describe. Call describe_component with no arguments for the list of what does exist. A "+ + "project's own components are picked up from its declaration script (src/components.ts by "+ + 'default, or `scripts.register` in project.esproject): define it there with defineComponent, '+ + 'or import the file that does, and it becomes describable.',+ );+ }return inspectorFields(component, {});}getFieldValue(entity: EntityId, component: string, key: string): InspectorFieldValue | null {diff --git a/desktop/tests/editor-control-surface.test.ts b/desktop/tests/editor-control-surface.test.tsindex cd441a460..57eca970b 100644--- a/desktop/tests/editor-control-surface.test.ts+++ b/desktop/tests/editor-control-surface.test.ts@@ -153,6 +153,17 @@ describe.skipIf(!HAS_WASM)('EditorControlSurface (headless World)', () => {expect(() => S.surface.setField(id, 'Sprite', 'size', 'vec2', 'garbage')).toThrow(/expects/);});+ it('describeComponent refuses a name nothing declares, rather than answering "no fields"', () => {+ // The empty list was indistinguishable from a real component with nothing on+ // it, so a caller asking about the component it was about to write read the+ // answer as a description and carried on.+ expect(S.surface.describeComponent('Sprite').length).toBeGreaterThan(0);+ expect(() => S.surface.describeComponent('ChessPiece')).toThrow(/no component schema named/);+ expect(() => S.surface.describeComponent('ChessPiece')).toThrow(/defineComponent/);+ // No name at all is still the catalog, not a refusal.+ expect(S.surface.describeComponent().length).toBeGreaterThan(0);+ });+it('setField writes ONE member of a structural field, leaving the rest', () => {const id = S.surface.addEntity()!;S.surface.addComponent(id, 'Sprite');