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(editor): loadGroup / remote groups work in the Play realm

yhh8a9cf4ccf708
diff --git a/desktop/src/engine/playProtocol.ts b/desktop/src/engine/playProtocol.ts
index fd099ac3c..cde9f05d2 100644
--- a/desktop/src/engine/playProtocol.ts
+++ b/desktop/src/engine/playProtocol.ts
@@ -11,7 +11,7 @@
* import of an editor module here would break the realm bundle. Type-only
* imports are erased before resolution and are safe.
*/
-import type { SceneData, PhysicsPluginConfig, AudioProjectConfig, ThemeOverrides } from 'esengine';
+import type { SceneData, PhysicsPluginConfig, AudioProjectConfig, ThemeOverrides, AddressableManifest } from 'esengine';
/**
* Editor↔realm message-contract version. The realm reports it in `hello`; the editor
@@ -53,6 +53,9 @@ export interface PlayNetConfig {
export interface PlayPayload {
sceneData: SceneData;
assetManifest: Record<string, string>;
+ /** AddressableManifest (groups + bundle modes) so `Assets.loadGroup` — remote /
+ * lazy groups — works in Play exactly as in a shipped build. */
+ manifest?: AddressableManifest;
/** Export name of the entry scene (scenes-dir-relative, sans extension), so
* switchTo back to it works exactly as in a shipped build. Absent = '__play'. */
entrySceneName?: string;
diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.ts
index dbee08c87..8b958cf57 100644
--- a/desktop/src/playHost.ts
+++ b/desktop/src/playHost.ts
@@ -208,6 +208,10 @@ async function buildAppAndRun(msg: InitMessage): Promise<void> {
canvas,
sceneData: msg.sceneData,
assetManifest: msg.assetManifest,
+ // Addressable manifest → Assets.loadGroup works in the realm (remote / lazy
+ // groups) just like a shipped build. Remote assets resolve same-origin
+ // estella:// via assetBaseUrl, so no remoteRoot is set here.
+ manifest: msg.manifest,
// Play == ship: the entry keeps its export name and every sibling scene
// registers lazily by path, so runtime switchTo works like a shipped build.
entrySceneName: msg.entrySceneName,
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index a7f6914b0..002ec0d8a 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -3,7 +3,7 @@
import { createStore } from 'zustand/vanilla';
import { getComponent, getEditorType, Assets, migratePrefabData, extractPrefab, flattenPrefab, collectExternalEntityRefs, collapseInstance, applyDeltaToSource, buildVariant, validateOverrides, setTextureParams, TextureFilter, TextureWrap, Renderer, RETIRED_COMPONENT_TYPES, parseThemeOverrides } from 'esengine';
import { readTextureImportSettings } from './assetImporter';
-import type { SceneData, PrefabData, ExtractEntity, ProcessedEntity, PhysicsPluginConfig, AudioProjectConfig, AssetsData, ThemeOverrides, StaleOverride, PrefabOverride } from 'esengine';
+import type { SceneData, PrefabData, ExtractEntity, ProcessedEntity, PhysicsPluginConfig, AudioProjectConfig, AssetsData, ThemeOverrides, StaleOverride, PrefabOverride, AddressableManifest } from 'esengine';
import { EngineHost } from '@/engine/EngineHost';
import { applyWidgetTheme } from '@/engine/widgetTheme';
import { bootProfiler } from '@/engine/bootProfiler';
@@ -1359,9 +1359,45 @@ class ProjectStoreImpl {
* the lossless refs, not resolved handles — plus a uuid→url manifest the realm
* fetches over `estella://`. Null if no scene is loaded.
*/
+ /**
+ * Build the AddressableManifest for Play so `Assets.loadGroup` (remote / lazy
+ * groups) works in the editor realm exactly as in a shipped build. The folder
+ * convention mirrors the cook's `groupOf` (cookAssets.ts — the canonical
+ * source): `remote/<name>/` → remote group, `subpackages/<name>/` → lazy, else
+ * `main`/local. Types are inferred from the extension (the realm resolves each
+ * asset's url through the same uuid/path channel); `size` is 0 (unknown before a
+ * cook, and unused by loadGroup).
+ */
+ private buildPlayManifest(): AddressableManifest {
+ const typeOfExt = (path: string): string => {
+ const ext = path.slice(path.lastIndexOf('.')).toLowerCase();
+ if (['.png', '.jpg', '.jpeg', '.webp', '.ktx2', '.bmp', '.gif'].includes(ext)) return 'texture';
+ if (ext === '.esmaterial') return 'material';
+ if (['.wav', '.mp3', '.ogg', '.m4a'].includes(ext)) return 'audio';
+ if (ext === '.esprefab') return 'prefab';
+ if (ext === '.esshader') return 'text';
+ if (['.esscene', '.esanim', '.estilemap', '.estileset', '.estimeline', '.json', '.eslocale'].includes(ext)) return 'json';
+ return 'binary';
+ };
+ type Asset = { path: string; type: string; size: number; labels: string[] };
+ const groups: Record<string, { bundleMode: string; labels: string[]; assets: Record<string, Asset> }> = {};
+ for (const [uuid, raw] of this.uuidToPath) {
+ const path = raw.replace(/\\/g, '/');
+ const sub = /^subpackages\/([^/]+)\//.exec(path);
+ const rem = /^remote\/([^/]+)\//.exec(path);
+ const name = sub?.[1] ?? rem?.[1] ?? 'main';
+ const mode = sub ? 'lazy' : rem ? 'remote' : 'local';
+ const g = (groups[name] ??= { bundleMode: mode, labels: [], assets: {} });
+ g.assets[uuid.toLowerCase()] = { path, type: typeOfExt(path), size: 0, labels: [] };
+ }
+ groups.main ??= { bundleMode: 'local', labels: [], assets: {} };
+ return { version: '2.0', groups } as unknown as AddressableManifest;
+ }
+
playPayload(): {
sceneData: SceneData;
assetManifest: Record<string, string>;
+ manifest: AddressableManifest;
entrySceneName?: string;
extraScenes?: Array<{ name: string; path: string }>;
physicsEnabled?: boolean;
@@ -1426,7 +1462,7 @@ class ProjectStoreImpl {
const uiTheme = this.uiTheme();
const uiThemeOverrides = this.uiThemeOverrides();
return {
- sceneData, assetManifest, physicsEnabled: f.enabled, physicsConfig,
+ sceneData, assetManifest, manifest: this.buildPlayManifest(), physicsEnabled: f.enabled, physicsConfig,
...(currentScene ? { entrySceneName: exportSceneName(currentScene) } : {}),
...(extraScenes.length > 0 ? { extraScenes } : {}),
...(audioConfig.buses ? { audioConfig } : {}),