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 delivery-mode vocabulary

esengine20f46ab607e9
diff --git a/desktop/src/panels/ContentBrowser.tsx b/desktop/src/panels/ContentBrowser.tsx
index 555fdffd2..60507dfde 100644
--- a/desktop/src/panels/ContentBrowser.tsx
+++ b/desktop/src/panels/ContentBrowser.tsx
@@ -28,6 +28,7 @@ import { createAnimatedSpriteFromClip } from '@/flipbook/createAnimatedSprite';
import { createTilemapFromTileset } from '@/tilemap/createTilemap';
import { createMaterialInstance } from '@/material/openMaterial';
import { NEW_ASSET_TYPES, type CreateAsset } from '@/project/newAssetTypes';
+import { ASSET_GROUP_MODES, type AssetGroupMode } from 'esengine';
import { onAssetReveal } from '@/project/assetReveal';
import { fsRefresh } from '@/project/fsWatch';
import { t, type MsgKey } from '@/i18n';
@@ -40,6 +41,16 @@ const TILE_KEY = 'estella.content.tileSize';
const errMsg = (e: unknown) => (e instanceof Error ? e.message : String(e));
+// Per-delivery-mode presentation (menu label + corner badge; `local` has none).
+// Keyed by AssetGroupMode so adding a mode to the SDK's ASSET_GROUP_MODES forces
+// a matching entry here — the vocabulary is single-sourced in the SDK, only its
+// editor-side presentation lives here.
+const DELIVERY_MODE_META: Record<AssetGroupMode, { labelKey: MsgKey; badge?: { color: string; textKey: MsgKey } }> = {
+ local: { labelKey: 'cb.deliveryLocal' },
+ subpackage: { labelKey: 'cb.deliverySubpackage', badge: { color: '#8a5cf6', textKey: 'cb.badgeSubpackage' } },
+ remote: { labelKey: 'cb.deliveryRemote', badge: { color: '#2f6df6', textKey: 'cb.badgeRemote' } },
+};
+
// Lazily read a project-relative directory (or [] when null / no project / error),
// re-reading whenever the path changes or an fs mutation bumps fsRefresh.
// `loading` flips in-render on a path change (so the empty state never paints
@@ -1020,8 +1031,8 @@ export function ContentBrowser() {
...(entry.isDir
? [{
label: t('cb.delivery'),
- children: (['local', 'subpackage', 'remote'] as const).map((m) => ({
- label: m === 'local' ? t('cb.deliveryLocal') : m === 'subpackage' ? t('cb.deliverySubpackage') : t('cb.deliveryRemote'),
+ children: ASSET_GROUP_MODES.map((m) => ({
+ label: t(DELIVERY_MODE_META[m].labelKey),
checked: ProjectStore.folderDeliveryMode(path) === m,
onClick: () => void ProjectStore.setFolderDeliveryMode(path, m),
})),
@@ -1228,13 +1239,13 @@ export function ContentBrowser() {
<AssetIcon type={type} size={30} />
)}
{!it.isDir && TYPE_CODE[type] && <span className="badge">{TYPE_CODE[type]}</span>}
- {deliv !== 'local' && (
+ {DELIVERY_MODE_META[deliv].badge && (
<span
className="badge"
- style={{ background: deliv === 'remote' ? '#2f6df6' : '#8a5cf6', color: '#fff' }}
- title={deliv === 'remote' ? t('cb.deliveryRemote') : t('cb.deliverySubpackage')}
+ style={{ background: DELIVERY_MODE_META[deliv].badge!.color, color: '#fff' }}
+ title={t(DELIVERY_MODE_META[deliv].labelKey)}
>
- {deliv === 'remote' ? t('cb.badgeRemote') : t('cb.badgeSubpackage')}
+ {t(DELIVERY_MODE_META[deliv].badge!.textKey)}
</span>
)}
{path === project?.defaultScene && (
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index 1f21c015a..43bcf96a3 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1321 stable · 17 beta · 0 deprecated
+Symbols: 1322 stable · 17 beta · 0 deprecated
## ABI_LAYOUT_HASH — const
```
@@ -18,6 +18,11 @@ readonly AnchorAxis[]
"1.3"
```
+## ASSET_GROUP_MODES — const
+```
+readonly ["local", "subpackage", "remote"]
+```
+
## ActionDef — interface
```
bindings: Binding[]
@@ -496,12 +501,12 @@ static prototype: ArrayDataSource<any>
## AssetGroupDef — interface
```
folder: string
-mode: AssetGroupMode
+mode: "local" | "subpackage" | "remote"
```
## AssetGroupMode — type
```
-'local' | 'subpackage' | 'remote'
+typeof ASSET_GROUP_MODES[number]
```
## AssetGroupsConfig — interface
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 9fcfe05af..7406da83e 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1321 stable · 22 beta · 0 deprecated
+Symbols: 1322 stable · 22 beta · 0 deprecated
## ABI_LAYOUT_HASH — const
```
@@ -18,6 +18,11 @@ readonly AnchorAxis[]
"1.3"
```
+## ASSET_GROUP_MODES — const
+```
+readonly ["local", "subpackage", "remote"]
+```
+
## ActionDef — interface
```
bindings: Binding[]
@@ -496,12 +501,12 @@ static prototype: ArrayDataSource<any>
## AssetGroupDef — interface
```
folder: string
-mode: AssetGroupMode
+mode: "local" | "subpackage" | "remote"
```
## AssetGroupMode — type
```
-'local' | 'subpackage' | 'remote'
+typeof ASSET_GROUP_MODES[number]
```
## AssetGroupsConfig — interface
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 3888d205e..ba12dcfbd 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1320 stable · 19 beta · 0 deprecated
+Symbols: 1321 stable · 19 beta · 0 deprecated
## ANCHOR_AXES — const
```
@@ -13,6 +13,11 @@ readonly AnchorAxis[]
"1.3"
```
+## ASSET_GROUP_MODES — const
+```
+readonly ["local", "subpackage", "remote"]
+```
+
## ActionDef — interface
```
bindings: Binding[]
@@ -491,12 +496,12 @@ static prototype: ArrayDataSource<any>
## AssetGroupDef — interface
```
folder: string
-mode: AssetGroupMode
+mode: "local" | "subpackage" | "remote"
```
## AssetGroupMode — type
```
-'local' | 'subpackage' | 'remote'
+typeof ASSET_GROUP_MODES[number]
```
## AssetGroupsConfig — interface
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 74008ed03..01b966e1a 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 1331 stable · 17 beta · 0 deprecated
+Symbols: 1332 stable · 17 beta · 0 deprecated
## ANCHOR_AXES — const
```
@@ -13,6 +13,11 @@ readonly AnchorAxis[]
"1.3"
```
+## ASSET_GROUP_MODES — const
+```
+readonly ["local", "subpackage", "remote"]
+```
+
## ActionDef — interface
```
bindings: Binding[]
@@ -491,12 +496,12 @@ static prototype: ArrayDataSource<any>
## AssetGroupDef — interface
```
folder: string
-mode: AssetGroupMode
+mode: "local" | "subpackage" | "remote"
```
## AssetGroupMode — type
```
-'local' | 'subpackage' | 'remote'
+typeof ASSET_GROUP_MODES[number]
```
## AssetGroupsConfig — interface
diff --git a/sdk/src/asset/assetGroups.ts b/sdk/src/asset/assetGroups.ts
index 49a2963c1..16565a880 100644
--- a/sdk/src/asset/assetGroups.ts
+++ b/sdk/src/asset/assetGroups.ts
@@ -16,9 +16,13 @@
*/
import type { BundleMode } from './AddressableManifest';
-/** User-facing delivery mode for a group. `subpackage` maps to the manifest's
- * `lazy` bundle mode; `local`/`remote` map to themselves. */
-export type AssetGroupMode = 'local' | 'subpackage' | 'remote';
+/** The user-facing delivery modes for a group, as a runtime list so callers
+ * (the editor's Delivery menu / badges) enumerate them from one source instead
+ * of hand-repeating the members. `subpackage` maps to the manifest's `lazy`
+ * bundle mode; `local`/`remote` map to themselves. */
+export const ASSET_GROUP_MODES = ['local', 'subpackage', 'remote'] as const;
+
+export type AssetGroupMode = typeof ASSET_GROUP_MODES[number];
/** One authored group: every asset under `folder` (recursively) joins it. */
export interface AssetGroupDef {
diff --git a/sdk/src/asset/index.ts b/sdk/src/asset/index.ts
index 8eddee549..626db8b2c 100644
--- a/sdk/src/asset/index.ts
+++ b/sdk/src/asset/index.ts
@@ -19,6 +19,7 @@ export {
folderGroupMode,
withFolderGroup,
withActiveRemoteRoot,
+ ASSET_GROUP_MODES,
type AssetGroupMode,
type AssetGroupDef,
type BuildProfile,
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index 50c0fc042..0ec8e43e9 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -73,6 +73,7 @@ export {
folderGroupMode,
withFolderGroup,
withActiveRemoteRoot,
+ ASSET_GROUP_MODES,
type AssetGroupMode,
type AssetGroupDef,
type BuildProfile,