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): drop + automation surface reuse the create pipeline (E5)
esengine492b70a78d07
diff --git a/desktop/src/engine/EditorControlSurface.ts b/desktop/src/engine/EditorControlSurface.tsindex 69ed93571..93b2de80d 100644--- a/desktop/src/engine/EditorControlSurface.ts+++ b/desktop/src/engine/EditorControlSurface.ts@@ -23,7 +23,7 @@ import type {NodeKind,SceneNode,} from '@/types';-import type { SceneData, SubsystemStatus } from 'esengine';+import type { SceneData, PrefabData, SubsystemStatus } from 'esengine';import { Material, Sprite, Renderer } from 'esengine';import { EngineHost } from './EngineHost';import { ViewportController } from './ViewportController';@@ -119,6 +119,17 @@ export class EditorControlSurfaceImpl {addEntity(): EntityId | null {return this.s.commands.addEntity();}+ /**+ * Create entities from a template/prefab through the one create pipeline (E5) —+ * so headless/automation can spawn any ready-made entity, not just a blank one.+ * With `linkPrefabRef` the subtree is tagged as a prefab instance.+ */+ create(+ prefab: PrefabData,+ opts: { parent: EntityId | null; position?: { x: number; y: number }; linkPrefabRef?: string },+ ): EntityId | null {+ return this.s.commands.create(prefab, opts);+ }deleteEntity(id: EntityId): void {this.s.commands.deleteEntity(id);}diff --git a/desktop/src/panels/Viewport.tsx b/desktop/src/panels/Viewport.tsxindex e20733ac0..e1e30566e 100644--- a/desktop/src/panels/Viewport.tsx+++ b/desktop/src/panels/Viewport.tsx@@ -19,6 +19,7 @@ import { PlayRealm } from '@/engine/PlayRealm';import { ViewportController } from '@/engine/ViewportController';import { ProjectStore } from '@/project/ProjectStore';import { IMAGE_RE } from '@/project/assetMeta';+import { createTilemapFromTileset } from '@/tilemap/createTilemap';import { SceneModel } from '@/engine/SceneModel';import { SceneCommands } from '@/engine/SceneCommands';import { SceneStore } from '@/engine/SceneStore';@@ -999,7 +1000,8 @@ export function Viewport() {// Drag an asset from the Content Browser into the scene → place it at the drop// point (one undoable step): a `.esprefab` instantiates the prefab; an image- // spawns a Sprite entity sized to the texture.+ // spawns a Sprite entity sized to the texture; a `.estileset` spawns a paintable+ // TilemapLayer.const isAssetDrag = (e: ReactDragEvent) =>e.dataTransfer.types.includes('application/x-estella-asset');@@ -1021,6 +1023,10 @@ export function Viewport() {} else if (IMAGE_RE.test(path)) {e.preventDefault();void ProjectStore.instantiateSpriteFromPath(path, wp ?? { x: 0, y: 0 });+ } else if (path.toLowerCase().endsWith('.estileset')) {+ e.preventDefault();+ // A tileset spawns a paintable TilemapLayer, which wires its own placement + painter.+ void createTilemapFromTileset(path);}};diff --git a/desktop/tests/editor-control-surface.test.ts b/desktop/tests/editor-control-surface.test.tsindex 323146d7c..d390d1a1e 100644--- a/desktop/tests/editor-control-surface.test.ts+++ b/desktop/tests/editor-control-surface.test.ts@@ -14,8 +14,8 @@* App so step() exercises the engine.*/import { describe, it, expect, beforeAll, beforeEach, afterEach, vi } from 'vitest';-import { App, Transform } from 'esengine';-import type { ESEngineModule } from 'esengine';+import { App, Transform, Sprite, migratePrefabData } from 'esengine';+import type { ESEngineModule, PrefabData } from 'esengine';import { loadWasmModule, HAS_WASM } from './helpers/loadWasm';// Per-test state, injected into the mocked EngineHost. `vi.hoisted` so the mock@@ -82,6 +82,17 @@ describe.skipIf(!HAS_WASM)('EditorControlSurface (headless World)', () => {expect(S.surface.getStats().entities).toBe(1);});+ it('create() spawns a ready-made entity into model + World (headless, not just blank)', () => {+ const prefab = migratePrefabData({+ version: '1.0', name: 'Hero', rootEntityId: 'root',+ entities: [{ prefabEntityId: 'root', name: 'Hero', parent: null, children: [], components: [{ type: 'Transform', data: {} }, { type: 'Sprite', data: {} }], visible: true }],+ }).data as PrefabData;+ const id = S.surface.create(prefab, { parent: null })!;+ expect(id).not.toBeNull();+ expect(S.surface.getSceneTree().length).toBe(1);+ expect(host.world.has(S.model.runtimeFor(id)!, Sprite)).toBe(true);+ });+it('setField writes a component field; surface undo reverts it', () => {const id = S.surface.addEntity()!; // source idconst e = S.model.runtimeFor(id)!; // runtime World entity