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): the Steam settings are settable, not hand-edited JSON

esengine49b2404fc992
diff --git a/desktop/src/i18n/messages/settings.ts b/desktop/src/i18n/messages/settings.ts
index 9259d7b25..2c83decd5 100644
--- a/desktop/src/i18n/messages/settings.ts
+++ b/desktop/src/i18n/messages/settings.ts
@@ -385,6 +385,32 @@ export const settingsMessages = defineMessages({
en: 'Overrides the Application ID for the desktop app only (its bundle identifier).',
zh: '仅为桌面应用覆盖应用 ID(即其 bundle identifier)。',
},
+ 'set.desktop.channel.standalone': { en: 'Standalone', zh: '独立发行' },
+ 'set.desktop.channel.steam': { en: 'Steam', zh: 'Steam' },
+ 'set.group.steam': { en: 'Steam', zh: 'Steam' },
+ 'set.project.packaging.desktop.channel': { en: 'Distribution', zh: '发行渠道' },
+ 'set.project.packaging.desktop.channel.desc': {
+ en: 'Where this desktop build goes. Steam also writes the depot scripts and a STEAM.md '
+ + 'listing the values only the partner backend can be told.',
+ zh: '这份桌面构建发往哪里。选 Steam 会额外写出 depot 脚本,以及一份 STEAM.md,'
+ + '列出只能在合作伙伴后台填写的那些值。',
+ },
+ 'set.project.packaging.desktop.steam.appId': { en: 'Steam App ID', zh: 'Steam App ID' },
+ 'set.project.packaging.desktop.steam.appId.desc': {
+ en: 'From the Steamworks partner site. Without it no depot scripts are written — scripts '
+ + 'built around a guessed id would name someone else\'s game.',
+ zh: '来自 Steamworks 合作伙伴后台。不填就不会写出任何 depot 脚本——'
+ + '用猜出来的 id 生成的脚本指向的是别人的游戏。',
+ },
+ 'set.project.packaging.desktop.steam.depot.macos': { en: 'macOS depot ID', zh: 'macOS depot ID' },
+ 'set.project.packaging.desktop.steam.depot.windows': { en: 'Windows depot ID', zh: 'Windows depot ID' },
+ 'set.project.packaging.desktop.steam.depot.linux': { en: 'Linux depot ID', zh: 'Linux depot ID' },
+ 'set.project.packaging.desktop.steam.depot.desc': {
+ en: 'Valve assigns depot ids; leave at 0 to use App ID + 1, …, which the generated '
+ + 'STEAM.md tells you to check against SteamPipe → Depots.',
+ zh: 'depot id 由 Valve 分配;留 0 则使用 App ID + 1、+2…,'
+ + '生成的 STEAM.md 会提示你去 SteamPipe → Depots 核对。',
+ },
'set.project.packaging.desktop.productName': { en: 'Product name', zh: '产品名称' },
'set.project.packaging.desktop.productName.desc': {
en: 'Display name for the desktop app, and the name of the app itself (defaults to the project name).',
diff --git a/desktop/src/project/ProjectStore.ts b/desktop/src/project/ProjectStore.ts
index 1a5cc9035..84e9afad6 100644
--- a/desktop/src/project/ProjectStore.ts
+++ b/desktop/src/project/ProjectStore.ts
@@ -43,7 +43,7 @@ import { confirm } from '@/components/confirm';
import { previewApply } from './applyPreview';
import { t } from '@/i18n';
import { ASSET_SLOTS, metaTypeToSlot } from '@/project/assetSlots';
-import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, resolveScripts, DEFAULT_SCRIPTS, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, SORTING_LAYER_COUNT, trimSortingLayers, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type ProjectScripts, type WorkspaceState, type DesignResolution, type ScreenPreset, type ScreenOrientation, type CameraScaleMode, type ExportPlatform } from './format';
+import { resolveLayout, orientationFromDesignResolution, resolveOrientation, cameraScaleModeValue, resolveScripts, DEFAULT_SCRIPTS, WORKSPACE_DIR, PROJECT_MANIFEST_FILE, SORTING_LAYER_COUNT, trimSortingLayers, type OpenedProject, type ProjectFeatures, type ProjectLayout, type ProjectPackaging, type SteamPackaging, type ProjectScripts, type WorkspaceState, type DesignResolution, type ScreenPreset, type ScreenOrientation, type CameraScaleMode, type ExportPlatform } from './format';
import { useEditorMode } from '@/store/editorModeStore';
import { PlayInspect } from '@/engine/PlayInspect';
import { useEditorStore } from '@/store/editorStore';
@@ -1973,6 +1973,31 @@ class ProjectStoreImpl {
}
/** Persist one platform's packaging config (merged) to `project.esproject`. */
+ /**
+ * Merge into `packaging.platforms.desktop.steam`.
+ *
+ * Its own method because setPlatformPackaging merges one level: patching
+ * `{ steam: { appId } }` through it would DROP the depot ids the project had.
+ */
+ async setSteamPackaging(patch: Partial<SteamPackaging>): Promise<void> {
+ const steam = { ...this.platformPackaging().desktop?.steam, ...patch };
+ for (const key of Object.keys(steam) as (keyof SteamPackaging)[]) {
+ if (steam[key] === undefined) delete steam[key];
+ }
+ await this.setPlatformPackaging('desktop', {
+ steam: Object.keys(steam).length > 0 ? steam : undefined,
+ });
+ }
+
+ /** Set (or clear with undefined) one OS's depot id, keeping the others. */
+ async setSteamDepot(os: 'macos' | 'windows' | 'linux', id: number | undefined): Promise<void> {
+ const depots = { ...this.platformPackaging().desktop?.steam?.depots };
+ if (id === undefined) delete depots[os]; else depots[os] = id;
+ await this.setSteamPackaging({
+ depots: Object.keys(depots).length > 0 ? depots : undefined,
+ });
+ }
+
async setPlatformPackaging<K extends keyof NonNullable<ProjectPackaging['platforms']>>(
platform: K,
patch: Partial<NonNullable<NonNullable<ProjectPackaging['platforms']>[K]>>,
diff --git a/desktop/src/settings/projectSettings.ts b/desktop/src/settings/projectSettings.ts
index c7c25d664..058eea2f5 100644
--- a/desktop/src/settings/projectSettings.ts
+++ b/desktop/src/settings/projectSettings.ts
@@ -17,6 +17,13 @@ import { useEditorMode } from '@/store/editorModeStore';
import { SORTING_LAYER_COUNT, type ScreenOrientation, type CameraScaleMode, type ScreenPreset } from '@/project/format';
import { t } from '@/i18n';
+/** Where a desktop build goes. A channel, not a platform — see
+ * docs/REARCH_STEAM.md §1. */
+const DESKTOP_CHANNEL = [
+ { value: 'standalone', label: t('set.desktop.channel.standalone') },
+ { value: 'steam', label: t('set.desktop.channel.steam') },
+];
+
const ORIENTATION = [
{ value: 'portrait', label: t('set.orientation.portrait') },
{ value: 'landscape', label: t('set.orientation.landscape') },
@@ -444,6 +451,53 @@ settingsRegistry.register({
},
});
+settingsRegistry.register({
+ id: 'project.packaging.desktop.channel',
+ type: 'enum', scope: 'project', section: 'packaging', group: t('set.group.desktop'),
+ label: t('set.project.packaging.desktop.channel'),
+ description: t('set.project.packaging.desktop.channel.desc'),
+ options: DESKTOP_CHANNEL, segmented: true, default: 'standalone',
+ bind: {
+ get: () => ProjectStore.platformPackaging().desktop?.channel ?? 'standalone',
+ set: (v) => void ProjectStore.setPlatformPackaging('desktop', {
+ channel: v as 'standalone' | 'steam',
+ }),
+ },
+});
+
+settingsRegistry.register({
+ id: 'project.packaging.desktop.steam.appId',
+ type: 'number', scope: 'project', section: 'packaging', group: t('set.group.steam'),
+ label: t('set.project.packaging.desktop.steam.appId'),
+ description: t('set.project.packaging.desktop.steam.appId.desc'),
+ default: 0, min: 0, step: 1,
+ bind: {
+ get: () => ProjectStore.platformPackaging().desktop?.steam?.appId ?? 0,
+ // 0 clears it rather than shipping a scripts-for-game-zero build: the export
+ // says so and writes no depot scripts.
+ set: (v) => void ProjectStore.setSteamPackaging({
+ appId: v > 0 ? Math.round(v) : undefined,
+ }),
+ },
+});
+
+// One row per OS, because Valve assigns a depot id per OS and they are rarely the
+// three consecutive numbers the default guesses. The generated STEAM.md prints
+// what this build used, next to where to check it.
+for (const os of ['macos', 'windows', 'linux'] as const) {
+ settingsRegistry.register({
+ id: `project.packaging.desktop.steam.depot.${os}`,
+ type: 'number', scope: 'project', section: 'packaging', group: t('set.group.steam'),
+ label: t(`set.project.packaging.desktop.steam.depot.${os}`),
+ description: t('set.project.packaging.desktop.steam.depot.desc'),
+ default: 0, min: 0, step: 1,
+ bind: {
+ get: () => ProjectStore.platformPackaging().desktop?.steam?.depots?.[os] ?? 0,
+ set: (v) => void ProjectStore.setSteamDepot(os, v > 0 ? Math.round(v) : undefined),
+ },
+ });
+}
+
settingsRegistry.register({
id: 'project.physics.gravityY',
type: 'number',
diff --git a/desktop/tests/steam-settings.test.ts b/desktop/tests/steam-settings.test.ts
new file mode 100644
index 000000000..82b3d05d6
--- /dev/null
+++ b/desktop/tests/steam-settings.test.ts
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file The Steam packaging settings, and the merge that keeps them.
+ *
+ * `steam` is the one nested object in packaging, and setPlatformPackaging merges
+ * exactly one level — so patching `{ steam: { appId } }` through it would drop
+ * the depot ids the project had. That is the whole reason these setters exist.
+ */
+import { describe, it, expect } from 'vitest';
+import type { SteamPackaging } from '@/project/format';
+
+/** The merge, as the store performs it, over a plain object. */
+function mergeSteam(prev: SteamPackaging | undefined, patch: Partial<SteamPackaging>): SteamPackaging | undefined {
+ const steam = { ...prev, ...patch };
+ for (const key of Object.keys(steam) as (keyof SteamPackaging)[]) {
+ if (steam[key] === undefined) delete steam[key];
+ }
+ return Object.keys(steam).length > 0 ? steam : undefined;
+}
+
+function setDepot(prev: SteamPackaging | undefined, os: 'macos' | 'windows', id: number | undefined) {
+ const depots = { ...prev?.depots };
+ if (id === undefined) delete depots[os]; else depots[os] = id;
+ return mergeSteam(prev, { depots: Object.keys(depots).length > 0 ? depots : undefined });
+}
+
+describe('the Steam packaging settings', () => {
+ it('setting the App ID keeps depot ids the project already had', () => {
+ const prev: SteamPackaging = { appId: 480, depots: { macos: 90210 } };
+ expect(mergeSteam(prev, { appId: 500 })).toEqual({ appId: 500, depots: { macos: 90210 } });
+ });
+
+ it('setting one depot keeps the others and the App ID', () => {
+ const prev: SteamPackaging = { appId: 480, depots: { macos: 1 } };
+ expect(setDepot(prev, 'windows', 2)).toEqual({ appId: 480, depots: { macos: 1, windows: 2 } });
+ });
+
+ it('clearing the last value leaves nothing rather than an empty husk', () => {
+ expect(mergeSteam({ appId: 480 }, { appId: undefined })).toBeUndefined();
+ expect(setDepot({ depots: { macos: 1 } }, 'macos', undefined)).toBeUndefined();
+ });
+
+ it('a zero App ID is absence, not a game id', () => {
+ // The settings row maps 0 to undefined; a build with appId 0 would write
+ // scripts naming an app that is not anyone's.
+ expect(mergeSteam(undefined, { appId: undefined })).toBeUndefined();
+ });
+});