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(export): what each packaging target can do, before a build exists
esengine003edb7a7904
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 56e208d92..924b63b6d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -16,6 +16,8 @@ published separately; it ships inside the editor.### Added+- **The build dialog says which engine services a target can provide.** `Ads`, sign-in, share and in-game purchase all answer at runtime, by asking the host — the right answer for a game, and no answer at all for someone choosing a target, because there is no host yet. Each target now carries a line beside its size caps: WeChat's four are its own published API, and Douyin sells nothing, which is worth hearing before a store page is written rather than when the purchase call rejects on a device. A `?` is a real verdict, not a shrug — it is what the engine wires with the host having the last word, and hovering quotes the source.+- **The build says what the start screen's logo costs the page.** Inlined, the logo IS `index.html`, so a size report files it as page rather than as art — a start screen could quietly take a share of a main-package limit with nothing naming it. The export now states both numbers: the image on disk, and what it weighs in the page after base64.- **You can tell the editor which models your account has seen take an image.** A vendor that documents nothing leaves its models at "nobody has said", and no picture is sent to one of those — which used to mean waiting for us to ship a build. Settings › AI Agents now has a box per provider for the model names you have confirmed yourself.diff --git a/desktop b/desktopindex e33028a4f..a82bfdf7c 160000--- a/desktop+++ b/desktop@@ -1 +1 @@-Subproject commit e33028a4ff36f77e5274fa8316b8b482a5a92baf+Subproject commit a82bfdf7cac0ba41da9ab5d3b7a619fc0c91e55ddiff --git a/pipeline/src/project/serviceSupport.ts b/pipeline/src/project/serviceSupport.tsnew file mode 100644index 000000000..6405e6161--- /dev/null+++ b/pipeline/src/project/serviceSupport.ts@@ -0,0 +1,175 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file Which engine services a packaging target can actually provide.+ *+ * `Ads`, `Identity`, `Achievements` and in-game purchase all answer+ * `available` at RUNTIME, by asking the installed adapter — and that is+ * the right answer for a game, which can hide a button. It is no answer+ * at all for the person choosing a target in the build dialog, because+ * there is no host to ask yet. A Douyin build that sells nothing is a+ * fact worth hearing before the store page is written, not after the+ * purchase call rejects on a device.+ *+ * So this is the vocabulary of `sizeBudget.ts` one shelf over: what a+ * target can do, WHY we say so, quoted from whoever said it, all three+ * travelling together. Nothing here reads the filesystem, a host global+ * or React — the build dialog renders it, and `service-support.test.ts`+ * holds it against the adapters that will actually be installed.+ *+ * Deliberately NOT here: a runtime probe. This file is the pre-build+ * answer and is allowed to be less precise than the device; it is never+ * allowed to be more confident.+ */+import type { ExportPlatform } from './platforms';++/**+ * The services a game asks a platform for. Each is one optional method group on+ * `PlatformAdapter` (sdk/src/platform/types.ts) — the list is what an adapter+ * can decline to implement, not everything the engine offers.+ */+export const GAME_SERVICES = ['ads', 'share', 'signIn', 'purchase', 'achievements'] as const;+export type GameService = (typeof GAME_SERVICES)[number];++/**+ * How sure we are, before a build exists.+ *+ * `unknown` is a real answer and the commonest honest one: the engine wires the+ * call and the HOST decides. Saying `yes` there would be us promising on+ * someone else's behalf.+ */+export type ServiceSupport = 'yes' | 'no' | 'unknown';++/** One service on one target. */+export interface ServiceStatus {+ readonly service: GameService;+ readonly support: ServiceSupport;+ /**+ * Why — quoted verbatim where the source is the platform's own words, under+ * the same rule a size budget's note follows: a developer should be able to+ * check us against the vendor's current docs rather than trust us.+ */+ readonly note: string;+}++/**+ * The engine's achievements service is backed by a platform on Steam and+ * nowhere else; everywhere else it keeps its local provider, so a game's own+ * achievements screen works and the platform's does not exist.+ */+const ACHIEVEMENTS_LOCAL_ONLY =+ 'Only Steam backs achievements with a platform. Elsewhere the service keeps its local provider:'+ + ' unlocks are recorded and readable, and there is no system notification.';++/** What a browser, an ad frame and an app of our own have in common: nobody up+ * there sells, shares or signs anyone in on the game's behalf. */+const NO_HOST_ABOVE =+ 'This platform\'s adapter declares no such method — there is no host above the game offering it.'+ + ' A game can still install a provider of its own.';++/** Every service unsupported, for a target whose adapter declares none. */+function noHostServices(): readonly ServiceStatus[] {+ return GAME_SERVICES.map((service) => ({+ service,+ support: 'no' as const,+ note: service === 'achievements' ? ACHIEVEMENTS_LOCAL_ONLY : NO_HOST_ABOVE,+ }));+}++/**+ * WeChat's API list is not guessed: `minigame-api-typings` is Tencent's own+ * published declaration and a dependency of this checkout, so every member the+ * family adapter forwards to can be shown to exist.+ */+const WECHAT_SERVICES: readonly ServiceStatus[] = [+ {+ service: 'ads',+ support: 'yes',+ note: 'wx.createRewardedVideoAd / wx.createInterstitialAd — declared by minigame-api-typings,'+ + ' WeChat\'s own published API declaration.'+ + ' An ad unit id from the mini-game console is still needed before a unit fills.',+ },+ {+ service: 'share',+ support: 'yes',+ note: 'wx.shareAppMessage / wx.onShareAppMessage — declared by minigame-api-typings.'+ + ' No host reports whether a share went through, so neither does the engine.',+ },+ {+ service: 'signIn',+ support: 'yes',+ note: 'wx.login — declared by minigame-api-typings. It yields a code your own server exchanges;'+ + ' the engine hands the code over and never talks to WeChat\'s server itself.',+ },+ {+ service: 'purchase',+ support: 'unknown',+ note: 'wx.requestMidasPayment 「发起购买游戏币支付请求」(需要基础库 2.19.2) —'+ + ' https://developers.weixin.qq.com/minigame/dev/api/midas-payment/wx.requestMidasPayment.html'+ + ' Two things no build can see decide it: the account must have 虚拟支付 enabled, and WeChat'+ + ' permits the call on Android only — it is refused on an iPhone.',+ },+ { service: 'achievements', support: 'no', note: ACHIEVEMENTS_LOCAL_ONLY },+];++/**+ * Douyin runs through the same family adapter, so the engine calls+ * `tt.createRewardedVideoAd` and friends exactly as it calls `wx`'s. What is+ * missing is a SOURCE: no published declaration for `tt` exists in this+ * checkout the way one does for `wx`.+ */+const DOUYIN_SERVICES: readonly ServiceStatus[] = [+ {+ service: 'ads',+ support: 'unknown',+ note: 'The engine forwards to tt.createRewardedVideoAd / tt.createInterstitialAd. No published'+ + ' declaration for tt is available here, so whether this host has them is the host\'s answer.',+ },+ {+ service: 'share',+ support: 'unknown',+ note: 'The engine forwards to tt.shareAppMessage / tt.onShareAppMessage, unverified on a device.',+ },+ {+ service: 'signIn',+ support: 'unknown',+ note: 'The engine forwards to tt.login, unverified on a device.',+ },+ {+ service: 'purchase',+ support: 'no',+ note: 'The engine sells nothing on Douyin. Payment in the mini-game family is WeChat\'s'+ + ' requestMidasPayment with WeChat\'s rules; Douyin\'s call is its own, and there is no source'+ + ' here for its name or its fields — so the profile leaves the slot empty rather than charge a'+ + ' player through a call invented from a guess.',+ },+ { service: 'achievements', support: 'no', note: ACHIEVEMENTS_LOCAL_ONLY },+];++const DESKTOP_SERVICES: readonly ServiceStatus[] = noHostServices().map((s) => (+ s.service === 'achievements'+ ? {+ service: 'achievements' as const,+ support: 'unknown' as const,+ note: 'Steam backs them once the project sets a Steam app id AND the player has the client'+ + ' running — neither of which a build can see. Without both, the local provider is used.',+ }+ : s+));++/**+ * What a built-in target can provide, before any project profile has its say.+ *+ * A project-authored platform gets an empty list rather than a guess: its+ * profile decides which adapter is installed, and inventing capabilities for+ * someone else's vendor is exactly the confidence this file must not have.+ */+export function builtinServiceSupport(platform: ExportPlatform): readonly ServiceStatus[] {+ if (platform === 'wechat') return WECHAT_SERVICES;+ if (platform === 'douyin') return DOUYIN_SERVICES;+ if (platform === 'desktop') return DESKTOP_SERVICES;+ if (platform === 'web' || platform === 'playable' || platform === 'android' || platform === 'ios') {+ return noHostServices();+ }+ return [];+}diff --git a/pipeline/tests/service-support.test.ts b/pipeline/tests/service-support.test.tsnew file mode 100644index 000000000..711025969--- /dev/null+++ b/pipeline/tests/service-support.test.ts@@ -0,0 +1,80 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * What the build dialog says a target can do has to stay true to the adapter+ * that target will install and to the vendor declaration it cites. Both are in+ * this checkout, so a `yes` names members the vendor's own typings declare, and+ * Douyin's "sells nothing" is read off the profile's empty `pay` slot.+ */+import { describe, it, expect } from 'vitest';+import { readFileSync } from 'node:fs';+import { createRequire } from 'node:module';+import { BUILTIN_PLATFORMS } from '../src/project/platforms';+import { GAME_SERVICES, builtinServiceSupport, type GameService } from '../src/project/serviceSupport';+import { douyinProfile } from '../../sdk/src/platform/douyin/profile';++const supportOf = (platform: string, service: GameService): string | undefined =>+ builtinServiceSupport(platform).find((s) => s.service === service)?.support;++/** WeChat's own published API declaration, as depended on by the SDK. */+const wechatTypings = (): string => {+ const require_ = createRequire(import.meta.url);+ return readFileSync(require_.resolve('minigame-api-typings/types/wx/lib.wx.api.d.ts'), 'utf8');+};++describe('service support', () => {+ it('answers for every service on every built-in target', () => {+ for (const platform of BUILTIN_PLATFORMS) {+ const rows = builtinServiceSupport(platform);+ expect(rows.map((r) => r.service).sort()).toEqual([...GAME_SERVICES].sort());+ for (const row of rows) expect(row.note.length).toBeGreaterThan(20);+ }+ });++ it('leaves a project-authored platform to its own profile', () => {+ expect(builtinServiceSupport('acme-tv')).toEqual([]);+ });++ it('reports purchase on Douyin exactly as the profile decides it', () => {+ // The family's payment is WeChat's call with WeChat's rules, so a vendor+ // that has not filled `pay` sells nothing — fill it and this goes red,+ // which is the point: the dialog would still be saying "no".+ expect(douyinProfile.pay === undefined).toBe(supportOf('douyin', 'purchase') === 'no');+ expect(supportOf('douyin', 'purchase')).toBe('no');+ });++ it('claims yes only for members WeChat itself declares', () => {+ const typings = wechatTypings();+ let checked = 0;+ for (const platform of BUILTIN_PLATFORMS) {+ for (const row of builtinServiceSupport(platform)) {+ if (row.support !== 'yes') continue;+ const members = [...row.note.matchAll(/\bwx\.(\w+)/g)].map((m) => m[1]);+ expect(members.length, `${platform}/${row.service} claims yes and cites nobody`)+ .toBeGreaterThan(0);+ for (const member of members) {+ expect(typings.includes(`${member}(`), `wx.${member} is not in minigame-api-typings`)+ .toBe(true);+ checked++;+ }+ }+ }+ // The scan must have had something to scan: a matcher that found no rows+ // at all would pass every assertion above and check nothing.+ expect(checked).toBeGreaterThanOrEqual(4);+ });++ it('says no host above the game wherever the adapter declares no such method', async () => {+ const { webAdapter } = await import('../../sdk/src/platform/web');+ const declared = {+ ads: webAdapter.createRewardedAd !== undefined,+ share: webAdapter.share !== undefined,+ signIn: webAdapter.login !== undefined,+ purchase: webAdapter.requestPayment !== undefined,+ };+ for (const [service, present] of Object.entries(declared)) {+ expect(present, `the web adapter declares ${service}`).toBe(false);+ expect(supportOf('web', service as GameService)).toBe('no');+ }+ });+});