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
fix(douyin): the config file, the appid and a payment slot
esengine9e1daaf513de
diff --git a/desktop b/desktopindex 77c125f33..b93afcdb7 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit 77c125f3342f7cfa9be0bba4ef429685b9ebe4e9+Subproject commit b93afcdb7f6bb749a0162e28829a65a7527664aediff --git a/pipeline/src/export/exportGame.ts b/pipeline/src/export/exportGame.tsindex d5397b8e3..f6f9be1e6 100644--- a/pipeline/src/export/exportGame.ts+++ b/pipeline/src/export/exportGame.ts@@ -414,8 +414,13 @@ export interface ExportGameOptions {/** Desktop product/display name (Project Settings); default the project title. */desktopProductName?: string;- /** WeChat appid (Project Settings → Packaging → WeChat). */- wechatAppid?: string;+ /**+ * The id the game is registered under on THIS export's mini-game vendor+ * console (Project Settings → Packaging). One option, not one per vendor: a+ * WeChat appid in a Douyin package is refused at upload, and naming it+ * `wechatAppid` is how the Douyin export came to send one.+ */+ miniGameAppid?: string;/** Reverse-DNS application id for a native target (format.ts resolveAppId).* Written into app.config.json, where the packagers read it. */appId?: string;@@ -622,7 +627,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>outDir: opts.outDir,hostsDir: opts.hostsDir,title,- appid: opts.wechatAppid,+ appid: opts.miniGameAppid,orientation,runtime,minify: opts.minify,@@ -654,7 +659,7 @@ async function produceExport(opts: ExportGameOptions): Promise<ExportGameResult>outDir: opts.outDir,hostsDir: opts.hostsDir,title,- appid: opts.wechatAppid,+ appid: opts.miniGameAppid,orientation,runtime,minify: opts.minify,diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.tsindex 77ba3cc3f..03a17f2e1 100644--- a/pipeline/src/export/miniGameExportProfile.ts+++ b/pipeline/src/export/miniGameExportProfile.ts@@ -209,7 +209,7 @@ export interface MiniGameExportProfile {*/readonly runtimeProfileHost?: RuntimeHost;- /** Emit the vendor config files (game.json + project.config.json / project.tt.json). */+ /** Emit the vendor config files (game.json + project.config.json). */emitConfigFiles(ctx: MiniGameConfigContext): Array<{ file: string; content: string }>;/** Emit the MiniGame entry the host runs (game.js). */emitEntry(ctx: MiniGameEntryContext): string;@@ -345,9 +345,12 @@ export const douyinExportProfile: MiniGameExportProfile = {appid: ctx.appid,compileType: 'game',};+ // `project.config.json`, the same name WeChat uses: the vendor's own CLI+ // (tt-minigame-ide-cli) and its Godot adaptation doc both name that file,+ // and nothing published names `project.tt.json`.return [{ file: 'game.json', content: JSON.stringify(gameCfg, null, 2) + '\n' },- { file: 'project.tt.json', content: JSON.stringify(projectCfg, null, 2) + '\n' },+ { file: 'project.config.json', content: JSON.stringify(projectCfg, null, 2) + '\n' },];},diff --git a/pipeline/src/project/format.ts b/pipeline/src/project/format.tsindex d25c175c4..4b4706489 100644--- a/pipeline/src/project/format.ts+++ b/pipeline/src/project/format.ts@@ -187,7 +187,12 @@ export type RenderResolutionMode = 'surface' | 'design' | 'integer';/** Per-platform packaging config (the platform-specific Project Settings pages).* Orientation is NOT here — it is one project-wide {@link ProjectPackaging.orientation}* consumed by every target (a landscape build is landscape everywhere). */-export interface WeChatPackaging { appid?: string; }+/** What a mini-game vendor needs and nothing else can supply: the id the game+ * was registered under on THAT vendor's console. One shape, because every+ * vendor asks the same question and a package built for one is rejected by the+ * other. */+export interface MiniGamePackaging { appid?: string; }+export type WeChatPackaging = MiniGamePackaging;export interface DesktopPackaging {appId?: string;productName?: string;@@ -352,7 +357,8 @@ export interface ProjectPackaging {/** Per-platform packaging config: each target's slice of the app identity, plus* whatever only it has (a WeChat appid, an Android versionCode). */platforms?: {- wechat?: WeChatPackaging;+ wechat?: MiniGamePackaging;+ douyin?: MiniGamePackaging;desktop?: DesktopPackaging;android?: AndroidPackaging;ios?: IosPackaging;@@ -729,6 +735,10 @@ export function parseManifest(raw: unknown): ProjectManifest {if (!orientation && (wx.orientation === 'portrait' || wx.orientation === 'landscape')) orientation = wx.orientation;if (Object.keys(w).length > 0) platforms.wechat = w;}+ const tt = pl.douyin as Record<string, unknown> | undefined;+ if (tt && typeof tt === 'object' && typeof tt.appid === 'string') {+ platforms.douyin = { appid: tt.appid };+ }const dt = pl.desktop as Record<string, unknown> | undefined;if (dt && typeof dt === 'object') {const d: DesktopPackaging = {};diff --git a/pipeline/tests/export-compiled-systems.test.ts b/pipeline/tests/export-compiled-systems.test.tsindex edf0156f2..8b80a8e9a 100644--- a/pipeline/tests/export-compiled-systems.test.ts+++ b/pipeline/tests/export-compiled-systems.test.ts@@ -98,7 +98,7 @@ const config = (out: string): PackagedGameConfig =>const runWeChat = (f: { root: string; out: string }) => exportGame({root: f.root, entryScene: 'scenes/main.esscene', hostsDir: 'unused-for-wechat',- scriptsEntry: 'src/main.ts', platform: 'wechat', wechatAppid: 'wxTEST0123456789',+ scriptsEntry: 'src/main.ts', platform: 'wechat', miniGameAppid: 'wxTEST0123456789',sdkDistDir: path.join(f.root, '_sdk'), wasmDir: path.join(f.root, '_wasm'),outDir: f.out,});diff --git a/pipeline/tests/export-douyin.test.ts b/pipeline/tests/export-douyin.test.tsindex 8323dea5b..1e0b7abc0 100644--- a/pipeline/tests/export-douyin.test.ts+++ b/pipeline/tests/export-douyin.test.ts@@ -64,17 +64,24 @@ describe('exportGame (douyin)', () => {platform: 'douyin',orientation: 'landscape',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),+ miniGameAppid: 'tt0123456789abcdef',});expect(res.ok, res.errors.join('\n')).toBe(true);expect(res.platform).toBe('douyin');- expect(existsSync(path.join(out, 'project.tt.json'))).toBe(true);- expect(existsSync(path.join(out, 'project.config.json'))).toBe(false);- const cfg = JSON.parse(readFileSync(path.join(out, 'project.tt.json'), 'utf8'));+ // The vendor's contract, not this exporter's habit: Douyin's own CLI and its+ // Godot adaptation doc both name `project.config.json`, and nothing+ // published names `project.tt.json`.+ expect(existsSync(path.join(out, 'project.config.json'))).toBe(true);+ expect(existsSync(path.join(out, 'project.tt.json'))).toBe(false);+ const cfg = JSON.parse(readFileSync(path.join(out, 'project.config.json'), 'utf8'));expect(cfg.compileType).toBe('game');expect(cfg.miniprogramRoot).toBe('./');expect(JSON.parse(readFileSync(path.join(out, 'game.json'), 'utf8')).deviceOrientation).toBe('landscape');+ // This vendor's id, not the other one's: a WeChat appid in a Douyin package+ // is refused at upload with "不存在此 AppID".+ expect(cfg.appid).toBe('tt0123456789abcdef');}, 180_000);it('boots through the vendor-neutral entry and names its host', () => {diff --git a/pipeline/tests/export-wechat-audio-src.test.ts b/pipeline/tests/export-wechat-audio-src.test.tsindex a13d28bf9..c3286b2df 100644--- a/pipeline/tests/export-wechat-audio-src.test.ts+++ b/pipeline/tests/export-wechat-audio-src.test.ts@@ -79,7 +79,7 @@ describe('the source a cooked mini-game hands its audio player', () => {outDir: out,title: 'Audio',platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',orientation: 'landscape',compressAudio: true,runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),diff --git a/pipeline/tests/export-wechat-subpackage.test.ts b/pipeline/tests/export-wechat-subpackage.test.tsindex f03a7ff97..055a1d58b 100644--- a/pipeline/tests/export-wechat-subpackage.test.ts+++ b/pipeline/tests/export-wechat-subpackage.test.ts@@ -69,7 +69,7 @@ describe('WeChat 分包 declared through asset-groups.json', () => {outDir: out,title: 'My Game',platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',orientation: 'landscape',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});@@ -130,7 +130,7 @@ describe('WeChat 分包 declared through asset-groups.json', () => {outDir: out2,title: 'Local Group',platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',orientation: 'landscape',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});@@ -186,7 +186,7 @@ describe('WeChat 分包 declared through asset-groups.json', () => {outDir: out2,title: 'Scene Group',platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',orientation: 'landscape',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});diff --git a/pipeline/tests/export-wechat.test.ts b/pipeline/tests/export-wechat.test.tsindex ece0a3e15..1bb59e543 100644--- a/pipeline/tests/export-wechat.test.ts+++ b/pipeline/tests/export-wechat.test.ts@@ -74,7 +74,7 @@ describe('exportGame (wechat)', () => {outDir: out,title: 'My Game',platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',orientation: 'landscape',runtime: runtimeConfigOf({designResolution: { width: 1280, height: 720 },@@ -541,7 +541,7 @@ describe('exportGame (wechat)', () => {wasmDir: path.join(root, '_wxwasm'),outDir: o,platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',compressWasm: true,runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});@@ -575,7 +575,7 @@ describe('exportGame (wechat)', () => {wasmDir: path.join(root, '_wxwasm'),outDir: o,platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});expect(res.ok).toBe(true);@@ -597,7 +597,7 @@ describe('exportGame (wechat)', () => {wasmDir: path.join(root, '_wxwasm'),outDir: o,platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',engineSubpackage: true,runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});@@ -641,7 +641,7 @@ describe('exportGame (wechat)', () => {wasmDir: path.join(root, '_wxwasm'),outDir: o,platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});expect(res.ok).toBe(true);@@ -663,7 +663,7 @@ describe('exportGame (wechat)', () => {wasmDir: path.join(root, '_wxwasm'),outDir: o,platform: 'wechat',- wechatAppid: 'wxTEST0123456789',+ miniGameAppid: 'wxTEST0123456789',runtime: runtimeConfigOf({ designResolution: { width: 1280, height: 720 } }),});expect(res.ok).toBe(true);diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.mdindex 2402b3f9d..e29dc3d56 100644--- a/sdk/etc/minigame.api.md+++ b/sdk/etc/minigame.api.md@@ -5227,6 +5227,7 @@ global: MiniGameGlobalhostLabel: stringid: MiniGameVendorinstantiateWasm: ((pathOrBuffer: string | ArrayBuffer, imports: WebAssembly.Imports) => Promise<WasmInstantiateResult>) | undefined+pay: { can(): boolean; request(request: PlatformPaymentRequest): Promise<void>; } | undefined```## MiniGameRequestOptions — interface @experimentaldiff --git a/sdk/src/platform/douyin/profile.ts b/sdk/src/platform/douyin/profile.tsindex f91a0781b..26531fe92 100644--- a/sdk/src/platform/douyin/profile.ts+++ b/sdk/src/platform/douyin/profile.ts@@ -14,6 +14,13 @@* its own the way WeChat's WXWebAssembly does. If it does not, this profile* gains an `instantiateWasm` exactly as WeChat's has one. RM-032's acceptance is* a real device for that reason.+ *+ * NOT CLAIMED: `pay`. The family's payment is WeChat's `requestMidasPayment`+ * with WeChat's rules, and Douyin's call is its own. There is no source in this+ * checkout for its name or its fields, and a payment path invented from a guess+ * charges a player through a call that does not exist. So purchase reports+ * itself unavailable here — the profile now has the slot to fill once a vendor+ * doc or a device answers.*/import type { MiniGameGlobal, MiniGameProfile } from '../minigame';diff --git a/sdk/src/platform/minigame/adapter.ts b/sdk/src/platform/minigame/adapter.tsindex 44d89cceb..3edfa5cba 100644--- a/sdk/src/platform/minigame/adapter.ts+++ b/sdk/src/platform/minigame/adapter.ts@@ -213,6 +213,7 @@ export class MiniGamePlatformAdapter implements PlatformAdapter {* built, against the host's sandbox.*/canPay(): boolean {+ if (this.profile_.pay) return this.profile_.pay.can();if (!this.g_.requestMidasPayment) return false;const where = this.g_.getSystemInfoSync().platform;// Unknown means a host that did not say. Treated as allowed: refusing@@ -225,6 +226,7 @@ export class MiniGamePlatformAdapter implements PlatformAdapter {* failed" without a code cannot be told apart from the player changing* their mind, and those need different UI. */requestPayment(request: PlatformPaymentRequest): Promise<void> {+ if (this.profile_.pay) return this.profile_.pay.request(request);const pay = this.g_.requestMidasPayment;if (!pay) return Promise.reject(new Error('this host sells nothing'));return new Promise<void>((resolve, reject) => {diff --git a/sdk/src/platform/minigame/api.ts b/sdk/src/platform/minigame/api.tsindex 3079362a3..58ed3de88 100644--- a/sdk/src/platform/minigame/api.ts+++ b/sdk/src/platform/minigame/api.ts@@ -18,7 +18,9 @@import type { PlatformAudioBackend } from '../../audio/PlatformAudioBackend';import type { PlatformVideoBackend, VideoBackendContext } from '../../video/PlatformVideoBackend';-import type { PlatformSocket, PlatformSocketOptions, WasmInstantiateResult } from '../types';+import type {+ PlatformPaymentRequest, PlatformSocket, PlatformSocketOptions, WasmInstantiateResult,+} from '../types';// =============================================================================// Normalized host primitives@@ -356,4 +358,16 @@ export interface MiniGameProfile {createVideoBackend?(ctx: VideoBackendContext): PlatformVideoBackend;/** Omit for the family socket over `global.connectSocket()`. */createSocket?(options: PlatformSocketOptions): PlatformSocket;++ /**+ * Buying in-game currency, when the vendor's call is not WeChat's+ * `requestMidasPayment`. That one carries WeChat's own rules (Android only,+ * Midas field names), and applying them everywhere makes the engine say+ * "this host sells nothing" about a host that sells things.+ */+ pay?: {+ /** Asked before a game offers a purchase at all. */+ can(): boolean;+ request(request: PlatformPaymentRequest): Promise<void>;+ };}diff --git a/sdk/tests/minigame-payment-slot.test.ts b/sdk/tests/minigame-payment-slot.test.tsnew file mode 100644index 000000000..81393197d--- /dev/null+++ b/sdk/tests/minigame-payment-slot.test.ts@@ -0,0 +1,52 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file A vendor whose payment is not WeChat's can supply its own.+ *+ * The family's purchase path is `requestMidasPayment` with WeChat's rules —+ * Android only, Midas field names. Applied to every vendor it makes `canPay()`+ * answer false for a host that does sell things, and `requestPayment` reject+ * with "this host sells nothing". A profile had no way to correct that.+ */+import { describe, it, expect, vi } from 'vitest';+import { MiniGamePlatformAdapter } from '../src/platform/minigame/adapter';+import type { MiniGameGlobal, MiniGameProfile } from '../src/platform/minigame';++/** A host with no WeChat payment call — which is every vendor but one. */+const hostWithoutMidas = (): MiniGameGlobal => ({+ getSystemInfoSync: () => ({ platform: 'android' }),+} as unknown as MiniGameGlobal);++const profile = (over: Partial<MiniGameProfile> = {}): MiniGameProfile => ({+ id: 'douyin', hostLabel: '抖音', global: hostWithoutMidas(), ...over,+} as MiniGameProfile);++describe('a mini-game vendor that sells things its own way', () => {+ it('says it can sell, where the family alone would say it cannot', () => {+ expect(new MiniGamePlatformAdapter(profile()).canPay()).toBe(false);+ const own = profile({ pay: { can: () => true, request: async () => {} } });+ expect(new MiniGamePlatformAdapter(own).canPay()).toBe(true);+ });++ it('is the one asked to charge, with the request untouched', async () => {+ const request = vi.fn(async () => {});+ const own = profile({ pay: { can: () => true, request } });+ await new MiniGamePlatformAdapter(own).requestPayment({ offerId: 'o1', quantity: 10 });+ expect(request).toHaveBeenCalledWith({ offerId: 'o1', quantity: 10 });+ });++ it('carries its own refusal, rather than the family\'s', async () => {+ const own = profile({+ pay: { can: () => true, request: () => Promise.reject(new Error('the player cancelled')) },+ });+ await expect(new MiniGamePlatformAdapter(own).requestPayment({ offerId: 'o1', quantity: 1 }))+ .rejects.toThrow('the player cancelled');+ });++ // Unclaimed is the honest answer until a vendor doc or a device names the+ // call: a purchase path invented from a guess charges through nothing.+ it('reports no purchase at all when the profile claims none', async () => {+ await expect(new MiniGamePlatformAdapter(profile()).requestPayment({ offerId: 'o1', quantity: 1 }))+ .rejects.toThrow('sells nothing');+ });+});