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): one icon setting, both platforms

esengine001e4b4ecbd4
diff --git a/build-tools/utils/iosProject.d.ts b/build-tools/utils/iosProject.d.ts
index 821fa11ff..955e3813f 100644
--- a/build-tools/utils/iosProject.d.ts
+++ b/build-tools/utils/iosProject.d.ts
@@ -16,6 +16,8 @@ export interface IosProjectSources {
mainM: string;
/** The Info.plist template the app's identity is substituted into. */
infoPlistIn: string;
+ /** The template's default launcher icon, used when the project sets none. */
+ icon: string;
}
export interface IosAppIdentity {
@@ -31,4 +33,5 @@ export function emitIosXcodeProject(
app: IosAppIdentity,
sources: IosProjectSources,
deploymentTarget?: string,
+ icon?: Buffer,
): Promise<string>;
diff --git a/build-tools/utils/iosProject.js b/build-tools/utils/iosProject.js
index a454c132f..7eafaa2f7 100644
--- a/build-tools/utils/iosProject.js
+++ b/build-tools/utils/iosProject.js
@@ -18,6 +18,24 @@ import { cp, mkdir, readdir, rm, readFile, writeFile } from 'fs/promises';
import { renderPbxproj, renderScheme } from './xcodeProject.js';
import { iosInterfaceOrientations } from './nativeApp.js';
+/** The asset catalog Xcode compiles the app icon out of. A single 1024×1024 image
+ * is all a modern catalog needs — Xcode derives every size the system asks for,
+ * so nothing here resizes anything. */
+const ICON_CATALOG = 'Assets.xcassets';
+
+async function writeIconCatalog(contentDir, iconPng) {
+ const iconSet = path.join(contentDir, ICON_CATALOG, 'AppIcon.appiconset');
+ await mkdir(iconSet, { recursive: true });
+ await writeFile(path.join(iconSet, 'icon.png'), iconPng);
+ await writeFile(path.join(iconSet, 'Contents.json'), `${JSON.stringify({
+ images: [{ filename: 'icon.png', idiom: 'universal', platform: 'ios', size: '1024x1024' }],
+ info: { author: 'estella', version: 1 },
+ }, null, 2)}\n`);
+ await writeFile(path.join(contentDir, ICON_CATALOG, 'Contents.json'), `${JSON.stringify({
+ info: { author: 'estella', version: 1 },
+ }, null, 2)}\n`);
+}
+
/** A target/product name Xcode and the shell can both carry unquoted. */
function targetName(appName) {
return appName.replace(/[^A-Za-z0-9]+/g, '') || 'EstellaGame';
@@ -31,12 +49,13 @@ function targetName(appName) {
* @param {string} contentDir The export (cooked content + the two configs).
* @param {{id: string, name: string, version: string, versionCode: number,
* orientation: 'landscape'|'portrait'}} app From `app.config.json`.
- * @param {{xcframework: string, mainM: string, infoPlistIn: string}} sources
+ * @param {{xcframework: string, mainM: string, infoPlistIn: string, icon?: string}} sources
* The prebuilt pieces, out of the installed runtime template.
* @param {string} [deploymentTarget]
+ * @param {Buffer} [icon] The launcher icon; the template's default when absent.
* @returns {Promise<string>} The `.xcodeproj` path, to reveal or open.
*/
-export async function emitIosXcodeProject(contentDir, app, sources, deploymentTarget = '17.0') {
+export async function emitIosXcodeProject(contentDir, app, sources, deploymentTarget = '17.0', icon) {
const name = targetName(app.name);
const frameworkName = 'Estella.xcframework';
const projectDir = path.join(contentDir, `${name}.xcodeproj`);
@@ -48,11 +67,14 @@ export async function emitIosXcodeProject(contentDir, app, sources, deploymentTa
await rm(projectDir, { recursive: true, force: true });
await rm(appDir, { recursive: true, force: true });
await rm(frameworkDest, { recursive: true, force: true });
+ await rm(path.join(contentDir, ICON_CATALOG), { recursive: true, force: true });
await cp(sources.xcframework, frameworkDest, { recursive: true });
await mkdir(appDir, { recursive: true });
await cp(sources.mainM, path.join(appDir, 'main.m'));
+ await writeIconCatalog(contentDir, icon ?? await readFile(sources.icon));
+
const template = await readFile(sources.infoPlistIn, 'utf8');
const orientations = iosInterfaceOrientations(app.orientation)
.map((o) => `\t\t<string>${o}</string>`).join('\n');
diff --git a/build-tools/utils/xcodeProject.js b/build-tools/utils/xcodeProject.js
index 11445519a..b0915292b 100644
--- a/build-tools/utils/xcodeProject.js
+++ b/build-tools/utils/xcodeProject.js
@@ -53,6 +53,10 @@ const SYSTEM_FRAMEWORKS = [
/** Xcode's file type for an export resource, by extension. `folder` ships a
* directory as-is, keeping the cooked tree's shape inside the bundle. */
function fileType(name, isDir) {
+ // An asset catalog is a directory Xcode COMPILES (actool) rather than copies —
+ // which is the whole reason the app icon goes through one: since iOS 11 the
+ // store takes icons no other way.
+ if (name.endsWith('.xcassets')) return 'folder.assetcatalog';
if (isDir) return 'folder';
if (name.endsWith('.json')) return 'text.json';
if (name.endsWith('.js')) return 'sourcecode.javascript';
@@ -126,6 +130,7 @@ export function renderPbxproj(o) {
CURRENT_PROJECT_VERSION: String(o.versionCode),
INFOPLIST_FILE: 'App/Info.plist',
GENERATE_INFOPLIST_FILE: 'NO',
+ ASSETCATALOG_COMPILER_APPICON_NAME: 'AppIcon',
CODE_SIGN_STYLE: 'Automatic',
// The xcframework sits at the project root, next to the export's files.
FRAMEWORK_SEARCH_PATHS: ['$(inherited)', '$(PROJECT_DIR)'],
diff --git a/desktop/electron/exportGame.ts b/desktop/electron/exportGame.ts
index 5a24a7eba..fbb4aeac5 100644
--- a/desktop/electron/exportGame.ts
+++ b/desktop/electron/exportGame.ts
@@ -434,6 +434,8 @@ export async function exportGame(opts: {
/** Android: the identity to sign with. Omitted uses the development key, which
* installs on a device and is refused by every store. */
androidKey?: SigningKey;
+ /** The app's launcher icon (project-relative). Omitted ⇒ the template's default. */
+ appIcon?: string;
}): Promise<ExportGameResult> {
const platform = opts.platform ?? 'web';
const title = opts.title ?? 'Game';
@@ -663,6 +665,16 @@ export async function exportGame(opts: {
};
await writeFile(path.join(payloadDir, 'app.config.json'), JSON.stringify(appConfig, null, 2) + '\n');
+ // One icon for both targets, read once. A path that no longer exists is a
+ // warning rather than a failed export: the package is still correct, it just
+ // carries the default mark.
+ let icon: Buffer | undefined;
+ if (opts.appIcon) {
+ const file = path.join(opts.root, opts.appIcon);
+ if (existsSync(file)) icon = await readFile(file);
+ else warnings.push(`The app icon ${opts.appIcon} does not exist — packaged with Estella's default.`);
+ }
+
// Both mobile targets finish the job here, out of the installed runtime
// template: assembling an app is copying files and writing two formats, so it
// belongs in the export rather than behind a command the user has to find. An
@@ -671,7 +683,7 @@ export async function exportGame(opts: {
progress({ phase: 'Writing Xcode project' });
const sources = opts.iosSources ?? null;
if (sources) {
- const projectDir = await emitIosXcodeProject(absOut, appConfig, sources);
+ const projectDir = await emitIosXcodeProject(absOut, appConfig, sources, undefined, icon);
xcodeProject = projectDir;
} else {
warnings.push('No iOS runtime template is installed for this editor version, so no Xcode '
@@ -685,7 +697,7 @@ export async function exportGame(opts: {
const template = opts.androidTemplate ?? null;
if (template) {
const key = opts.androidKey ?? debugSigningKey();
- const assembly = { templateDir: template.dir, contentDir: absOut, app: appConfig, abi: template.abi, key };
+ const assembly = { templateDir: template.dir, contentDir: absOut, app: appConfig, abi: template.abi, key, icon };
apkFile = path.join(absOut, apkFileName(appConfig.id));
await writeFile(apkFile, assembleApk(assembly));
if (opts.androidAppBundle) {
diff --git a/desktop/electron/main.ts b/desktop/electron/main.ts
index 76c111a97..00db2386d 100644
--- a/desktop/electron/main.ts
+++ b/desktop/electron/main.ts
@@ -883,6 +883,7 @@ ipcMain.handle(
appVersion: manifest.version,
androidVersionCode: plat?.android?.versionCode,
androidAppBundle: plat?.android?.appBundle,
+ appIcon: manifest.packaging?.icon,
// One project-wide orientation for every target: the explicit packaging
// setting, else derived from the design resolution's aspect.
orientation: resolveOrientation(manifest),
diff --git a/desktop/electron/nativeTemplates.ts b/desktop/electron/nativeTemplates.ts
index 0634e3bc8..6f1ed9000 100644
--- a/desktop/electron/nativeTemplates.ts
+++ b/desktop/electron/nativeTemplates.ts
@@ -50,7 +50,7 @@ export function resolveNativeTemplate(platform: NativePlatform, engineVersion: s
/** The three files an iOS Xcode project is built around, or null without a template. */
export function iosSourcesFromTemplate(engineVersion: string): {
- xcframework: string; mainM: string; infoPlistIn: string;
+ xcframework: string; mainM: string; infoPlistIn: string; icon: string;
} | null {
const template = resolveNativeTemplate('ios', engineVersion);
return template ? iosTemplateSources(template.dir) : null;
diff --git a/desktop/src/i18n/messages/settings.ts b/desktop/src/i18n/messages/settings.ts
index d93baa9fe..47001b5c5 100644
--- a/desktop/src/i18n/messages/settings.ts
+++ b/desktop/src/i18n/messages/settings.ts
@@ -229,6 +229,11 @@ export const settingsMessages = defineMessages({
en: 'Reverse-DNS id the installed app is known by — the Android manifest package, the iOS bundle id, the desktop installer id. Empty derives one from the project name; a published app should set its own, because a store keeps it forever.',
zh: '已安装应用的反向域名 id——Android 的 manifest package、iOS 的 bundle id、桌面安装包的 id。留空则按项目名推导;正式发布的应用应当自己指定,因为应用商店会永久沿用它。',
},
+ 'set.project.packaging.icon': { en: 'App Icon', zh: '应用图标' },
+ 'set.project.packaging.icon.desc': {
+ en: 'Project-relative square PNG, ideally 1024×1024 — the launcher icon on every installable target. Android takes it as the launcher mipmap and iOS as the asset catalog Xcode derives its sizes from, so one image is all you keep. Empty ships Estella\'s mark rather than the platform\'s placeholder.',
+ zh: '项目内的方形 PNG,建议 1024×1024——所有可安装目标的启动图标。Android 用作 launcher mipmap,iOS 用作 Xcode 据以派生各尺寸的 asset catalog,所以只需保留这一张。留空则使用 Estella 的标识,而不是平台的占位图。',
+ },
'set.project.packaging.android.versionCode': { en: 'Android Version Code', zh: 'Android 版本号' },
'set.project.packaging.android.versionCode.desc': {
en: 'The integer Google Play orders builds by — it must increase with every upload. The version users see comes from the project version.',
diff --git a/desktop/src/project/format.ts b/desktop/src/project/format.ts
index 7fffde389..bc7c3e36a 100644
--- a/desktop/src/project/format.ts
+++ b/desktop/src/project/format.ts
@@ -200,6 +200,16 @@ export interface ProjectPackaging {
* always has one — but a shipped app should say its own.
*/
appId?: string;
+ /**
+ * The app's launcher icon: a project-relative square PNG, ideally 1024×1024.
+ *
+ * ONE image for every installable target — Android takes it as the launcher
+ * mipmap, iOS as the asset catalog Xcode derives every size from. Nothing
+ * resizes it: both platforms scale, and a per-density set would be five files to
+ * keep in sync for a picture that is the same picture. Absent ⇒ Estella's own
+ * mark, so a packaged game never ships with the platform's placeholder.
+ */
+ icon?: string;
/** Per-platform packaging config: each target's slice of the app identity, plus
* whatever only it has (a WeChat appid, an Android versionCode). */
platforms?: {
diff --git a/desktop/src/settings/projectSettings.ts b/desktop/src/settings/projectSettings.ts
index 9fd14faa0..8da25eb98 100644
--- a/desktop/src/settings/projectSettings.ts
+++ b/desktop/src/settings/projectSettings.ts
@@ -316,6 +316,21 @@ settingsRegistry.register({
},
});
+// One icon for every installable target: Android takes it as the launcher mipmap,
+// iOS as the asset catalog Xcode derives its sizes from. Nothing resizes it, so
+// one large square is all a project keeps.
+settingsRegistry.register({
+ id: 'project.packaging.icon',
+ type: 'string', scope: 'project', section: 'packaging', group: t('set.group.application'),
+ label: t('set.project.packaging.icon'),
+ description: t('set.project.packaging.icon.desc'),
+ placeholder: 'assets/icon.png', default: '',
+ bind: {
+ get: () => ProjectStore.packagingSettings().icon ?? '',
+ set: (v) => void ProjectStore.setPackaging({ icon: v || undefined }),
+ },
+});
+
settingsRegistry.register({
id: 'project.packaging.android.versionCode',
type: 'number', scope: 'project', section: 'packaging', group: t('set.group.application'),