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.

feat(cook): a DragonBones atlas keeps the texture it points at

esengine081cdefb1d7e
diff --git a/desktop/electron/assetDb.ts b/desktop/electron/assetDb.ts
index c4cf7c04c..94b93fc33 100644
--- a/desktop/electron/assetDb.ts
+++ b/desktop/electron/assetDb.ts
@@ -127,6 +127,11 @@ async function adoptOrphans(root: string, rel = '', adopted: string[] = []): Pro
*/
// 'animation' covers .estimeline (AnimFrames tracks reference textures) and
// legacy .esanim metas written before the type split to 'animclip'.
+// A skeletal atlas names its page images, and nothing else in the project does —
+// no component references them. Scanned for deps whatever their own asset type is,
+// so the cook keeps the textures instead of shipping an atlas that 404s them.
+const SKELETAL_ATLAS_TYPES = new Set(['spine-atlas', 'dragonbones-atlas']);
+
const JSON_REF_TYPES = new Set([
'scene', 'prefab', 'material', 'tileset', 'tilemap', 'animclip', 'animation', 'statemachine', 'behaviortree',
]);
@@ -221,7 +226,7 @@ async function computeDeps(
const byPath = new Map(entries.map((e) => [e.path, e]));
const uuids = new Set(entries.map((e) => e.uuid));
const refEntries = (targets ?? entries).filter(
- (e) => JSON_REF_TYPES.has(e.type) || getEditorType(e.path) === 'spine-atlas',
+ (e) => JSON_REF_TYPES.has(e.type) || SKELETAL_ATLAS_TYPES.has(getEditorType(e.path)),
);
type DepResult = { uuid: string; refs: string[] } | { warning: string };
const depResults = await mapLimit(refEntries, SCAN_IO_CONCURRENCY, async (entry): Promise<DepResult> => {
@@ -229,6 +234,8 @@ async function computeDeps(
// texture deps — the same edge the SpineAssetLoader walks at runtime. Scan it
// apart from the JSON path so the cook embeds those textures (else the atlas
// ships but its .png is culled and the playable 404s it).
+ // Spine's atlas is a TEXT manifest and needs its own parser; DragonBones'
+ // is JSON, so the generic walk below already finds its `imagePath`.
const isSpineAtlas = getEditorType(entry.path) === 'spine-atlas';
try {
const refs = new Set<string>();
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 4ce64eac0..404851853 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -608,6 +608,7 @@ contentType: AssetContentType
editorType: EditorAssetType
extensions: string[]
hasTransitiveDeps: boolean
+suffixes: string[] | undefined
wechatPackInclude: boolean
```
@@ -2438,6 +2439,7 @@ ui_getRenderOrder: ((registry: CppRegistry, entity: number) => number) | undefin
## EditorAssetType — type
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
+ | 'dragonbones-atlas' | 'dragonbones-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
| 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index f3d7d50e8..882923c00 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -608,6 +608,7 @@ contentType: AssetContentType
editorType: EditorAssetType
extensions: string[]
hasTransitiveDeps: boolean
+suffixes: string[] | undefined
wechatPackInclude: boolean
```
@@ -2446,6 +2447,7 @@ ui_getRenderOrder: ((registry: CppRegistry, entity: number) => number) | undefin
## EditorAssetType — type
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
+ | 'dragonbones-atlas' | 'dragonbones-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
| 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index a31fca112..c300165a5 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -603,6 +603,7 @@ contentType: AssetContentType
editorType: EditorAssetType
extensions: string[]
hasTransitiveDeps: boolean
+suffixes: string[] | undefined
wechatPackInclude: boolean
```
@@ -2433,6 +2434,7 @@ ui_getRenderOrder: ((registry: CppRegistry, entity: number) => number) | undefin
## EditorAssetType — type
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
+ | 'dragonbones-atlas' | 'dragonbones-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
| 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index d30c3978f..503b42f37 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -603,6 +603,7 @@ contentType: AssetContentType
editorType: EditorAssetType
extensions: string[]
hasTransitiveDeps: boolean
+suffixes: string[] | undefined
wechatPackInclude: boolean
```
@@ -2433,6 +2434,7 @@ ui_getRenderOrder: ((registry: CppRegistry, entity: number) => number) | undefin
## EditorAssetType — type
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
+ | 'dragonbones-atlas' | 'dragonbones-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
| 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 4277c5eff..cd088de42 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -603,6 +603,7 @@ contentType: AssetContentType
editorType: EditorAssetType
extensions: string[]
hasTransitiveDeps: boolean
+suffixes: string[] | undefined
wechatPackInclude: boolean
```
@@ -2433,6 +2434,7 @@ ui_getRenderOrder: ((registry: CppRegistry, entity: number) => number) | undefin
## EditorAssetType — type
```
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
+ | 'dragonbones-atlas' | 'dragonbones-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
| 'tilemap' | 'tileset' | 'timeline'
| 'unknown'
diff --git a/sdk/src/assetTypes.ts b/sdk/src/assetTypes.ts
index 00b73b407..a754f459a 100644
--- a/sdk/src/assetTypes.ts
+++ b/sdk/src/assetTypes.ts
@@ -8,6 +8,7 @@ export type AddressableAssetType =
export type EditorAssetType =
| 'texture' | 'material' | 'shader' | 'spine-atlas' | 'spine-skeleton'
+ | 'dragonbones-atlas' | 'dragonbones-skeleton'
| 'bitmap-font' | 'prefab' | 'json' | 'audio' | 'video' | 'scene' | 'anim-clip'
| 'tilemap' | 'tileset' | 'timeline'
| 'unknown';
@@ -16,6 +17,13 @@ export type AssetBuildTransform = (content: string, context: unknown) => string;
export interface AssetTypeEntry {
extensions: string[];
+ /**
+ * Full lower-case name endings claiming this type, checked BEFORE extensions
+ * because they are the more specific claim. For a format whose files are told
+ * apart by convention rather than suffix — DragonBones ships `_ske.json`
+ * beside `_tex.json`, and `.json` alone cannot see the difference.
+ */
+ suffixes?: string[];
contentType: AssetContentType;
editorType: EditorAssetType;
addressableType: AddressableAssetType | null;
@@ -45,6 +53,11 @@ const ASSET_TYPE_REGISTRY: readonly AssetTypeEntry[] = [
{ extensions: ['esshader'], contentType: 'text', editorType: 'shader', addressableType: null, wechatPackInclude: false, hasTransitiveDeps: false },
{ extensions: ['atlas'], contentType: 'text', editorType: 'spine-atlas', addressableType: 'binary', wechatPackInclude: true, hasTransitiveDeps: true },
{ extensions: ['skel'], contentType: 'binary', editorType: 'spine-skeleton', addressableType: 'spine', wechatPackInclude: true, hasTransitiveDeps: true },
+ // DragonBones. The atlas has transitive deps — its `imagePath` names a PNG no
+ // component references, so without that flag the cook ships the atlas and culls
+ // the image it points at, and the export 404s a texture at runtime.
+ { extensions: ['dbbin'], suffixes: ['_ske.json'], contentType: 'binary', editorType: 'dragonbones-skeleton', addressableType: 'binary', wechatPackInclude: true, hasTransitiveDeps: false },
+ { extensions: [], suffixes: ['_tex.json'], contentType: 'text', editorType: 'dragonbones-atlas', addressableType: 'binary', wechatPackInclude: true, hasTransitiveDeps: true },
{ extensions: ['json'], contentType: 'json', editorType: 'json', addressableType: 'json', wechatPackInclude: false, hasTransitiveDeps: false },
// Input map (defineInputMap / loadInputMapAsset) — data-driven key/gamepad bindings.
{ extensions: ['inputmap'], contentType: 'json', editorType: 'json', addressableType: 'json', wechatPackInclude: true, hasTransitiveDeps: false },
@@ -124,6 +137,12 @@ function extractExtension(extensionOrPath: string): string {
}
export function getAssetTypeEntry(extensionOrPath: string): AssetTypeEntry | undefined {
+ // Suffix first: `foo_ske.json` is a DragonBones skeleton, and letting `.json`
+ // answer would classify it as whatever that extension maps to.
+ const lower = extensionOrPath.toLowerCase();
+ for (const entry of ASSET_TYPE_REGISTRY) {
+ if (entry.suffixes?.some((s) => lower.endsWith(s))) return entry;
+ }
return extToEntry.get(extractExtension(extensionOrPath));
}
diff --git a/sdk/tests/dragonbones-asset-type.test.ts b/sdk/tests/dragonbones-asset-type.test.ts
new file mode 100644
index 000000000..377aeb9fc
--- /dev/null
+++ b/sdk/tests/dragonbones-asset-type.test.ts
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+//
+// The classification the cook reads. Getting it wrong is not a crash: the export
+// builds, ships the atlas, and 404s the texture it points at on a device — which
+// is why the transitive-deps flag is asserted rather than assumed.
+import { describe, it, expect } from 'vitest';
+import { getAssetTypeEntry, getEditorType, getAddressableType } from '../src/assetTypes';
+
+describe('DragonBones asset classification', () => {
+ it('tells the two halves apart, which the extension cannot', () => {
+ expect(getEditorType('hero_ske.json')).toBe('dragonbones-skeleton');
+ expect(getEditorType('hero_tex.json')).toBe('dragonbones-atlas');
+ expect(getEditorType('hero.dbbin')).toBe('dragonbones-skeleton');
+ });
+
+ it('is case-insensitive, and only claims the END of a name', () => {
+ expect(getEditorType('Hero_SKE.JSON')).toBe('dragonbones-skeleton');
+ // A backup is not a skeleton.
+ expect(getEditorType('hero_ske.json.bak')).not.toBe('dragonbones-skeleton');
+ });
+
+ it('leaves an ordinary json alone', () => {
+ expect(getEditorType('package.json')).not.toBe('dragonbones-skeleton');
+ expect(getEditorType('package.json')).not.toBe('dragonbones-atlas');
+ });
+
+ it('marks the atlas as carrying transitive deps, and the skeleton as not', () => {
+ // The atlas's `imagePath` names a PNG nothing else in the project points
+ // at. Without this flag the dependency scan skips the file, the cook culls
+ // the image, and the shipped build asks for a texture that is not there.
+ expect(getAssetTypeEntry('hero_tex.json')?.hasTransitiveDeps).toBe(true);
+ expect(getAssetTypeEntry('hero_ske.json')?.hasTransitiveDeps).toBe(false);
+ });
+
+ it('ships both halves inside a WeChat package', () => {
+ // Neither is huge, and a skeleton fetched remotely while its atlas is local
+ // is the kind of split that only fails on a phone.
+ expect(getAssetTypeEntry('hero_ske.json')?.wechatPackInclude).toBe(true);
+ expect(getAssetTypeEntry('hero_tex.json')?.wechatPackInclude).toBe(true);
+ });
+
+ it('leaves Spine classifying exactly as before', () => {
+ expect(getEditorType('hero.atlas')).toBe('spine-atlas');
+ expect(getEditorType('hero.skel')).toBe('spine-skeleton');
+ expect(getAddressableType('hero.skel')).toBe('spine');
+ expect(getEditorType('hero.png')).toBe('texture');
+ });
+});