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): a network you just created is selectable now, and stays findable later

esengine6065197c1736
diff --git a/desktop/electron/platformCatalog.ts b/desktop/electron/platformCatalog.ts
index 3478e549a..eeae3b95c 100644
--- a/desktop/electron/platformCatalog.ts
+++ b/desktop/electron/platformCatalog.ts
@@ -502,6 +502,10 @@ export interface PlayableNetworkOption {
id: string;
label: string;
source: 'builtin' | 'project';
+ /** Project networks only — the profile that defines it, project-relative. A network
+ * the project WROTE is a file it has to be able to find and edit, so the dialog can
+ * point at it (and at the error, when one fails to load). */
+ file?: string;
/** Present when a project profile failed to load, and why — the row still appears. */
error?: string;
}
@@ -520,13 +524,14 @@ export async function listPlayableNetworks(root: string | null): Promise<Playabl
const { mod, error } = await importPlatformModule(file);
// A broken profile is NAMED rather than dropped — a project that wrote a file
// and sees nothing cannot tell the difference between "not loaded" and "typo".
+ const rel = posix(path.relative(root, file));
if (error) {
const id = path.basename(file, '.mjs');
- if (!out.some((p) => p.id === id)) out.push({ id, label: path.basename(file), source: 'project', error });
+ if (!out.some((p) => p.id === id)) out.push({ id, label: path.basename(file), source: 'project', file: rel, error });
continue;
}
if (!mod || mod.kind !== 'playable') continue;
- out.push({ id: mod.id, label: mod.label, source: 'project' });
+ out.push({ id: mod.id, label: mod.label, source: 'project', file: rel });
}
return out;
}
diff --git a/desktop/src/components/BuildDialog.tsx b/desktop/src/components/BuildDialog.tsx
index afe489fe0..ce9664c99 100644
--- a/desktop/src/components/BuildDialog.tsx
+++ b/desktop/src/components/BuildDialog.tsx
@@ -292,6 +292,12 @@ 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;
+ const refreshNetworks = async (): Promise<PlayableNetworkOption[]> => {
+ const rows = (await window.estella.project?.listPlayableNetworks?.()) ?? [];
+ setAdNetworks(rows);
+ return rows;
+ };
+
useEffect(() => {
let live = true;
void window.estella.project?.listPlayableNetworks?.().then((rows) => {
@@ -304,6 +310,8 @@ export function BuildDialog() {
* the last — except the unnamed default, which keeps the plain folder. */
const playableOut = (network: string): string => (network === 'generic' ? 'dist-playable' : `dist-playable/${network}`);
+ const selectedNetwork = adNetworks.find((n) => n.id === adNetwork);
+
const pickNetwork = (network: string) => {
// Follow the output only while it is still a default; never overwrite a path the
// developer typed.
@@ -340,8 +348,17 @@ export function BuildDialog() {
// An ad network joins the playable target's network list, not the platform nav.
if (newKind === 'playable') {
setCreatedNetwork({ id, file: res.packagingFile! });
+ // Re-read the list so the new network is selectable NOW, and select it: it was
+ // just written, so it is what the developer means to package with.
+ const rows = await refreshNetworks();
setCreating(false);
setPlatform('playable');
+ if (rows.some((r) => r.id === id)) {
+ setAdNetwork(id);
+ setOutDir(playableOut(id));
+ }
+ setPhase('idle');
+ setResult(null);
return;
}
setCreated({ id, packaging: res.packagingFile!, runtime: res.runtimeFile! });
@@ -570,11 +587,6 @@ export function BuildDialog() {
<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>
)}
@@ -634,10 +646,29 @@ export function BuildDialog() {
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 }))}
+ .map((n) => ({ value: n.id, label: n.error ? `${n.label} ⚠` : n.label }))}
onChange={pickNetwork}
/>
</div>
+ {/* A network the PROJECT wrote is a file it must be able to find again —
+ the dialog is the only place that knows which file that is. */}
+ {selectedNetwork?.file && (
+ <div className={`build__prereq${selectedNetwork.error ? ' is-error' : ''}`}>
+ {selectedNetwork.error ? <AlertCircle size={13} /> : <Info size={13} />}
+ <div className="build__prereq-body">
+ <span className="selectable">
+ {selectedNetwork.error
+ ? `${selectedNetwork.file} — ${selectedNetwork.error}`
+ : t('build.adNetworkFile', { file: selectedNetwork.file })}
+ </span>
+ <div className="build__fix">
+ <Button onClick={() => void window.estella.shell?.showItem?.(selectedNetwork.file!)}>
+ <FolderOpen size={12} /> {t('build.revealFiles')}
+ </Button>
+ </div>
+ </div>
+ </div>
+ )}
<div className="build__hint">
<Info size={11} /> {t('build.adNetworkHint')}
</div>
diff --git a/desktop/src/i18n/messages/project.ts b/desktop/src/i18n/messages/project.ts
index 2bea56247..3fd60be04 100644
--- a/desktop/src/i18n/messages/project.ts
+++ b/desktop/src/i18n/messages/project.ts
@@ -85,8 +85,8 @@ export const projectMessages = defineMessages({
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}”。',
+ en: 'Created {file} and selected it below. Fill in its size limit and CTA bridge, then package.',
+ zh: '已创建 {file},并已在下方选中它。填好它的体积上限与 CTA 桥接后即可打包。',
},
'build.revealFiles': { en: 'Show files', zh: '显示文件' },
'build.noCustomPlatforms': {
@@ -155,6 +155,10 @@ export const projectMessages = defineMessages({
en: 'Decides the size limit, what goes in <head>, and the API playableCta() calls.',
zh: '决定体积上限、<head> 注入内容,以及 playableCta() 调用的接口。',
},
+ 'build.adNetworkFile': {
+ en: 'Defined by this project in {file}.',
+ zh: '由本项目在 {file} 中定义。',
+ },
'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\' 的配置来添加。',
diff --git a/desktop/tests/platform-catalog.test.ts b/desktop/tests/platform-catalog.test.ts
index 9b204dfd1..ebb2d5ccb 100644
--- a/desktop/tests/platform-catalog.test.ts
+++ b/desktop/tests/platform-catalog.test.ts
@@ -306,7 +306,12 @@ describe('playable ad networks', () => {
const rows = await listPlayableNetworks(root);
expect(rows.filter((r) => r.source === 'builtin').map((r) => r.id))
.toEqual(['generic', 'meta', 'google', 'mraid', 'unity', 'applovin']);
- expect(rows.find((r) => r.id === 'acme-ads')).toMatchObject({ label: 'Acme Ads', source: 'project' });
+ // A project network names the file that defines it, so the dialog can point at it
+ // (and at the error, when one fails to load). Built-ins have no file.
+ expect(rows.find((r) => r.id === 'acme-ads')).toMatchObject({
+ label: 'Acme Ads', source: 'project', file: '.esengine/platforms/acme-ads.mjs',
+ });
+ expect(rows.find((r) => r.id === 'meta')!.file).toBeUndefined();
});
it('resolves a project network to a profile the export can run with', async () => {
@@ -370,6 +375,8 @@ describe('playable ad networks', () => {
writePlatform('bad.mjs', "export default { id: 'bad', kind: 'playable', label: 'Bad' };");
const row = (await listPlayableNetworks(root)).find((r) => r.id === 'bad');
expect(row!.error).toMatch(/maxBytes/);
+ // Named WITH its file — an error you cannot locate is barely an error report.
+ expect(row!.file).toBe('.esengine/platforms/bad.mjs');
});
it('keeps networks out of the platform list, and platforms out of the network list', async () => {