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(tilemap): create_tilemap answers with the entity it made, or says it made none
yhh6d3ff6490e7b
diff --git a/desktop/src/main.tsx b/desktop/src/main.tsxindex bdb323c13..3a7820877 100644--- a/desktop/src/main.tsx+++ b/desktop/src/main.tsx@@ -346,7 +346,19 @@ function buildEditorAutomation(): unknown {listEntityTemplates: () => allEntitySources().map(({ id, label, category }) => ({ id, label, category })),/** Create a TilemapLayer from an .estileset with an optional grid layout* (orientation/stagger/hex) — drives the New-Tilemap flow headlessly. */- createTilemap: (tilesetPath: string, grid?: TileGridConfig) => createTilemapFromTileset(tilesetPath, grid),+ // Throws where the UI toasts: a headless caller has no screen to read the+ // toast off, and `ok` for a tilemap that was never created sends it hunting+ // through the scene tree for an entity nobody made.+ createTilemap: async (tilesetPath: string, grid?: TileGridConfig) => {+ const id = await createTilemapFromTileset(tilesetPath, grid);+ if (id == null) {+ throw new Error(+ `could not create a tilemap from "${tilesetPath}" — it is not a tracked .estileset `+ + 'in this project, or it does not parse. list_assets with type "tilemap" shows the ones that are.',+ );+ }+ return id;+ },/** Create a collision (obstacle) layer and return its selected source id — drives the* obstacle-grid flow headlessly (no tileset needed). */createCollisionLayer: async () => { await createCollisionLayer(); return useSelection.getState().selectedId; },diff --git a/desktop/src/tilemap/createTilemap.ts b/desktop/src/tilemap/createTilemap.tsindex 79d913f8f..2daf2d3d7 100644--- a/desktop/src/tilemap/createTilemap.ts+++ b/desktop/src/tilemap/createTilemap.ts@@ -12,6 +12,7 @@import { parseTileset, COLLISION_PALETTE_REF } from 'esengine';import { Grid3x3, Shapes } from 'lucide-react';import { createFromSource, tilemapPrefab, type EntitySource, type TileGridConfig } from '@/engine/entitySources';+import type { EntityId } from '@/types';import { useSelection } from '@/store/selectionStore';import { useTilemapPaint } from '@/store/tilemapPaintStore';import { ProjectStore } from '@/project/ProjectStore';@@ -47,22 +48,32 @@ function tilesetSource(};}-/** Create a TilemapLayer entity referencing the given .estileset, select it, and start- * painting. `grid` sets the orientation/stagger layout (defaults to orthogonal). */-export async function createTilemapFromTileset(tilesetPath: string, grid?: TileGridConfig): Promise<void> {+/**+ * Create a TilemapLayer entity referencing the given .estileset, select it, and start+ * painting. `grid` sets the orientation/stagger layout (defaults to orthogonal).+ *+ * Answers with the new entity, or NULL when it made none — an untracked tileset+ * or one that will not parse. Both used to be a toast and a `return`, which is+ * the right shape for a person watching the screen and no answer at all for a+ * caller that is not: the headless door reported success for a tilemap that+ * does not exist, and the next call went looking for it in the scene tree.+ */+export async function createTilemapFromTileset(+ tilesetPath: string, grid?: TileGridConfig,+): Promise<EntityId | null> {const tilesetRef = ProjectStore.assetRef(tilesetPath); // .estileset → @uuidif (!tilesetRef) {Toasts.push(t('tile.toast.untracked'), 'error');- return;+ return null;}let asset;try {asset = parseTileset(JSON.parse(await window.estella.fs.read(tilesetPath)));} catch (e) {Toasts.push(t('tile.toast.readFailed', { error: String(e) }), 'error');- return;+ return null;}- await createFromSource(+ return createFromSource(tilesetSource(tilesetPath, tilesetRef, asset.tileWidth, asset.tileHeight, grid), { parent: null },);}