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(editor): the create door can name a point in space
esenginebe062ba62c11
diff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex 74c7765a8..5e3f6bd88 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -566,15 +566,15 @@ const ATOMS = [+ 'Outline, hit-flash, dissolve, pixelate and UV-scroll are among the ones already here; reaching for a hand-written shader before reading this list is writing one that exists.',schema: obj({}), method: 'listShaderTemplates', args: () => [], root: 'editor' },{ name: 'create_entity', effect: 'undoable',- description: 'Spawn a ready-made entity from a template id (see list_entity_templates) through the same pipeline as the Create menu; returns the new entity id. Optional world position, parent and NAME. '+ description: 'Spawn a ready-made entity from a template id (see list_entity_templates) through the same pipeline as the Create menu; returns the new entity id. Optional world position (x, y and — for a scene with depth — z), parent and NAME. '+ '`name` matters most for a `prefab:<path>` template: without it every instance arrives called whatever the prefab is called, so ten enemies are ten entities you cannot tell apart. '+ 'It is applied as the entity is built (one undo step) and, on an instance, saves as an ordinary name override — the prefab keeps its own name.',schema: obj({template: { type: 'string' }, parent: { type: ['number', 'null'] },- x: { type: 'number' }, y: { type: 'number' }, name: { type: 'string' },+ x: { type: 'number' }, y: { type: 'number' }, z: { type: 'number' }, name: { type: 'string' },}, ['template']),method: 'createEntity',- args: (i) => [i.template, { parent: i.parent ?? null, x: i.x, y: i.y, name: i.name }], root: 'editor' },+ args: (i) => [i.template, { parent: i.parent ?? null, x: i.x, y: i.y, z: i.z, name: i.name }], root: 'editor' },{ name: 'set_play', effect: 'ephemeral',description: "Put the game in a NAMED state and get the one it reached: 'playing', 'paused', or 'stopped'. AWAITED — it resolves once the realm is up (or gone), so there is nothing to poll. "+ "A named state rather than a toggle because a toggle needs you to know where it started, and called twice it is a no-op that reads as a failure. 'paused' from stopped boots the realm and freezes it, which is the state to set up in before stepping. "diff --git a/desktop/src/main.tsx b/desktop/src/main.tsxindex b8ce69c0d..b1b3ec965 100644--- a/desktop/src/main.tsx+++ b/desktop/src/main.tsx@@ -512,13 +512,17 @@ function buildEditorAutomation(): unknown {/** Spawn a ready-made entity through the one create pipeline (menu/DnD parity). */createEntity: async (sourceId: string,- opts?: { parent?: number | null; x?: number; y?: number; name?: string },+ opts?: { parent?: number | null; x?: number; y?: number; z?: number; name?: string },) => {const source = sourceById(sourceId);if (!source) throw new Error(`unknown entity template: ${sourceId} (see listEntityTemplates)`);+ // A point in space, as the viewport's own drop resolves one: z is optional and+ // omitting it keeps the template's own depth, which is what a 2D caller means.return createFromSource(source, {parent: opts?.parent ?? null,- position: opts?.x != null && opts?.y != null ? { x: opts.x, y: opts.y } : undefined,+ position: opts?.x != null && opts?.y != null+ ? { x: opts.x, y: opts.y, ...(opts.z != null ? { z: opts.z } : {}) }+ : undefined,name: opts?.name,});},diff --git a/desktop/tests/scene-create.test.ts b/desktop/tests/scene-create.test.tsindex 07cf57cfd..246de3ad8 100644--- a/desktop/tests/scene-create.test.ts+++ b/desktop/tests/scene-create.test.ts@@ -34,7 +34,7 @@ function widgetPrefab(): PrefabData {const REF = '@uuid:widget-1';const rootPos = (m: SceneModelImpl, id: number) =>- (m.entityBySource(id)!.components.find((c) => c.type === 'Transform')!.data as { position: { x: number; y: number } }).position;+ (m.entityBySource(id)!.components.find((c) => c.type === 'Transform')!.data as { position: { x: number; y: number; z: number } }).position;describe('SceneCommands.create (unified template/prefab birth path)', () => {let model: SceneModelImpl;@@ -79,6 +79,22 @@ describe('SceneCommands.create (unified template/prefab birth path)', () => {expect([p.x, p.y]).toEqual([50, 60]);});+ // A drop point in a 3D view has a depth of its own, and the caller says so.+ it('a drop point with a depth places the root at it', () => {+ const rootId = cmds.create(widgetPrefab(), { parent: null, position: { x: 50, y: 60, z: -140 } })!;+ const p = rootPos(model, rootId);+ expect([p.x, p.y, p.z]).toEqual([50, 60, -140]);+ });++ // Without one, the template keeps the depth it was authored at — which is what+ // every 2D caller means by naming only x and y.+ it('a drop point without one leaves the authored depth alone', () => {+ const prefab = widgetPrefab();+ (prefab.entities[0].components[0].data as { position: { z: number } }).position.z = -7;+ const rootId = cmds.create(prefab, { parent: null, position: { x: 50, y: 60 } })!;+ expect(rootPos(model, rootId).z).toBe(-7);+ });+it('under a parent: the root attaches to the given parent', () => {const parent = cmds.addEntity()!;const rootId = cmds.create(widgetPrefab(), { parent })!;