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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
feat(editor): the ad network is pickable, including one the project wrote itself
esenginefa97b666c9e7
diff --git a/desktop/src/components/BuildDialog.tsx b/desktop/src/components/BuildDialog.tsxindex d5bb7219a..43bd66cc5 100644--- a/desktop/src/components/BuildDialog.tsx+++ b/desktop/src/components/BuildDialog.tsx@@ -207,7 +207,12 @@ export function BuildDialog() {const [newId, setNewId] = useState('my-platform');const [newLabel, setNewLabel] = useState('My Platform');const [createErr, setCreateErr] = useState<string | null>(null);- const [created, setCreated] = useState<{ id: string; packaging: string; runtime: string } | null>(null);+ const [created, setCreated] = useState<{ id: string; packaging: string; runtime?: string } | null>(null);+ // Mini-game vendor or playable ad network — two extension points, one form. A+ // network is NOT a platform row (it is chosen inside the playable target), so+ // creating one lands on a note rather than on a new selection.+ const [newKind, setNewKind] = useState<'minigame' | 'playable'>('minigame');+ const [createdNetwork, setCreatedNetwork] = useState<{ id: string; file: string } | null>(null);const [phase, setPhase] = useState<Phase>('idle');const [result, setResult] = useState<Result | null>(null);const [log, setLog] = useState<string[]>([]);@@ -295,12 +300,19 @@ export function BuildDialog() {const createPlatform = async () => {setCreateErr(null);- const res = await window.estella.project?.createPlatform?.(newId.trim(), newLabel.trim());+ const res = await window.estella.project?.createPlatform?.(newId.trim(), newLabel.trim(), newKind);if (!res?.ok) {setCreateErr(res?.error ?? t('build.packageFailed'));return;}const id = newId.trim();+ // An ad network joins the playable target's network list, not the platform nav.+ if (newKind === 'playable') {+ setCreatedNetwork({ id, file: res.packagingFile! });+ setCreating(false);+ setPlatform('playable');+ return;+ }setCreated({ id, packaging: res.packagingFile!, runtime: res.runtimeFile! });// Re-read the catalog so the new platform joins the nav, then select it.const rows = (await window.estella.project?.listPlatforms?.()) ?? [];@@ -477,6 +489,18 @@ export function BuildDialog() {<span className="build__blurb">{t('build.newPlatformBlurb')}</span></div><Group title={t('build.newPlatform')}>+ <div className="build__row">+ <span className="build__label">{t('build.platformKind')}</span>+ <Segmented+ value={newKind}+ onChange={(v) => setNewKind(v as 'minigame' | 'playable')}+ ariaLabel={t('build.platformKind')}+ options={[+ { value: 'minigame', label: t('build.platformKind.minigame') },+ { value: 'playable', label: t('build.platformKind.playable') },+ ]}+ />+ </div><div className="build__row"><span className="build__label" title={t('build.platformIdTip')}>{t('build.platformId')}</span><input value={newId} spellCheck={false} onChange={(e) => setNewId(e.target.value)} />@@ -505,12 +529,28 @@ export function BuildDialog() {<span className="build__blurb">{def.blurb}</span></div>+ {createdNetwork && def.id === 'playable' && (+ <div className="build__prereq">+ <CheckCircle2 size={13} />+ <div className="build__prereq-body">+ <span className="selectable">+ {t('build.createdNetwork', { file: createdNetwork.file, label: createdNetwork.id })}+ </span>+ <div className="build__fix">+ <Button onClick={() => void window.estella.shell?.showItem?.(createdNetwork.file)}>+ <FolderOpen size={12} /> {t('build.revealFiles')}+ </Button>+ </div>+ </div>+ </div>+ )}+{created?.id === def.id && (<div className="build__prereq"><CheckCircle2 size={13} /><div className="build__prereq-body"><span className="selectable">- {t('build.created', { packaging: created.packaging, runtime: created.runtime })}+ {t('build.created', { packaging: created.packaging, runtime: created.runtime ?? '' })}</span><div className="build__fix"><Button onClick={() => void window.estella.shell?.showItem?.(created.packaging)}>diff --git a/desktop/src/components/SettingsDialog.tsx b/desktop/src/components/SettingsDialog.tsxindex 0929151ca..2dd5890dd 100644--- a/desktop/src/components/SettingsDialog.tsx+++ b/desktop/src/components/SettingsDialog.tsx@@ -255,14 +255,18 @@ function Control({ setting }: { setting: Setting }) {}}/>);- case 'enum':+ 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 }));if (setting.segmented) {return (<Segmentedvalue={String(value)}onChange={(v) => setValue(setting.id, v)}ariaLabel={setting.label}- options={setting.options.map((o) => ({ value: o.value, label: o.label }))}+ options={options}/>);}@@ -270,10 +274,11 @@ function Control({ setting }: { setting: Setting }) {<SelectariaLabel={setting.label}value={String(value)}- options={setting.options.map((o) => ({ value: o.value, label: o.label }))}+ options={options}onChange={(v) => setValue(setting.id, v)}/>);+ }case 'number':return <NumberControl setting={setting} />;case 'color':@@ -374,6 +379,20 @@ 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.tsindex fa56fe74c..eebc2cd1b 100644--- a/desktop/src/i18n/messages/project.ts+++ b/desktop/src/i18n/messages/project.ts@@ -67,9 +67,12 @@ export const projectMessages = defineMessages({'build.newPlatform': { en: 'New platform', zh: '新建平台' },'build.newPlatformTitle': { en: 'New project platform', zh: '新建项目平台' },'build.newPlatformBlurb': {- en: 'Estella writes both halves of the vendor — the packaging profile and the runtime profile it points at — already joined. Edit them to describe your host.',- zh: 'Estella 会把平台的两半都写好——打包配置,以及它指向的运行时配置——并且已经连接好。之后你只需编辑它们来描述你的宿主。',+ en: 'A mini-game host gets both halves written and already joined — the packaging profile and the runtime profile it points at. An ad network is one file: a playable always runs in a browser, so only its size limit, its <head> markup and its click-through API differ.',+ zh: '小游戏宿主会写好两半并连接完毕——打包配置,以及它指向的运行时配置。广告平台只需一个文件:试玩包始终跑在浏览器里,只有体积上限、<head> 注入内容与点击跳转接口不同。',},+ 'build.platformKind': { en: 'Kind', zh: '类型' },+ 'build.platformKind.minigame': { en: 'Mini-game host', zh: '小游戏宿主' },+ 'build.platformKind.playable': { en: 'Playable ad network', zh: '试玩广告平台' },'build.platformId': { en: 'Id', zh: '标识' },'build.platformIdTip': {en: 'Lowercase letters, digits and dashes. Also the per-texture Import Settings key for this platform.',@@ -81,6 +84,10 @@ export const projectMessages = defineMessages({en: 'Created {packaging} and {runtime}. Edit them to describe your host, then package.',zh: '已创建 {packaging} 与 {runtime}。编辑它们来描述你的宿主,然后就可以打包。',},+ 'build.createdNetwork': {+ en: 'Created {file}. Fill in its limit and CTA bridge, then select "{label}" in Project Settings → Packaging → Playable.',+ zh: '已创建 {file}。填好它的体积上限与 CTA 桥接后,在 项目设置 → 打包 → 试玩广告 里选择“{label}”。',+ },'build.revealFiles': { en: 'Show files', zh: '显示文件' },'build.noCustomPlatforms': {en: 'Drop a profile in .esengine/platforms/<id>.mjs to add your own target.',diff --git a/desktop/src/i18n/messages/settings.ts b/desktop/src/i18n/messages/settings.tsindex d93baa9fe..b10090c7a 100644--- a/desktop/src/i18n/messages/settings.ts+++ b/desktop/src/i18n/messages/settings.ts@@ -75,6 +75,7 @@ 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: '语言' },@@ -217,6 +218,17 @@ 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.tsindex 9fd14faa0..c1997b0e9 100644--- a/desktop/src/settings/projectSettings.ts+++ b/desktop/src/settings/projectSettings.ts@@ -300,6 +300,37 @@ 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 alwaysdiff --git a/desktop/src/settings/types.ts b/desktop/src/settings/types.tsindex a51ce0af8..22f67c6e5 100644--- a/desktop/src/settings/types.ts+++ b/desktop/src/settings/types.ts@@ -60,6 +60,17 @@ 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;}