Skip to content

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.

refactor(assets): single-source the .meta type vocabulary; register .estileset

esengine071e1626b943
diff --git a/desktop/electron/assetMeta.ts b/desktop/electron/assetMeta.ts
index 727add970..51936de1d 100644
--- a/desktop/electron/assetMeta.ts
+++ b/desktop/electron/assetMeta.ts
@@ -6,38 +6,24 @@
* orphan-adoption pass — mints through here, so the uuid/version/type/
* importer shape can never diverge between doors.
*
- * The ext→type table mirrors the canonical CLI `tools/asset-meta.js`
- * (meta `type` vocabulary, NOT the SDK's EditorAssetType spellings);
- * kept in sync by hand — a stable lookup table, and keeping this
- * desktop-contained avoids reaching into the root tools/.
+ * The ext→type vocabulary is single-sourced in `tools/assetMetaTable.js`,
+ * shared verbatim with the CLI `tools/asset-meta.js`, so the two mint
+ * doors can never disagree on a file's `.meta` type.
*/
import { writeFile } from 'node:fs/promises';
import { existsSync } from 'node:fs';
import { randomUUID } from 'node:crypto';
-import path from 'node:path';
import { META_EXT } from './contentPolicy';
import { importerDefaults } from '../src/project/assetImporter';
+import { EXT_TO_TYPE, metaTypeForExt } from '../../tools/assetMetaTable.js';
export const META_VERSION = '2.0';
-/** Import/adoption ext → `.meta` type (the meta vocabulary the scan reads). */
-export const EXT_TO_TYPE: Record<string, string> = {
- '.png': 'texture', '.jpg': 'texture', '.jpeg': 'texture', '.webp': 'texture', '.bmp': 'texture',
- '.ktx2': 'texture',
- '.wav': 'audio', '.mp3': 'audio', '.ogg': 'audio', '.aac': 'audio', '.flac': 'audio', '.m4a': 'audio', '.webm': 'audio',
- '.mp4': 'video', '.m4v': 'video', '.mov': 'video',
- '.esprefab': 'prefab', '.esscene': 'scene', '.esshader': 'shader', '.esmaterial': 'material', '.esmat': 'material',
- '.esanim': 'animclip', '.esanimclip': 'animclip', '.estimeline': 'animation',
- '.estileset': 'tileset', '.esfsm': 'statemachine', '.esbt': 'behaviortree', '.eslocale': 'locale',
- '.fnt': 'bitmapFont', '.bmfont': 'bitmapFont', '.ttf': 'font', '.otf': 'font', '.woff': 'font', '.woff2': 'font',
- '.tmx': 'tilemap', '.tmj': 'tilemap',
- '.skel': 'spine', '.atlas': 'spine',
- '.inputmap': 'inputmap',
-};
+export { EXT_TO_TYPE };
/** The meta `type` for a file name/path, or null for unknown extensions. */
export function metaTypeFor(file: string): string | null {
- return EXT_TO_TYPE[path.extname(file).toLowerCase()] ?? null;
+ return metaTypeForExt(file);
}
/** A fresh `.meta` document for an asset of `type`. */
diff --git a/desktop/tests/asset-meta-table.test.ts b/desktop/tests/asset-meta-table.test.ts
new file mode 100644
index 000000000..fe0bcb3da
--- /dev/null
+++ b/desktop/tests/asset-meta-table.test.ts
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+//
+// Guards the single source for the `.meta` type vocabulary. The CLI
+// (tools/asset-meta.js) and the editor mint door (electron/assetMeta.ts) both
+// derive from tools/assetMetaTable.js; they used to hand-mirror it and had
+// drifted (`.esanim` minted as `animation` from the CLI but `animclip` from the
+// editor; `.esanimator` had no CLI entry, so an imported animator controller
+// never got a `.meta`).
+import { describe, it, expect } from 'vitest';
+import { EXT_TO_TYPE, metaTypeFor } from '../electron/assetMeta';
+import { EXT_TO_TYPE as SHARED } from '../../tools/assetMetaTable.js';
+
+describe('.meta type table (single source)', () => {
+ it('the editor mint door re-exports the shared table verbatim', () => {
+ expect(EXT_TO_TYPE).toBe(SHARED);
+ });
+
+ it('mints the canonical type for every engine authoring format', () => {
+ expect(metaTypeFor('x.esanim')).toBe('animclip');
+ expect(metaTypeFor('x.esanimclip')).toBe('animclip');
+ expect(metaTypeFor('x.estimeline')).toBe('animation');
+ expect(metaTypeFor('x.estileset')).toBe('tileset');
+ expect(metaTypeFor('x.estilemap')).toBe('tilemap');
+ expect(metaTypeFor('x.esfsm')).toBe('statemachine');
+ expect(metaTypeFor('x.esbt')).toBe('behaviortree');
+ expect(metaTypeFor('x.eslocale')).toBe('locale');
+ expect(metaTypeFor('x.inputmap')).toBe('inputmap');
+ });
+
+ it('mints a type for an imported .esanimator (regression: was unknown → no meta)', () => {
+ expect(metaTypeFor('player.esanimator')).toBe('animatorcontroller');
+ });
+
+ it('is case-insensitive and null for unknown extensions', () => {
+ expect(metaTypeFor('X.ESANIM')).toBe('animclip');
+ expect(metaTypeFor('notes.txt')).toBeNull();
+ expect(metaTypeFor('README.md')).toBeNull();
+ });
+});
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 7f907c3f7..5c263c91a 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -2328,7 +2328,7 @@ undefineMaterial: (materialId: number) => void
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
- | 'tilemap' | 'timeline'
+ | 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
```
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 00b3b3726..bf6f015b0 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -2323,7 +2323,7 @@ undefineMaterial: (materialId: number) => void
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
- | 'tilemap' | 'timeline'
+ | 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
```
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index a97ce2dfe..416693810 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -2323,7 +2323,7 @@ undefineMaterial: (materialId: number) => void
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
- | 'tilemap' | 'timeline'
+ | 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
```
diff --git a/sdk/src/assetTypes.ts b/sdk/src/assetTypes.ts
index 3a2e08a28..00b73b407 100644
--- a/sdk/src/assetTypes.ts
+++ b/sdk/src/assetTypes.ts
@@ -9,7 +9,7 @@ export type AddressableAssetType =
export type EditorAssetType =
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
- | 'tilemap' | 'timeline'
+ | 'tilemap' | 'tileset' | 'timeline'
| 'unknown';
export type AssetBuildTransform = (content: string, context: unknown) => string;
@@ -54,6 +54,10 @@ const ASSET_TYPE_REGISTRY: readonly AssetTypeEntry[] = [
{ extensions: ['esscene'], contentType: 'json', editorType: 'scene', addressableType: null, wechatPackInclude: false, hasTransitiveDeps: false },
{ extensions: ['esanim'], contentType: 'json', editorType: 'anim-clip', addressableType: null, wechatPackInclude: true, hasTransitiveDeps: true },
{ extensions: ['tmj'], contentType: 'json', editorType: 'tilemap', addressableType: 'json', wechatPackInclude: true, hasTransitiveDeps: true },
+ // Tileset palette (TilesetAssetLoader). Fs-read as JSON at runtime — so it
+ // needs the WeChat pack whitelist — and it references an atlas texture by
+ // @uuid (transitive dep).
+ { extensions: ['estileset'], contentType: 'json', editorType: 'tileset', addressableType: 'json', wechatPackInclude: true, hasTransitiveDeps: true },
{ extensions: ['estimeline'], contentType: 'json', editorType: 'timeline', addressableType: 'json', wechatPackInclude: true, hasTransitiveDeps: true },
// Locale string table (LocaleAssetLoader → Localization.addCatalog) — one locale per file.
{ extensions: ['eslocale'], contentType: 'json', editorType: 'json', addressableType: 'json', wechatPackInclude: true, hasTransitiveDeps: false },
@@ -95,6 +99,7 @@ const MIME_MAP: Record<string, string> = {
esprefab: 'application/json',
esanim: 'application/json',
estimeline: 'application/json',
+ estileset: 'application/json',
eslocale: 'application/json',
esfsm: 'application/json',
esanimator: 'application/json',
diff --git a/sdk/tests/asset-types-tileset.test.ts b/sdk/tests/asset-types-tileset.test.ts
new file mode 100644
index 000000000..5c6073ff4
--- /dev/null
+++ b/sdk/tests/asset-types-tileset.test.ts
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { describe, it, expect } from 'vitest';
+import {
+ getAssetTypeEntry, getEditorType, getAddressableType, isKnownAssetExtension,
+ getCustomExtensions, isCustomExtension,
+} from '../src/assetTypes';
+
+describe('.estileset asset type registration', () => {
+ it('is a known JSON tileset asset', () => {
+ expect(isKnownAssetExtension('estileset')).toBe(true);
+ const entry = getAssetTypeEntry('terrain.estileset');
+ expect(entry?.contentType).toBe('json');
+ expect(entry?.editorType).toBe('tileset');
+ expect(entry?.addressableType).toBe('json');
+ });
+
+ it('resolves its editor / addressable types', () => {
+ expect(getEditorType('a/b/terrain.estileset')).toBe('tileset');
+ expect(getAddressableType('terrain.estileset')).toBe('json');
+ });
+
+ it('is on the WeChat pack whitelist (fs-read at runtime by TilesetAssetLoader)', () => {
+ // A packaged mini-game reads the .estileset via readFileSync; an
+ // extension not on the pack whitelist is denied there.
+ expect(getCustomExtensions()).toContain('.estileset');
+ expect(isCustomExtension('terrain.estileset')).toBe(true);
+ });
+});
diff --git a/tools/asset-meta.js b/tools/asset-meta.js
index 1b47bfe35..69cea59fb 100644
--- a/tools/asset-meta.js
+++ b/tools/asset-meta.js
@@ -27,6 +27,7 @@ import { readdir, stat, readFile, writeFile, access } from 'node:fs/promises';
import { join, extname, basename, relative, resolve } from 'node:path';
import { randomUUID } from 'node:crypto';
import { parseArgs } from 'node:util';
+import { EXT_TO_TYPE } from './assetMetaTable.js';
const META_VERSION = '2.0';
@@ -42,47 +43,8 @@ const SKIP_FILES = new Set([
'.gitkeep', '.gitignore', '.gitattributes',
]);
-// Extension → asset type mapping.
-// Extensions are matched case-insensitively; dot included.
-const EXT_TO_TYPE = Object.freeze({
- // Textures
- '.png': 'texture',
- '.jpg': 'texture',
- '.jpeg': 'texture',
- '.webp': 'texture',
- '.bmp': 'texture',
- // Audio
- '.wav': 'audio',
- '.mp3': 'audio',
- '.ogg': 'audio',
- '.aac': 'audio',
- '.flac': 'audio',
- '.m4a': 'audio',
- '.webm': 'audio',
- // Engine data
- '.esprefab': 'prefab',
- '.esscene': 'scene',
- '.esshader': 'shader',
- '.esmaterial': 'material',
- '.esmat': 'material',
- '.estl': 'timeline',
- '.esanim': 'animation',
- '.esanimclip': 'animation',
- // Fonts
- '.fnt': 'bitmapFont',
- '.bmfont': 'bitmapFont',
- '.ttf': 'font',
- '.otf': 'font',
- '.woff': 'font',
- '.woff2': 'font',
- // Tilemap
- '.tmx': 'tilemap',
- '.tmj': 'tilemap',
- '.estileset': 'tileset',
- // Spine (skel / atlas — .png pair handled by the texture entry)
- '.skel': 'spine',
- '.atlas': 'spine',
-});
+// Extension → `.meta` type is single-sourced in ./assetMetaTable.js (shared
+// with the editor's mint door, desktop/electron/assetMeta.ts).
/**
* Default `importer` settings per type. Shapes match the examples/ meta
diff --git a/tools/assetMetaTable.d.ts b/tools/assetMetaTable.d.ts
new file mode 100644
index 000000000..50f36a4d7
--- /dev/null
+++ b/tools/assetMetaTable.d.ts
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+export const EXT_TO_TYPE: Readonly<Record<string, string>>;
+export function metaTypeForExt(fileOrExt: string): string | null;
diff --git a/tools/assetMetaTable.js b/tools/assetMetaTable.js
new file mode 100644
index 000000000..f5ae24b1d
--- /dev/null
+++ b/tools/assetMetaTable.js
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file assetMetaTable.js
+ * @brief The ONE extension -> `.meta` type table.
+ *
+ * The `.meta` sidecar's `type` field is minted from here by both the CLI
+ * (`tools/asset-meta.js`) and the editor's mint door
+ * (`desktop/electron/assetMeta.ts`). Keeping the two doors on one table is the
+ * point: before this module they were hand-mirrored and had drifted — `.esanim`
+ * minted as `animation` from the CLI but `animclip` from the editor, and
+ * `.esanimator` had no CLI entry at all — so the same file got a different
+ * `type` (or none) depending on which door created it.
+ *
+ * This is deliberately a dependency-free plain-data module: the CLI is raw
+ * `node tools/asset-meta.js` (no build step) and the editor bundles it into the
+ * Electron main process, so neither can pull in TypeScript or the SDK barrel.
+ *
+ * The vocabulary here is the on-disk `.meta` `type` (`animclip`/`animation`/
+ * `statemachine`/…), NOT the SDK's runtime `EditorAssetType` spellings. The
+ * editor maps it to a content-browser slot in ProjectStore.metaTypeToSlot.
+ */
+
+/** Extension (lower-case, dot-included) -> `.meta` type. */
+export const EXT_TO_TYPE = Object.freeze({
+ // Textures
+ '.png': 'texture',
+ '.jpg': 'texture',
+ '.jpeg': 'texture',
+ '.webp': 'texture',
+ '.bmp': 'texture',
+ '.gif': 'texture',
+ '.svg': 'texture',
+ '.ktx2': 'texture',
+ // Audio
+ '.wav': 'audio',
+ '.mp3': 'audio',
+ '.ogg': 'audio',
+ '.aac': 'audio',
+ '.flac': 'audio',
+ '.m4a': 'audio',
+ '.webm': 'audio',
+ // Video
+ '.mp4': 'video',
+ '.m4v': 'video',
+ '.mov': 'video',
+ '.mpg': 'video',
+ '.mpeg': 'video',
+ '.esv': 'video',
+ // Engine data
+ '.esprefab': 'prefab',
+ '.esscene': 'scene',
+ '.esshader': 'shader',
+ '.esmaterial': 'material',
+ '.esmat': 'material',
+ '.esanim': 'animclip',
+ '.esanimclip': 'animclip',
+ '.estimeline': 'animation',
+ '.estileset': 'tileset',
+ '.esfsm': 'statemachine',
+ '.esbt': 'behaviortree',
+ '.esanimator': 'animatorcontroller',
+ '.eslocale': 'locale',
+ '.inputmap': 'inputmap',
+ // Fonts
+ '.fnt': 'bitmapFont',
+ '.bmfont': 'bitmapFont',
+ '.ttf': 'font',
+ '.otf': 'font',
+ '.woff': 'font',
+ '.woff2': 'font',
+ // Tilemap (.estilemap is the editor-native doc; .tmx is import-only, cooked to .tmj)
+ '.estilemap': 'tilemap',
+ '.tmx': 'tilemap',
+ '.tmj': 'tilemap',
+ // Spine (skel / atlas — the .png pair is a plain texture)
+ '.skel': 'spine',
+ '.atlas': 'spine',
+});
+
+/** The `.meta` type for a file name/path, or null for unknown extensions. */
+export function metaTypeForExt(fileOrExt) {
+ const dot = fileOrExt.lastIndexOf('.');
+ const ext = (dot >= 0 ? fileOrExt.slice(dot) : fileOrExt).toLowerCase();
+ return EXT_TO_TYPE[ext] ?? null;
+}