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.

fix(editor): pick the ad network where you package, not in Project Settings

esenginec165f9814fe7
diff --git a/desktop/src/components/BuildDialog.tsx b/desktop/src/components/BuildDialog.tsx
index 989719d29..afe489fe0 100644
--- a/desktop/src/components/BuildDialog.tsx
+++ b/desktop/src/components/BuildDialog.tsx
@@ -29,8 +29,10 @@ import {
Globe, Monitor, MessageSquare, ChevronRight, Smartphone, Apple, Package, TriangleAlert, Plus,
} from 'lucide-react';
import type { ExportPlatform, NativeToolchain, PlatformPrereq } from '@/project/platforms';
+import type { PlayableNetworkOption } from '../../electron/platformCatalog';
import { Modal } from '@/components/Modal';
import { Segmented } from '@/components/Segmented';
+import { Select } from '@/components/Select';
import { Button } from '@/components/Button';
import { ProjectStore } from '@/project/ProjectStore';
import { useEditorStore } from '@/store/editorStore';
@@ -202,6 +204,12 @@ export function BuildDialog() {
// compression entirely for fast iteration. The per-asset decisions live in the
// Inspector; this only picks whether to apply them.
const [assetCompression, setAssetCompression] = useState<AssetCompression>(saved.assetCompression ?? 'auto');
+ // Which ad network a playable is packaged for. It belongs HERE rather than in
+ // Project Settings: shipping the same game to several networks is a normal day, and
+ // that is a per-build decision, not a property of the project. The list arrives from
+ // the main process, since it includes the networks the PROJECT defines.
+ const [adNetwork, setAdNetwork] = useState<string>(saved.platforms?.playable?.network ?? 'generic');
+ const [adNetworks, setAdNetworks] = useState<PlayableNetworkOption[]>([]);
const [advOpen, setAdvOpen] = useState(false);
const [copiedFix, setCopiedFix] = useState(false);
// The scaffolding pane: a pseudo-selection, so the nav keeps working while it shows.
@@ -284,6 +292,27 @@ export function BuildDialog() {
a.path === project?.defaultScene ? -1 : b.path === project?.defaultScene ? 1 : a.path.localeCompare(b.path));
const shippedScenes = sceneList.filter((s) => s.path === project?.defaultScene || !excludedScenes.has(s.path)).length;
+ useEffect(() => {
+ let live = true;
+ void window.estella.project?.listPlayableNetworks?.().then((rows) => {
+ if (live) setAdNetworks(rows ?? []);
+ });
+ return () => { live = false; };
+ }, []);
+
+ /** Each network gets its own output dir, so packaging for one does not overwrite
+ * the last — except the unnamed default, which keeps the plain folder. */
+ const playableOut = (network: string): string => (network === 'generic' ? 'dist-playable' : `dist-playable/${network}`);
+
+ const pickNetwork = (network: string) => {
+ // Follow the output only while it is still a default; never overwrite a path the
+ // developer typed.
+ if (outDir === playableOut(adNetwork)) setOutDir(playableOut(network));
+ setAdNetwork(network);
+ setPhase('idle');
+ setResult(null);
+ };
+
const pickPlatform = (p: PlatformDef) => {
// A not-ready target is still selectable: seeing WHY it is not ready is the
// point, and what a build may attempt is the developer's call.
@@ -291,7 +320,7 @@ export function BuildDialog() {
setPhase('idle');
setResult(null);
// Restore this platform's saved output, else its suggested default.
- setOutDir(saved.outDir?.[p.id] ?? p.defaultOut);
+ setOutDir(saved.outDir?.[p.id] ?? (p.id === 'playable' ? playableOut(adNetwork) : p.defaultOut));
};
const startCreate = () => {
@@ -359,6 +388,9 @@ export function BuildDialog() {
setLog([]);
// Persist the chosen settings to project.esproject (restored next time).
void ProjectStore.setPackaging({ platform, config, sourceMaps, openFolder, assetCompression, outDir: { [platform]: outDir } });
+ // Awaited, not fired-and-forgotten: the export resolves the network from the
+ // manifest, so a race here would package for the previous one.
+ if (platform === 'playable') await ProjectStore.setPlatformPackaging('playable', { network: adNetwork });
// 'auto' → honor each asset's Import Settings (the cook then reads per-asset
// texture/audio compression + Max Size); 'skip' → ship everything raw.
const compress = assetCompression === 'auto';
@@ -594,6 +626,23 @@ export function BuildDialog() {
)}
<Group title={t('build.secBuild')}>
+ {platform === 'playable' && (
+ <>
+ <div className="build__row">
+ <span className="build__label" title={t('build.adNetworkTip')}>{t('build.adNetwork')}</span>
+ <Select
+ ariaLabel={t('build.adNetwork')}
+ value={adNetwork}
+ options={(adNetworks.length > 0 ? adNetworks : [{ id: adNetwork, label: adNetwork, source: 'builtin' as const }])
+ .map((n) => ({ value: n.id, label: n.error ? `${n.label} — ${n.error}` : n.label }))}
+ onChange={pickNetwork}
+ />
+ </div>
+ <div className="build__hint">
+ <Info size={11} /> {t('build.adNetworkHint')}
+ </div>
+ </>
+ )}
<div className="build__row">
<span className="build__label">{t('build.configuration')}</span>
<Segmented
diff --git a/desktop/src/components/SettingsDialog.tsx b/desktop/src/components/SettingsDialog.tsx
index 2dd5890dd..9bc7bf8d2 100644
--- a/desktop/src/components/SettingsDialog.tsx
+++ b/desktop/src/components/SettingsDialog.tsx
@@ -256,10 +256,7 @@ function Control({ setting }: { setting: Setting }) {
/>
);
case 'enum': {
- // A provider's choices come from disk (e.g. the project's own ad-network
- // profiles), so they win over the descriptor's static list.
- const options = (setting.optionsProvider?.() ?? setting.options)
- .map((o) => ({ value: o.value, label: o.label }));
+ const options = setting.options.map((o) => ({ value: o.value, label: o.label }));
if (setting.segmented) {
return (
<Segmented
@@ -379,20 +376,6 @@ export function SettingsDialog() {
// Subscribe so rows reflect live changes of bound (editorStore) settings too.
useEditorStore((s) => `${s.showGrid}|${s.showGizmos}|${s.snapping}|${s.snapStep}`);
- // Settings whose choices live on disk (the playable's ad networks, for one) load
- // them here; the bump re-renders once they are in. Generic on purpose — the dialog
- // asks every descriptor and never learns which one needed it.
- const [, bumpOptions] = useState(0);
- useEffect(() => {
- const pending = settingsRegistry.all()
- .map((s) => (s.type === 'enum' ? s.prepareOptions?.() : undefined))
- .filter((p): p is Promise<void> => !!p);
- if (pending.length === 0) return;
- let live = true;
- void Promise.allSettled(pending).then(() => { if (live) bumpOptions((n) => n + 1); });
- return () => { live = false; };
- }, []);
-
useEffect(() => {
const raf = requestAnimationFrame(() => setOpen(true));
const onKey = (e: KeyboardEvent) => {
diff --git a/desktop/src/i18n/messages/project.ts b/desktop/src/i18n/messages/project.ts
index 82ae6cb3b..2bea56247 100644
--- a/desktop/src/i18n/messages/project.ts
+++ b/desktop/src/i18n/messages/project.ts
@@ -150,6 +150,15 @@ export const projectMessages = defineMessages({
'build.openXcode': { en: 'Open in Xcode', zh: '在 Xcode 中打开' },
// — Options —
+ 'build.adNetwork': { en: 'Ad network', zh: '广告平台' },
+ 'build.adNetworkTip': {
+ en: 'Decides the size limit, what goes in <head>, and the API playableCta() calls.',
+ zh: '决定体积上限、<head> 注入内容,以及 playableCta() 调用的接口。',
+ },
+ 'build.adNetworkHint': {
+ en: 'Each network gets its own output folder. Add one we don\'t ship with a kind: \'playable\' profile in .esengine/platforms/.',
+ zh: '每个平台输出到各自的目录。我们没内置的平台,可在 .esengine/platforms/ 放一个 kind: \'playable\' 的配置来添加。',
+ },
'build.configuration': { en: 'Configuration', zh: '配置' },
'build.development': { en: 'Development', zh: '开发' },
'build.shipping': { en: 'Shipping', zh: '发行' },
diff --git a/desktop/src/i18n/messages/settings.ts b/desktop/src/i18n/messages/settings.ts
index b10090c7a..d93baa9fe 100644
--- a/desktop/src/i18n/messages/settings.ts
+++ b/desktop/src/i18n/messages/settings.ts
@@ -75,7 +75,6 @@ export const settingsMessages = defineMessages({
'set.group.application': { en: 'Application', zh: '应用' },
'set.group.wechat': { en: 'WeChat', zh: '微信' },
'set.group.desktop': { en: 'Desktop', zh: '桌面' },
- 'set.group.playable': { en: 'Playable', zh: '试玩广告' },
// — Editor settings —
'set.appearance.language': { en: 'Language', zh: '语言' },
@@ -218,17 +217,6 @@ export const settingsMessages = defineMessages({
en: 'Anti-tunneling for fast bodies (Box2D default on).',
zh: '高速刚体的防穿透(Box2D 默认开启)。',
},
- 'set.project.packaging.playable.network': { en: 'Ad network', zh: '广告平台' },
- 'set.project.packaging.playable.network.desc': {
- en: 'Which network the single-file playable is packaged for: its size limit, its <head> markup, '
- + 'and the API playableCta() calls. Define your own in .esengine/platforms/<id>.mjs '
- + "with kind: 'playable'.",
- zh: '单文件试玩包面向哪个平台:体积上限、<head> 注入内容,以及 playableCta() 调用的接口。'
- + "可在 .esengine/platforms/<id>.mjs 中以 kind: 'playable' 自定义。",
- },
- 'set.project.packaging.playable.network.generic': {
- en: 'Generic (single-file HTML5)', zh: '通用(单文件 HTML5)',
- },
'set.project.packaging.wechat.appid': { en: 'AppID', zh: 'AppID' },
'set.project.packaging.wechat.appid.desc': {
en: 'Your WeChat MiniGame appid — written into project.config.json on export.',
diff --git a/desktop/src/settings/projectSettings.ts b/desktop/src/settings/projectSettings.ts
index c1997b0e9..9fd14faa0 100644
--- a/desktop/src/settings/projectSettings.ts
+++ b/desktop/src/settings/projectSettings.ts
@@ -300,37 +300,6 @@ settingsRegistry.register({
},
});
-// The ad network a playable is packaged for. The choices are not knowable here: a
-// project can define its own network in `.esengine/platforms/<id>.mjs`, and those
-// stand beside the editor's own — so the list is read from the main process when the
-// dialog opens.
-let playableNetworks: { value: string; label: string }[] = [];
-
-settingsRegistry.register({
- id: 'project.packaging.playable.network',
- type: 'enum', scope: 'project', section: 'packaging', group: t('set.group.playable'),
- label: t('set.project.packaging.playable.network'),
- description: t('set.project.packaging.playable.network.desc'),
- default: 'generic',
- options: [{ value: 'generic', label: t('set.project.packaging.playable.network.generic') }],
- optionsProvider: () => (playableNetworks.length > 0 ? playableNetworks : undefined) ?? [
- { value: 'generic', label: t('set.project.packaging.playable.network.generic') },
- ],
- prepareOptions: async () => {
- const rows = await window.estella.project.listPlayableNetworks();
- // A profile that failed to load is still offered, labelled with its error —
- // silently dropping a file the developer wrote is worse than naming it.
- playableNetworks = rows.map((r) => ({
- value: r.id,
- label: r.error ? `${r.label} — ${r.error}` : r.label,
- }));
- },
- bind: {
- get: () => ProjectStore.platformPackaging().playable?.network ?? 'generic',
- set: (v) => void ProjectStore.setPlatformPackaging('playable', { network: v }),
- },
-});
-
// The application identifier every installable target needs. One project ships as
// one application, so it is declared once; a target that genuinely differs
// overrides it below. Absent ⇒ derived from the project name, so a build always
diff --git a/desktop/src/settings/types.ts b/desktop/src/settings/types.ts
index 22f67c6e5..a51ce0af8 100644
--- a/desktop/src/settings/types.ts
+++ b/desktop/src/settings/types.ts
@@ -60,17 +60,6 @@ export interface NumberSetting extends BaseSetting<number> {
export interface EnumSetting extends BaseSetting<string> {
type: 'enum';
options: { value: string; label: string }[];
- /**
- * Choices discovered at open time rather than known when the descriptor was
- * written — the playable's ad networks, for one, include whatever profiles the
- * PROJECT defines on disk. Consulted first; `options` remains the fallback (and
- * the answer while the provider's data is still loading).
- */
- optionsProvider?: () => { value: string; label: string }[];
- /** Load whatever {@link optionsProvider} reads. The dialog awaits every setting's
- * on open and re-renders, so a descriptor can source its choices from disk
- * without the dialog knowing which setting did. */
- prepareOptions?: () => Promise<void>;
/** Render as a segmented control instead of a dropdown. */
segmented?: boolean;
}
diff --git a/docs/astro/src/content/docs/guides/build-export.mdx b/docs/astro/src/content/docs/guides/build-export.mdx
index 32032aa0e..f4b3eb136 100644
--- a/docs/astro/src/content/docs/guides/build-export.mdx
+++ b/docs/astro/src/content/docs/guides/build-export.mdx
@@ -74,8 +74,11 @@ and opens it in your browser.
Every network takes the same single HTML file but disagrees on three things: how big
it may be, what must sit in `<head>`, and which function sends the player to the
-store. Pick the network in **Project Settings → Packaging → Playable → Ad network**
-and the export handles all three.
+store. Pick the network in the **Package Project** dialog — it sits with the Playable
+target's own settings — and the export handles all three. Shipping the same game to
+several networks is a normal day, so it is a per-build choice rather than a project
+property; each network also gets its own output folder (`dist-playable/<network>`), so
+packaging for one never overwrites the last.
Your game code never names a network. Call the CTA once:
@@ -105,8 +108,8 @@ number to trust.
### A network we don't ship
Define it yourself — the built-in networks are written against this exact contract,
-so nothing is out of reach. **Build → New platform** scaffolds one (pick *Playable ad
-network*), or write `.esengine/platforms/<id>.mjs` by hand:
+so nothing is out of reach. **Package Project → New platform** scaffolds one (pick
+*Playable ad network*), or write `.esengine/platforms/<id>.mjs` by hand:
```js
export default {
@@ -127,8 +130,8 @@ export default {
};
```
-It then appears in the Ad network list beside the built-in ones, and packages through
-the same pipeline.
+It then appears in the dialog's Ad network dropdown beside the built-in ones, and
+packages through the same pipeline.
## Runtime prerequisites
diff --git a/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx b/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx
index 55d298a5c..4a94f3a0f 100644
--- a/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx
+++ b/docs/astro/src/content/docs/zh-cn/guides/build-export.mdx
@@ -64,8 +64,9 @@ import { Aside, Steps } from '@astrojs/starlight/components';
## 试玩广告平台
各家平台收的都是同一个单文件 HTML,但在三件事上不一致:体积上限、`<head>` 里必须放什么、
-以及用哪个函数把玩家送去商店。在 **项目设置 → 打包 → 试玩广告 → 广告平台** 选好平台,
-导出会把这三件事都处理掉。
+以及用哪个函数把玩家送去商店。在**打包项目**对话框里选平台(就在 Playable 目标自己的设置里),
+导出会把这三件事都处理掉。同一个游戏投多家是常事,所以这是**每次打包时的选择**而不是项目属性;
+每个平台还各有自己的输出目录(`dist-playable/<平台>`),打一家不会覆盖上一家。
游戏代码里不出现任何平台名字,只调一次 CTA:
@@ -93,7 +94,7 @@ playableCta();
### 我们没内置的平台
-自己定义就行——内置的那几家写的就是这份契约,没有做不到的事。**构建 → 新建平台** 可以
+自己定义就行——内置的那几家写的就是这份契约,没有做不到的事。**打包项目 → 新建平台** 可以
生成脚手架(类型选*试玩广告平台*),也可以手写 `.esengine/platforms/<id>.mjs`:
```js
@@ -114,7 +115,7 @@ export default {
};
```
-它随后就会和内置平台并列出现在"广告平台"列表里,并走同一条导出管线。
+它随后就会和内置平台并列出现在对话框的"广告平台"下拉里,并走同一条导出管线。
## 运行时前置条件