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(tilemap): editor-created maps store the .estileset REF, not copies
yhhb785c9e8ed60
diff --git a/desktop/src/tilemap/createTilemap.ts b/desktop/src/tilemap/createTilemap.tsindex d8e2a9e9b..79c301b4c 100644--- a/desktop/src/tilemap/createTilemap.ts+++ b/desktop/src/tilemap/createTilemap.ts@@ -7,10 +7,8 @@* paintable entity, the tileset is the reusable asset it references.*/-import { parseTileset, collidableTileIds } from 'esengine';+import { parseTileset } from 'esengine';import { SceneCommands } from '@/engine/SceneCommands';-import { SceneModel } from '@/engine/SceneModel';-import { EditorHistory } from '@/engine/EditorHistory';import { useSelection } from '@/store/selectionStore';import { useTilemapPaint } from '@/store/tilemapPaintStore';import { ProjectStore } from '@/project/ProjectStore';@@ -32,35 +30,23 @@ export async function createTilemapFromTileset(tilesetPath: string): Promise<voireturn;}- // Preload the atlas texture so the Reconciler resolves its handle and the- // TilemapSyncSystem (which needs a non-zero texture + dims) initializes the layer.- const texInfo = ProjectStore.assetInfo(asset.texture);- if (texInfo) await ProjectStore.assetRefForPath(texInfo.path, 'texture');-const sourceId = SceneCommands.addEntity();if (sourceId == null) return;SceneCommands.addComponent(sourceId, 'TilemapLayer');SceneCommands.beginGesture('Configure Tilemap');+ // cellSize is a per-layer authoring choice SEEDED from the tileset's tile size;+ // everything else — render table (texture/columns), animations, collision —+ // derives LIVE from the .estileset reference (tilemap sync resolves it and calls+ // setTilesets), so editing the tileset updates every map that references it.+ // The old flow copied texture/columns onto the component and baked+ // collidableTileIds into the model: three snapshots that went stale the moment+ // the tileset changed.SceneCommands.setField(sourceId, 'TilemapLayer', 'cellSize', 'vec2', [asset.tileWidth, asset.tileHeight]);- SceneCommands.setField(sourceId, 'TilemapLayer', 'tileset', 'string', asset.texture); // texture @uuid → handle- SceneCommands.setField(sourceId, 'TilemapLayer', 'tilesetColumns', 'number', asset.columns);- // The .estileset link (editor palette restore + T4 runtime collision). Not a C++- // field — carried losslessly in the model like the chunks blob.+ // The .estileset link. Not a C++ field — carried losslessly in the model like+ // the chunks blob, and preloaded via the component's discoverAssets.SceneCommands.setField(sourceId, 'TilemapLayer', 'tilesetAsset', 'string', tilesetRef);SceneCommands.endGesture();- // Bake the tileset's collidable tile ids onto the layer (out-of-band model data the- // runtime reads to spawn colliders — T4). Its own undo step so redo restores it.- const collIds = collidableTileIds(asset);- if (collIds.length > 0) {- SceneModel.setField(sourceId, 'TilemapLayer', 'collidableTileIds', collIds);- EditorHistory.record(- 'Bake Tilemap Collision',- () => SceneModel.setField(sourceId, 'TilemapLayer', 'collidableTileIds', collIds),- () => SceneModel.setField(sourceId, 'TilemapLayer', 'collidableTileIds', []),- );- }-useSelection.getState().select(sourceId);useTilemapPaint.getState().setTileset(tilesetPath);useTilemapPaint.getState().setTool('brush');diff --git a/sdk/src/runtimeLoader.ts b/sdk/src/runtimeLoader.tsindex 357ad3aa3..c11acc3da 100644--- a/sdk/src/runtimeLoader.ts+++ b/sdk/src/runtimeLoader.ts@@ -175,15 +175,20 @@ const PHYSICS_COMPONENT_TYPES = new Set(['SegmentCollider', 'PolygonCollider', 'ChainCollider',]);-/** True if any entity carries a physics component, or a TilemapLayer that will spawn- * colliders at runtime (its baked collidable tiles are invisible to a component scan). */-function sceneUsesPhysics(sceneData: SceneData): boolean {+/** True if any entity carries a physics component, or a TilemapLayer that may spawn+ * colliders at runtime — either baked collidable tile ids (legacy scenes) or a+ * `.estileset` reference, whose collision shapes derive live at load and are+ * invisible to a component scan. A visual-only tileset costs one unused physics+ * module load; missing real tile colliders would break the scene. */+export function sceneUsesPhysics(sceneData: SceneData): boolean {for (const entity of sceneData.entities ?? []) {for (const comp of entity.components ?? []) {if (PHYSICS_COMPONENT_TYPES.has(comp.type)) return true;if (comp.type === 'TilemapLayer') {- const ids = (comp.data as Record<string, unknown> | undefined)?.collidableTileIds;+ const data = comp.data as Record<string, unknown> | undefined;+ const ids = data?.collidableTileIds;if (Array.isArray(ids) && ids.length > 0) return true;+ if (typeof data?.tilesetAsset === 'string' && data.tilesetAsset !== '') return true;}}}diff --git a/sdk/tests/scene-uses-physics.test.ts b/sdk/tests/scene-uses-physics.test.tsnew file mode 100644index 000000000..6c1a9748c--- /dev/null+++ b/sdk/tests/scene-uses-physics.test.ts@@ -0,0 +1,48 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Physics self-gating scan: a scene needs the physics module when it has+ * physics components OR a TilemapLayer that may spawn tile colliders —+ * baked ids (legacy) or a `.estileset` reference whose collision derives+ * live at load. Editor-created tilemaps stopped baking collidableTileIds,+ * so the ref check is what keeps tilemap-only-collision scenes working.+ */+import { describe, it, expect } from 'vitest';+import { sceneUsesPhysics } from '../src/runtimeLoader';+import type { SceneData } from '../src/scene';++function scene(components: Array<{ type: string; data?: Record<string, unknown> }>): SceneData {+ return {+ version: '1.0',+ name: 'test',+ entities: [{ id: 1, name: 'e', parent: null, children: [], components: components.map(c => ({ type: c.type, data: c.data ?? {} })) }],+ };+}++describe('sceneUsesPhysics', () => {+ it('false for a scene with no physics surface', () => {+ expect(sceneUsesPhysics(scene([{ type: 'Sprite' }]))).toBe(false);+ });++ it('true for a physics component', () => {+ expect(sceneUsesPhysics(scene([{ type: 'RigidBody' }]))).toBe(true);+ });++ it('true for a TilemapLayer with baked collidable ids (legacy scenes)', () => {+ expect(sceneUsesPhysics(scene([+ { type: 'TilemapLayer', data: { collidableTileIds: [1, 2] } },+ ]))).toBe(true);+ });++ it('true for a TilemapLayer referencing a .estileset (live-derived collision)', () => {+ expect(sceneUsesPhysics(scene([+ { type: 'TilemapLayer', data: { tilesetAsset: '@uuid:e43a0ed9-50e9-46d8-b1db-da1c549590a8' } },+ ]))).toBe(true);+ });++ it('false for a TilemapLayer with neither ids nor a tileset ref', () => {+ expect(sceneUsesPhysics(scene([+ { type: 'TilemapLayer', data: { collidableTileIds: [], tilesetAsset: '' } },+ ]))).toBe(false);+ });+});