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: add Catalog generation to build pipeline

esenginee84f9db4e7ab
diff --git a/editor/src/builder/ArtifactBuilder.ts b/editor/src/builder/ArtifactBuilder.ts
index 5c34e2e72..1445347ec 100644
--- a/editor/src/builder/ArtifactBuilder.ts
+++ b/editor/src/builder/ArtifactBuilder.ts
@@ -463,6 +463,101 @@ export function generateAddressableManifest(
return { version: '2.0', groups };
}
+export interface CatalogEntry {
+ type: string;
+ atlas?: string;
+ frame?: { x: number; y: number; w: number; h: number };
+ uv?: { offset: [number, number]; scale: [number, number] };
+ deps?: string[];
+ buildPath?: string;
+}
+
+export interface CatalogJson {
+ version: number;
+ entries: Record<string, CatalogEntry>;
+ addresses: Record<string, string>;
+ labels: Record<string, string[]>;
+}
+
+export function generateCatalog(artifact: BuildArtifact): CatalogJson {
+ const entries: Record<string, CatalogEntry> = {};
+ const addresses: Record<string, string> = {};
+ const labels: Record<string, string[]> = {};
+
+ const spineAtlasPaths = new Map<string, string>();
+ for (const relativePath of artifact.assetPaths) {
+ if (getAssetType(relativePath) === 'spine-atlas') {
+ const dir = relativePath.substring(0, relativePath.lastIndexOf('/'));
+ spineAtlasPaths.set(dir, relativePath);
+ }
+ }
+
+ const labelIndex = new Map<string, string[]>();
+
+ for (const relativePath of artifact.assetPaths) {
+ if (relativePath.endsWith('.esshader')) continue;
+
+ const editorType = getAssetType(relativePath);
+ const addressableType = toAddressableType(editorType);
+ if (!addressableType) continue;
+
+ const uuid = artifact.assetLibrary.getUuid(relativePath);
+ const assetEntry = uuid ? artifact.assetLibrary.getEntry(uuid) : null;
+
+ const entry: CatalogEntry = { type: addressableType };
+
+ if (artifact.packedPaths.has(relativePath)) {
+ const frameInfo = artifact.atlasResult.frameMap.get(relativePath);
+ if (frameInfo) {
+ const page = artifact.atlasResult.pages[frameInfo.page];
+ const f = frameInfo.frame;
+ entry.atlas = `atlas_${frameInfo.page}.png`;
+ entry.frame = { x: f.x, y: f.y, w: f.width, h: f.height };
+ entry.uv = {
+ offset: [f.x / page.width, 1.0 - (f.y + f.height) / page.height],
+ scale: [f.width / page.width, f.height / page.height],
+ };
+ }
+ }
+
+ if (addressableType === 'spine') {
+ const dir = relativePath.substring(0, relativePath.lastIndexOf('/'));
+ const atlasPath = spineAtlasPaths.get(dir);
+ if (atlasPath) {
+ entry.deps = [atlasPath];
+ }
+ }
+
+ const buildPath = toBuildPath(relativePath);
+ if (buildPath !== relativePath) {
+ entry.buildPath = buildPath;
+ }
+
+ entries[relativePath] = entry;
+
+ if (assetEntry?.address) {
+ addresses[assetEntry.address] = relativePath;
+ }
+
+ if (assetEntry) {
+ for (const label of assetEntry.labels) {
+ let list = labelIndex.get(label);
+ if (!list) {
+ list = [];
+ labelIndex.set(label, list);
+ }
+ list.push(relativePath);
+ }
+ }
+ }
+
+ for (const [label, paths] of labelIndex) {
+ labels[label] = paths;
+ }
+
+ return { version: 1, entries, addresses, labels };
+}
+
function transformPrefab(content: string, context: unknown): string {
const artifact = context as BuildArtifact;
const prefab = deserializePrefab(content);
diff --git a/editor/src/builder/PlayableEmitter.ts b/editor/src/builder/PlayableEmitter.ts
index 42ff3f294..e53b9b24a 100644
--- a/editor/src/builder/PlayableEmitter.ts
+++ b/editor/src/builder/PlayableEmitter.ts
@@ -9,7 +9,7 @@ import type { BuildResult, BuildContext, OutputFileEntry } from './BuildService'
import { BuildProgressReporter } from './BuildProgress';
import { getEditorContext } from '../context/EditorContext';
import { joinPath, getFileExtension, isAbsolutePath, getParentDir, normalizePath, getProjectDir } from '../utils/path';
-import { arrayBufferToBase64, generateAddressableManifest } from './ArtifactBuilder';
+import { arrayBufferToBase64, generateAddressableManifest, generateCatalog } from './ArtifactBuilder';
import { PLAYABLE_HTML_TEMPLATE } from './templates';
import type { NativeFS } from '../types/NativeFS';
import { getAssetMimeType, getAssetTypeEntry, toBuildPath } from 'esengine';
@@ -118,8 +118,10 @@ export class PlayableEmitter implements PlatformEmitter {
}
progress.log('info', `Collected ${assets.size} assets`);
- // 6.5 Generate addressable manifest
+ // 6.5 Generate addressable manifest + catalog
const manifestJson = JSON.stringify(generateAddressableManifest(artifact));
+ const catalogJson = JSON.stringify(generateCatalog(artifact));
+ assets.set('catalog.json', `data:application/json;base64,${btoa(catalogJson)}`);
// 7. Assemble HTML
progress.setCurrentTask('Assembling HTML...', 50);
diff --git a/editor/src/builder/WeChatEmitter.ts b/editor/src/builder/WeChatEmitter.ts
index 0b8180c45..b24f478b6 100644
--- a/editor/src/builder/WeChatEmitter.ts
+++ b/editor/src/builder/WeChatEmitter.ts
@@ -10,7 +10,7 @@ import { BuildProgressReporter } from './BuildProgress';
import { getEditorContext } from '../context/EditorContext';
import { joinPath, getProjectDir } from '../utils/path';
import { resolveShaderPath } from '../utils/shader';
-import { generateAddressableManifest } from './ArtifactBuilder';
+import { generateAddressableManifest, generateCatalog } from './ArtifactBuilder';
import { generateWeChatGameJs } from './templates';
import type { NativeFS } from '../types/NativeFS';
import { getWeChatPackOptions, getAssetTypeEntry, toBuildPath } from 'esengine';
@@ -365,6 +365,12 @@ export class WeChatEmitter implements PlatformEmitter {
joinPath(outputDir, 'asset-manifest.json'),
JSON.stringify(manifest, null, 2)
);
+
+ const catalog = generateCatalog(artifact);
+ await fs.writeFile(
+ joinPath(outputDir, 'catalog.json'),
+ JSON.stringify(catalog, null, 2)
+ );
}
private async collectOutputFiles(
diff --git a/editor/src/builder/index.ts b/editor/src/builder/index.ts
index 914f526f4..d11605c2e 100644
--- a/editor/src/builder/index.ts
+++ b/editor/src/builder/index.ts
@@ -5,7 +5,7 @@
export { BuildSettingsDialog, showBuildSettingsDialog } from './BuildSettingsDialog';
export { BuildService, type BuildResult, type BuildContext, type BuildOptions, type OutputFileEntry } from './BuildService';
-export { buildArtifact, initializeEsbuild, createBuildVirtualFsPlugin, arrayBufferToBase64, generateAddressableManifest, type SdkModuleLoader } from './ArtifactBuilder';
+export { buildArtifact, initializeEsbuild, createBuildVirtualFsPlugin, arrayBufferToBase64, generateAddressableManifest, generateCatalog, type SdkModuleLoader, type CatalogJson, type CatalogEntry } from './ArtifactBuilder';
export { PLAYABLE_HTML_TEMPLATE, generateWeChatGameJs, type WeChatGameJsParams } from './templates';
export { BuildCache, type BuildCacheData, type FileHash, type FileChangeResult } from './BuildCache';