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(sdk): a runtime service can live outside the engine

yhhc0fc87207ac7
diff --git a/docs/astro/src/content/docs/extending/editor-plugins.mdx b/docs/astro/src/content/docs/extending/editor-plugins.mdx
index 44b02709a..8c3af0c70 100644
--- a/docs/astro/src/content/docs/extending/editor-plugins.mdx
+++ b/docs/astro/src/content/docs/extending/editor-plugins.mdx
@@ -160,9 +160,10 @@ the manifest points at, and runtime code the game imports itself.
</FileTree>
```ts title="src/main.ts"
+import { addPlugin } from 'esengine';
import { TiledPlugin } from 'estella-plugin-tiled';
-app.use(TiledPlugin);
+addPlugin(TiledPlugin);
```
The runtime half needs no mechanism of its own — it is an ordinary module, bundled
diff --git a/docs/astro/src/content/docs/publishing/ads-sharing.mdx b/docs/astro/src/content/docs/publishing/ads-sharing.mdx
index 172a9ee82..56b59ffdf 100644
--- a/docs/astro/src/content/docs/publishing/ads-sharing.mdx
+++ b/docs/astro/src/content/docs/publishing/ads-sharing.mdx
@@ -68,10 +68,25 @@ installed provider. Use it to hide the "watch ad" button honestly:
## Sharing
+Sharing and [in-game purchase](#in-game-purchase) ship as a package rather than
+inside the engine — most games open neither:
+
+```bash
+npm install estella-plugin-minigame-services
+```
+
+```typescript title="src/main.ts"
+import { addPlugin } from 'esengine';
+import { miniGameServicesPlugin } from 'estella-plugin-minigame-services';
+
+addPlugin(miniGameServicesPlugin);
+```
+
A mini-game host has **two** share surfaces, and a game should configure both:
```typescript
-import { defineSystem, addStartupSystem, Res, Share } from 'esengine';
+import { defineSystem, addStartupSystem, Res } from 'esengine';
+import { Share } from 'estella-plugin-minigame-services';
addStartupSystem(defineSystem([Res(Share)], (share) => {
// The DEFAULT card: what the host's own share menu (top-right on WeChat)
@@ -195,7 +210,8 @@ Android-only: the call is present on an iPhone and the platform refuses it. So
than finding out when someone taps Buy.
```typescript
-import { defineSystem, Res, Payment } from 'esengine';
+import { defineSystem, Res } from 'esengine';
+import { Payment } from 'estella-plugin-minigame-services';
if (!payment.available) return; // iOS, web, native — do not open the shop
diff --git a/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx b/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx
index ba94f3628..2fbee3352 100644
--- a/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx
+++ b/docs/astro/src/content/docs/zh-cn/extending/editor-plugins.mdx
@@ -143,9 +143,10 @@ npm install estella-plugin-tiled
</FileTree>
```ts title="src/main.ts"
+import { addPlugin } from 'esengine';
import { TiledPlugin } from 'estella-plugin-tiled';
-app.use(TiledPlugin);
+addPlugin(TiledPlugin);
```
运行时那半不需要任何专门机制——它就是一个普通模块,和 `src/` 里的其余代码一起被打包
diff --git a/docs/astro/src/content/docs/zh-cn/publishing/ads-sharing.mdx b/docs/astro/src/content/docs/zh-cn/publishing/ads-sharing.mdx
index d8ffc4627..08c17d6cd 100644
--- a/docs/astro/src/content/docs/zh-cn/publishing/ads-sharing.mdx
+++ b/docs/astro/src/content/docs/zh-cn/publishing/ads-sharing.mdx
@@ -61,10 +61,24 @@ const reviveSystem = defineSystem([Res(Ads), GetWorld()], (ads, world) => {
## 分享
+分享和[内购](#内购)以包的形式发布,不在引擎里——大多数游戏两个都不会打开:
+
+```bash
+npm install estella-plugin-minigame-services
+```
+
+```typescript title="src/main.ts"
+import { addPlugin } from 'esengine';
+import { miniGameServicesPlugin } from 'estella-plugin-minigame-services';
+
+addPlugin(miniGameServicesPlugin);
+```
+
小游戏宿主有**两个**分享面,游戏两个都该配置:
```typescript
-import { defineSystem, addStartupSystem, Res, Share } from 'esengine';
+import { defineSystem, addStartupSystem, Res } from 'esengine';
+import { Share } from 'estella-plugin-minigame-services';
addStartupSystem(defineSystem([Res(Share)], (share) => {
// 默认卡片:宿主自己的分享菜单(微信右上角)展示的内容,也是 share() 不带参数时
@@ -177,7 +191,8 @@ code**。
应该在打开之前就问,而不是等玩家点了「购买」才发现。
```typescript
-import { defineSystem, Res, Payment } from 'esengine';
+import { defineSystem, Res } from 'esengine';
+import { Payment } from 'estella-plugin-minigame-services';
if (!payment.available) return; // iOS、网页、原生——不要打开商店
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index 04958dfd1..954a0fa85 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 112,
"beta": 60,
- "experimental": 1498,
+ "experimental": 1499,
"deprecated": 3
},
- "total": 1670,
+ "total": 1671,
"subsystems": [
{
"id": "ecs",
diff --git a/plugins/minigame-services/README.md b/plugins/minigame-services/README.md
new file mode 100644
index 000000000..898ec546d
--- /dev/null
+++ b/plugins/minigame-services/README.md
@@ -0,0 +1,60 @@
+# estella-plugin-minigame-services
+
+The mini-game host's **share sheet** and **in-game purchase**, as Estella
+services. Both used to ship inside the engine; they live here because most games
+never open either, and because a service is exactly the shape a plugin should be.
+
+```bash
+npm install estella-plugin-minigame-services
+```
+
+```ts title="src/main.ts"
+import { addPlugin } from 'esengine';
+import { miniGameServicesPlugin, Share, Payment } from 'estella-plugin-minigame-services';
+
+addPlugin(miniGameServicesPlugin);
+```
+
+## Share
+
+```ts
+const share = app.getResource(Share);
+
+// Hide your share button where the host has no sheet (web and native).
+if (share.available) showShareButton();
+
+// The card is asked for at SHARE time, so it can carry live state.
+share.setShareCard(() => ({ title: `I scored ${score}` }));
+share.share();
+```
+
+Setting the card also answers the host's OWN share menu — the passive surface a
+player reaches without touching your button.
+
+## Payment
+
+```ts
+const pay = app.getResource(Payment);
+
+// Answers for the DEVICE, not for the API: on WeChat, buying is Android-only.
+// A shop reads this to stay closed rather than to open and fail.
+if (!pay.available) return;
+
+await pay.request({ quantity: 10 });
+// Resolved means "the host says it completed" — go ASK your server what the
+// player owns. A purchase the client believes in is one an attacker can claim.
+```
+
+Failures reject with the host's own message and `code`, untranslated: vendors
+number them differently, and a mapping invented here would be a guess your game
+then branches on.
+
+## Built on the public API
+
+Only `esengine`'s public surface: `defineResource`, the `Plugin` interface, and
+the host capability functions (`platformShare`, `platformCanShare`,
+`platformOnShareRequest`, `platformCanPay`, `platformRequestPayment`). Declare
+`esengine` a **peer** dependency if you write one of these — a copy vendored
+inside the package would be a second engine whose resources nothing can read.
+
+Apache-2.0.
diff --git a/plugins/minigame-services/package.json b/plugins/minigame-services/package.json
new file mode 100644
index 000000000..515ac3592
--- /dev/null
+++ b/plugins/minigame-services/package.json
@@ -0,0 +1,15 @@
+{
+ "name": "estella-plugin-minigame-services",
+ "version": "0.1.0",
+ "description": "The mini-game host's share sheet and in-game purchase, as Estella services.",
+ "license": "Apache-2.0",
+ "type": "module",
+ "main": "./src/index.ts",
+ "types": "./src/index.ts",
+ "exports": { ".": "./src/index.ts" },
+ "files": ["src", "README.md"],
+ "keywords": ["estella", "estella-plugin", "minigame", "wechat", "share", "payment"],
+ "scripts": { "test": "vitest run" },
+ "peerDependencies": { "esengine": ">=0.51" },
+ "devDependencies": { "esengine": "workspace:*", "vitest": "^2.1.9" }
+}
diff --git a/plugins/minigame-services/src/index.ts b/plugins/minigame-services/src/index.ts
new file mode 100644
index 000000000..0f2bc2a91
--- /dev/null
+++ b/plugins/minigame-services/src/index.ts
@@ -0,0 +1,25 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file index.ts — the share sheet and the purchase, as a plugin.
+ *
+ * Two resources and nothing per frame: both services are façades over host
+ * capabilities, so what they cost is what the host charges when you call them.
+ */
+import type { App, Plugin } from 'esengine';
+import { Share, ShareAPI } from './share';
+import { Payment, PaymentAPI } from './payment';
+
+export { Share, ShareAPI, type ShareCard } from './share';
+export { Payment, PaymentAPI, type PaymentRequest, type PaymentFailure } from './payment';
+
+export class MiniGameServicesPlugin implements Plugin {
+ name = 'MiniGameServices';
+
+ build(app: App): void {
+ app.insertResource(Share, new ShareAPI());
+ app.insertResource(Payment, new PaymentAPI());
+ }
+}
+
+export const miniGameServicesPlugin = new MiniGameServicesPlugin();
diff --git a/sdk/src/services/payment.ts b/plugins/minigame-services/src/payment.ts
similarity index 93%
rename from sdk/src/services/payment.ts
rename to plugins/minigame-services/src/payment.ts
index e0fbaf0d7..06b210164 100644
--- a/sdk/src/services/payment.ts
+++ b/plugins/minigame-services/src/payment.ts
@@ -28,9 +28,10 @@
* none: a rehearsed purchase that charges nothing and grants nothing rehearses
* only the dialog, and the part that goes wrong is the part behind it.
*/
-import { defineResource } from '../ecs/resource';
-import { platformCanPay, platformRequestPayment } from '../platform';
-import type { PlatformPaymentRequest } from '../platform/types';
+import {
+ defineResource, platformCanPay, platformRequestPayment,
+ type PlatformPaymentRequest,
+} from 'esengine';
export type PaymentRequest = PlatformPaymentRequest;
diff --git a/sdk/src/services/share.ts b/plugins/minigame-services/src/share.ts
similarity index 90%
rename from sdk/src/services/share.ts
rename to plugins/minigame-services/src/share.ts
index f26cb2e8c..dd525808e 100644
--- a/sdk/src/services/share.ts
+++ b/plugins/minigame-services/src/share.ts
@@ -10,9 +10,10 @@
* time, so it can answer with live state — a room code, the current score.
* Fire-and-forget by design: no host reports whether the player shared.
*/
-import { defineResource } from '../ecs/resource';
-import { platformShare, platformCanShare, platformOnShareRequest } from '../platform';
-import type { PlatformShareOptions } from '../platform/types';
+import {
+ defineResource, platformShare, platformCanShare, platformOnShareRequest,
+ type PlatformShareOptions,
+} from 'esengine';
export type ShareCard = PlatformShareOptions;
diff --git a/plugins/minigame-services/tests/services.test.ts b/plugins/minigame-services/tests/services.test.ts
new file mode 100644
index 000000000..48071a66e
--- /dev/null
+++ b/plugins/minigame-services/tests/services.test.ts
@@ -0,0 +1,113 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file What the two services promise on top of the host's capability.
+ *
+ * Both are façades, so the claims are about the small amount they add: telling
+ * a menu honestly whether the host can do this at all, and asking for the share
+ * card at SHARE time rather than at set time — which is what lets a card carry
+ * a live score.
+ */
+import { describe, it, expect, vi, beforeEach } from 'vitest';
+
+const host = {
+ canShare: true,
+ canPay: true,
+ shared: [] as unknown[],
+ passive: null as null | (() => unknown),
+ paid: [] as unknown[],
+ payRejects: null as null | Error,
+};
+
+vi.mock('esengine', () => ({
+ defineResource: (value: unknown, name: string) => ({ value, name }),
+ platformCanShare: () => host.canShare,
+ platformShare: (options: unknown) => {
+ host.shared.push(options);
+ return host.canShare;
+ },
+ platformOnShareRequest: (provide: () => unknown) => {
+ host.passive = provide;
+ return true;
+ },
+ platformCanPay: () => host.canPay,
+ platformRequestPayment: (request: unknown) => {
+ host.paid.push(request);
+ return host.payRejects ? Promise.reject(host.payRejects) : Promise.resolve();
+ },
+}));
+
+const { ShareAPI } = await import('../src/share');
+const { PaymentAPI } = await import('../src/payment');
+
+beforeEach(() => {
+ host.canShare = true;
+ host.canPay = true;
+ host.shared = [];
+ host.passive = null;
+ host.paid = [];
+ host.payRejects = null;
+});
+
+describe('the share sheet', () => {
+ it('says whether the host has one, so a button can hide instead of failing', () => {
+ expect(new ShareAPI().available).toBe(true);
+ host.canShare = false;
+ expect(new ShareAPI().available).toBe(false);
+ });
+
+ it('shares the default card when given none', () => {
+ const share = new ShareAPI();
+ share.setShareCard({ title: 'Beat my score' });
+ share.share();
+ expect(host.shared).toEqual([{ title: 'Beat my score' }]);
+ });
+
+ it('asks a function card at SHARE time, so it can carry live state', () => {
+ let score = 0;
+ const share = new ShareAPI();
+ share.setShareCard(() => ({ title: `Score ${score}` }));
+ score = 42;
+ share.share();
+ expect(host.shared).toEqual([{ title: 'Score 42' }]);
+ });
+
+ it('answers the host s own menu from the same card', () => {
+ // The passive surface: the host asks, the game did not call anything.
+ let score = 0;
+ const share = new ShareAPI();
+ share.setShareCard(() => ({ title: `Score ${score}` }));
+ score = 7;
+ expect(host.passive?.()).toEqual({ title: 'Score 7' });
+ });
+
+ it('registers with the host once, not on every card change', () => {
+ const share = new ShareAPI();
+ share.setShareCard({ title: 'a' });
+ const first = host.passive;
+ share.setShareCard({ title: 'b' });
+ expect(host.passive).toBe(first);
+ expect(host.passive?.()).toEqual({ title: 'b' });
+ });
+});
+
+describe('in-game purchase', () => {
+ it('answers for the DEVICE, so a shop stays closed rather than opening and failing', () => {
+ expect(new PaymentAPI().available).toBe(true);
+ host.canPay = false;
+ expect(new PaymentAPI().available).toBe(false);
+ });
+
+ it('passes the request to the host untouched', async () => {
+ await new PaymentAPI().request({ quantity: 3 } as never);
+ expect(host.paid).toEqual([{ quantity: 3 }]);
+ });
+
+ it('rejects with the HOST s code, which it does not translate', async () => {
+ // Vendors number their failures differently, and a mapping invented here is
+ // a guess the game would then branch on.
+ host.payRejects = Object.assign(new Error('user cancelled'), { code: 1001 });
+ await expect(new PaymentAPI().request({ quantity: 1 } as never))
+ .rejects.toMatchObject({ message: 'user cancelled', code: 1001 });
+ });
+});
diff --git a/plugins/minigame-services/tsconfig.json b/plugins/minigame-services/tsconfig.json
new file mode 100644
index 000000000..bc0aecc4d
--- /dev/null
+++ b/plugins/minigame-services/tsconfig.json
@@ -0,0 +1,11 @@
+{
+ "compilerOptions": {
+ "strict": true,
+ "target": "ES2020",
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "noEmit": true,
+ "skipLibCheck": true
+ },
+ "include": ["src", "tests"]
+}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index dd3a90720..462d6c0ac 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -119,6 +119,15 @@ importers:
specifier: ^2.1.9
+ plugins/minigame-services:
+ devDependencies:
+ esengine:
+ specifier: workspace:*
+ version: link:../../sdk
+ vitest:
+ specifier: ^2.1.9
+
sdk:
devDependencies:
'@rollup/plugin-terser':
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index c3a22295f..d38660595 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 112 public · 53 beta · 1383 experimental · 3 deprecated
+Symbols: 112 public · 53 beta · 1384 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -567,9 +567,11 @@ static prototype: App
## AppContext — class @experimental
```
componentRegistry: Map<string, any>
+drainPendingPlugins: () => unknown[]
drainPendingSystems: () => PendingSystemEntry[]
editorBridge: EditorBridge | null
editorMode: boolean
+pendingPlugins: unknown[]
pendingSystems: PendingSystemEntry[]
playMode: boolean
reset: () => void
@@ -4710,32 +4712,6 @@ diagonal: boolean | undefined
snapRadius: number | undefined
```
-## Payment — const @experimental
-```
-ResourceDef<PaymentAPI>
-```
-
-## PaymentAPI — class @experimental
-```
-available: boolean
-request: (request: PaymentRequest) => Promise<void>
-static new (): PaymentAPI
-static prototype: PaymentAPI
-```
-
-## PaymentFailure — interface @experimental
-```
-code: number | undefined
-```
-
-## PaymentRequest — type @experimental
-```
-offerId: string
-quantity: number
-sandbox: boolean | undefined
-zoneId: string | undefined
-```
-
## Perceiver — const @experimental
```
ComponentDef<PerceiverData>
@@ -5065,6 +5041,14 @@ src: string
width: number
```
+## PlatformPaymentRequest — interface @experimental
+```
+offerId: string
+quantity: number
+sandbox: boolean | undefined
+zoneId: string | undefined
+```
+
## PlatformRequestOptions — interface @experimental
```
body: string | ArrayBuffer | undefined
@@ -5085,6 +5069,13 @@ statusText: string
text: () => Promise<string>
```
+## PlatformShareOptions — interface @experimental
+```
+imageUrl: string | undefined
+query: string | undefined
+title: string | undefined
+```
+
## PlatformSocket — interface @experimental
```
close: (code?: number, reason?: string) => void
@@ -6557,27 +6548,6 @@ Circle = 0
RoundedRect = 2
```
-## Share — const @experimental
-```
-ResourceDef<ShareAPI>
-```
-
-## ShareAPI — class @experimental
-```
-available: boolean
-setShareCard: (card: ShareCard | (() => ShareCard)) => void
-share: (card?: ShareCard) => boolean
-static new (): ShareAPI
-static prototype: ShareAPI
-```
-
-## ShareCard — type @experimental
-```
-imageUrl: string | undefined
-query: string | undefined
-title: string | undefined
-```
-
## SideModuleDescriptor — interface @experimental
```
file: string
@@ -8770,6 +8740,11 @@ TransformData
(g: MaterialGraph, type: GraphNodeType, x: number, y: number): { graph: MaterialGraph; id: string; }
```
+## addPlugin — function @experimental
+```
+(plugin: Plugin): void
+```
+
## addStartupSystem — function @public
```
(system: SystemDef): void
@@ -9640,7 +9615,7 @@ EventBindingPlugin
(s: TileStamp): TileStamp
```
-## flushPendingSystems — function @experimental
+## flushPendingRegistrations — function @experimental
```
(app: App): void
```
@@ -10435,6 +10410,16 @@ ParticlePlugin
PerceptionPlugin
```
+## platformCanPay — function @experimental
+```
+(): boolean
+```
+
+## platformCanShare — function @experimental
+```
+(): boolean
+```
+
## platformFetch — function @experimental
```
(url: string, options?: PlatformRequestOptions): Promise<PlatformResponse>
@@ -10450,6 +10435,11 @@ PerceptionPlugin
(pathOrBuffer: string | ArrayBuffer, imports: WebAssembly.Imports): Promise<WasmInstantiateResult>
```
+## platformOnShareRequest — function @experimental
+```
+(provide: () => PlatformShareOptions): boolean
+```
+
## platformReadFile — function @experimental
```
(path: string): Promise<ArrayBuffer>
@@ -10460,6 +10450,16 @@ PerceptionPlugin
(path: string): Promise<string>
```
+## platformRequestPayment — function @experimental
+```
+(request: PlatformPaymentRequest): Promise<void>
+```
+
+## platformShare — function @experimental
+```
+(options: PlatformShareOptions): boolean
+```
+
## playModeOnly — function @experimental
```
(): boolean
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 2751e1cbc..21f9f3b4a 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 112 public · 58 beta · 1402 experimental · 3 deprecated
+Symbols: 112 public · 58 beta · 1403 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -567,9 +567,11 @@ static prototype: App
## AppContext — class @experimental
```
componentRegistry: Map<string, any>
+drainPendingPlugins: () => unknown[]
drainPendingSystems: () => PendingSystemEntry[]
editorBridge: EditorBridge | null
editorMode: boolean
+pendingPlugins: unknown[]
pendingSystems: PendingSystemEntry[]
playMode: boolean
reset: () => void
@@ -4893,32 +4895,6 @@ diagonal: boolean | undefined
snapRadius: number | undefined
```
-## Payment — const @experimental
-```
-ResourceDef<PaymentAPI>
-```
-
-## PaymentAPI — class @experimental
-```
-available: boolean
-request: (request: PaymentRequest) => Promise<void>
-static new (): PaymentAPI
-static prototype: PaymentAPI
-```
-
-## PaymentFailure — interface @experimental
-```
-code: number | undefined
-```
-
-## PaymentRequest — type @experimental
-```
-offerId: string
-quantity: number
-sandbox: boolean | undefined
-zoneId: string | undefined
-```
-
## Perceiver — const @experimental
```
ComponentDef<PerceiverData>
@@ -5248,6 +5224,14 @@ src: string
width: number
```
+## PlatformPaymentRequest — interface @experimental
+```
+offerId: string
+quantity: number
+sandbox: boolean | undefined
+zoneId: string | undefined
+```
+
## PlatformRequestOptions — interface @experimental
```
body: string | ArrayBuffer | undefined
@@ -5268,6 +5252,13 @@ statusText: string
text: () => Promise<string>
```
+## PlatformShareOptions — interface @experimental
+```
+imageUrl: string | undefined
+query: string | undefined
+title: string | undefined
+```
+
## PlatformSocket — interface @experimental
```
close: (code?: number, reason?: string) => void
@@ -6750,27 +6741,6 @@ Circle = 0
RoundedRect = 2
```
-## Share — const @experimental
-```
-ResourceDef<ShareAPI>
-```
-
-## ShareAPI — class @experimental
-```
-available: boolean
-setShareCard: (card: ShareCard | (() => ShareCard)) => void
-share: (card?: ShareCard) => boolean
-static new (): ShareAPI
-static prototype: ShareAPI
-```
-
-## ShareCard — type @experimental
-```
-imageUrl: string | undefined
-query: string | undefined
-title: string | undefined
-```
-
## SideModuleDescriptor — interface @experimental
```
file: string
@@ -8963,6 +8933,11 @@ TransformData
(g: MaterialGraph, type: GraphNodeType, x: number, y: number): { graph: MaterialGraph; id: string; }
```
+## addPlugin — function @experimental
+```
+(plugin: Plugin): void
+```
+
## addStartupSystem — function @public
```
(system: SystemDef): void
@@ -9873,7 +9848,7 @@ EventBindingPlugin
(s: TileStamp): TileStamp
```
-## flushPendingSystems — function @experimental
+## flushPendingRegistrations — function @experimental
```
(app: App): void
```
@@ -10678,6 +10653,16 @@ ParticlePlugin
PerceptionPlugin
```
+## platformCanPay — function @experimental
+```
+(): boolean
+```
+
+## platformCanShare — function @experimental
+```
+(): boolean
+```
+
## platformFetch — function @experimental
```
(url: string, options?: PlatformRequestOptions): Promise<PlatformResponse>
@@ -10693,6 +10678,11 @@ PerceptionPlugin
(pathOrBuffer: string | ArrayBuffer, imports: WebAssembly.Imports): Promise<WasmInstantiateResult>
```
+## platformOnShareRequest — function @experimental
+```
+(provide: () => PlatformShareOptions): boolean
+```
+
## platformReadFile — function @experimental
```
(path: string): Promise<ArrayBuffer>
@@ -10703,6 +10693,16 @@ PerceptionPlugin
(path: string): Promise<string>
```
+## platformRequestPayment — function @experimental
+```
+(request: PlatformPaymentRequest): Promise<void>
+```
+
+## platformShare — function @experimental
+```
+(options: PlatformShareOptions): boolean
+```
+
## playModeOnly — function @experimental
```
(): boolean
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 5c4d9facb..29570031e 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 112 public · 55 beta · 1382 experimental · 3 deprecated
+Symbols: 112 public · 55 beta · 1383 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -562,9 +562,11 @@ static prototype: App
## AppContext — class @experimental
```
componentRegistry: Map<string, any>
+drainPendingPlugins: () => unknown[]
drainPendingSystems: () => PendingSystemEntry[]
editorBridge: EditorBridge | null
editorMode: boolean
+pendingPlugins: unknown[]
pendingSystems: PendingSystemEntry[]
playMode: boolean
reset: () => void
@@ -4705,32 +4707,6 @@ diagonal: boolean | undefined
snapRadius: number | undefined
```
-## Payment — const @experimental
-```
-ResourceDef<PaymentAPI>
-```
-
-## PaymentAPI — class @experimental
-```
-available: boolean
-request: (request: PaymentRequest) => Promise<void>
-static new (): PaymentAPI
-static prototype: PaymentAPI
-```
-
-## PaymentFailure — interface @experimental
-```
-code: number | undefined
-```
-
-## PaymentRequest — type @experimental
-```
-offerId: string
-quantity: number
-sandbox: boolean | undefined
-zoneId: string | undefined
-```
-
## Perceiver — const @experimental
```
ComponentDef<PerceiverData>
@@ -5060,6 +5036,14 @@ src: string
width: number
```
+## PlatformPaymentRequest — interface @experimental
+```
+offerId: string
+quantity: number
+sandbox: boolean | undefined
+zoneId: string | undefined
+```
+
## PlatformRequestOptions — interface @experimental
```
body: string | ArrayBuffer | undefined
@@ -5080,6 +5064,13 @@ statusText: string
text: () => Promise<string>
```
+## PlatformShareOptions — interface @experimental
+```
+imageUrl: string | undefined
+query: string | undefined
+title: string | undefined
+```
+
## PlatformSocket — interface @experimental
```
close: (code?: number, reason?: string) => void
@@ -6552,27 +6543,6 @@ Circle = 0
RoundedRect = 2
```
-## Share — const @experimental
-```
-ResourceDef<ShareAPI>
-```
-
-## ShareAPI — class @experimental
-```
-available: boolean
-setShareCard: (card: ShareCard | (() => ShareCard)) => void
-share: (card?: ShareCard) => boolean
-static new (): ShareAPI
-static prototype: ShareAPI
-```
-
-## ShareCard — type @experimental
-```
-imageUrl: string | undefined
-query: string | undefined
-title: string | undefined
-```
-
## SideModuleDescriptor — interface @experimental
```
file: string
@@ -8765,6 +8735,11 @@ TransformData
(g: MaterialGraph, type: GraphNodeType, x: number, y: number): { graph: MaterialGraph; id: string; }
```
+## addPlugin — function @experimental
+```
+(plugin: Plugin): void
+```
+
## addStartupSystem — function @public
```
(system: SystemDef): void
@@ -9635,7 +9610,7 @@ EventBindingPlugin
(s: TileStamp): TileStamp
```
-## flushPendingSystems — function @experimental
+## flushPendingRegistrations — function @experimental
```
(app: App): void
```
@@ -10440,6 +10415,16 @@ ParticlePlugin
PerceptionPlugin
```
+## platformCanPay — function @experimental
+```
+(): boolean
+```
+
+## platformCanShare — function @experimental
+```
+(): boolean
+```
+
## platformFetch — function @experimental
```
(url: string, options?: PlatformRequestOptions): Promise<PlatformResponse>
@@ -10455,6 +10440,11 @@ PerceptionPlugin
(pathOrBuffer: string | ArrayBuffer, imports: WebAssembly.Imports): Promise<WasmInstantiateResult>
```
+## platformOnShareRequest — function @experimental
+```
+(provide: () => PlatformShareOptions): boolean
+```
+
## platformReadFile — function @experimental
```
(path: string): Promise<ArrayBuffer>
@@ -10465,6 +10455,16 @@ PerceptionPlugin
(path: string): Promise<string>
```
+## platformRequestPayment — function @experimental
+```
+(request: PlatformPaymentRequest): Promise<void>
+```
+
+## platformShare — function @experimental
+```
+(options: PlatformShareOptions): boolean
+```
+
## playModeOnly — function @experimental
```
(): boolean
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index f0c482001..b82528009 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 112 public · 53 beta · 1403 experimental · 3 deprecated
+Symbols: 112 public · 53 beta · 1404 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -562,9 +562,11 @@ static prototype: App
## AppContext — class @experimental
```
componentRegistry: Map<string, any>
+drainPendingPlugins: () => unknown[]
drainPendingSystems: () => PendingSystemEntry[]
editorBridge: EditorBridge | null
editorMode: boolean
+pendingPlugins: unknown[]
pendingSystems: PendingSystemEntry[]
playMode: boolean
reset: () => void
@@ -4950,32 +4952,6 @@ diagonal: boolean | undefined
snapRadius: number | undefined
```
-## Payment — const @experimental
-```
-ResourceDef<PaymentAPI>
-```
-
-## PaymentAPI — class @experimental
-```
-available: boolean
-request: (request: PaymentRequest) => Promise<void>
-static new (): PaymentAPI
-static prototype: PaymentAPI
-```
-
-## PaymentFailure — interface @experimental
-```
-code: number | undefined
-```
-
-## PaymentRequest — type @experimental
-```
-offerId: string
-quantity: number
-sandbox: boolean | undefined
-zoneId: string | undefined
-```
-
## Perceiver — const @experimental
```
ComponentDef<PerceiverData>
@@ -5305,6 +5281,14 @@ src: string
width: number
```
+## PlatformPaymentRequest — interface @experimental
+```
+offerId: string
+quantity: number
+sandbox: boolean | undefined
+zoneId: string | undefined
+```
+
## PlatformRequestOptions — interface @experimental
```
body: string | ArrayBuffer | undefined
@@ -5325,6 +5309,13 @@ statusText: string
text: () => Promise<string>
```
+## PlatformShareOptions — interface @experimental
+```
+imageUrl: string | undefined
+query: string | undefined
+title: string | undefined
+```
+
## PlatformSocket — interface @experimental
```
close: (code?: number, reason?: string) => void
@@ -6797,27 +6788,6 @@ Circle = 0
RoundedRect = 2
```
-## Share — const @experimental
-```
-ResourceDef<ShareAPI>
-```
-
-## ShareAPI — class @experimental
-```
-available: boolean
-setShareCard: (card: ShareCard | (() => ShareCard)) => void
-share: (card?: ShareCard) => boolean
-static new (): ShareAPI
-static prototype: ShareAPI
-```
-
-## ShareCard — type @experimental
-```
-imageUrl: string | undefined
-query: string | undefined
-title: string | undefined
-```
-
## SideModuleDescriptor — interface @experimental
```
file: string
@@ -9010,6 +8980,11 @@ TransformData
(g: MaterialGraph, type: GraphNodeType, x: number, y: number): { graph: MaterialGraph; id: string; }
```
+## addPlugin — function @experimental
+```
+(plugin: Plugin): void
+```
+
## addStartupSystem — function @public
```
(system: SystemDef): void
@@ -9885,7 +9860,7 @@ EventBindingPlugin
(s: TileStamp): TileStamp
```
-## flushPendingSystems — function @experimental
+## flushPendingRegistrations — function @experimental
```
(app: App): void
```
@@ -10690,6 +10665,16 @@ ParticlePlugin
PerceptionPlugin
```
+## platformCanPay — function @experimental
+```
+(): boolean
+```
+
+## platformCanShare — function @experimental
+```
+(): boolean
+```
+
## platformFetch — function @experimental
```
(url: string, options?: PlatformRequestOptions): Promise<PlatformResponse>
@@ -10705,6 +10690,11 @@ PerceptionPlugin
(pathOrBuffer: string | ArrayBuffer, imports: WebAssembly.Imports): Promise<WasmInstantiateResult>
```
+## platformOnShareRequest — function @experimental
+```
+(provide: () => PlatformShareOptions): boolean
+```
+
## platformReadFile — function @experimental
```
(path: string): Promise<ArrayBuffer>
@@ -10715,6 +10705,16 @@ PerceptionPlugin
(path: string): Promise<string>
```
+## platformRequestPayment — function @experimental
+```
+(request: PlatformPaymentRequest): Promise<void>
+```
+
+## platformShare — function @experimental
+```
+(options: PlatformShareOptions): boolean
+```
+
## playModeOnly — function @experimental
```
(): boolean
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index 3901dfd8b..bdea36002 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 112 public · 53 beta · 1393 experimental · 3 deprecated
+Symbols: 112 public · 53 beta · 1394 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -562,9 +562,11 @@ static prototype: App
## AppContext — class @experimental
```
componentRegistry: Map<string, any>
+drainPendingPlugins: () => unknown[]
drainPendingSystems: () => PendingSystemEntry[]
editorBridge: EditorBridge | null
editorMode: boolean
+pendingPlugins: unknown[]
pendingSystems: PendingSystemEntry[]
playMode: boolean
reset: () => void
@@ -4712,32 +4714,6 @@ diagonal: boolean | undefined
snapRadius: number | undefined
```
-## Payment — const @experimental
-```
-ResourceDef<PaymentAPI>
-```
-
-## PaymentAPI — class @experimental
-```
-available: boolean
-request: (request: PaymentRequest) => Promise<void>
-static new (): PaymentAPI
-static prototype: PaymentAPI
-```
-
-## PaymentFailure — interface @experimental
-```
-code: number | undefined
-```
-
-## PaymentRequest — type @experimental
-```
-offerId: string
-quantity: number
-sandbox: boolean | undefined
-zoneId: string | undefined
-```
-
## Perceiver — const @experimental
```
ComponentDef<PerceiverData>
@@ -5067,6 +5043,14 @@ src: string
width: number
```
+## PlatformPaymentRequest — interface @experimental
+```
+offerId: string
+quantity: number
+sandbox: boolean | undefined
+zoneId: string | undefined
+```
+
## PlatformRequestOptions — interface @experimental
```
body: string | ArrayBuffer | undefined
@@ -5087,6 +5071,13 @@ statusText: string
text: () => Promise<string>
```
+## PlatformShareOptions — interface @experimental
+```
+imageUrl: string | undefined
+query: string | undefined
+title: string | undefined
+```
+
## PlatformSocket — interface @experimental
```
close: (code?: number, reason?: string) => void
@@ -6559,27 +6550,6 @@ Circle = 0
RoundedRect = 2
```
-## Share — const @experimental
-```
-ResourceDef<ShareAPI>
-```
-
-## ShareAPI — class @experimental
-```
-available: boolean
-setShareCard: (card: ShareCard | (() => ShareCard)) => void
-share: (card?: ShareCard) => boolean
-static new (): ShareAPI
-static prototype: ShareAPI
-```
-
-## ShareCard — type @experimental
-```
-imageUrl: string | undefined
-query: string | undefined
-title: string | undefined
-```
-
## SideModuleDescriptor — interface @experimental
```
file: string
@@ -8792,6 +8762,11 @@ TransformData
(g: MaterialGraph, type: GraphNodeType, x: number, y: number): { graph: MaterialGraph; id: string; }
```
+## addPlugin — function @experimental
+```
+(plugin: Plugin): void
+```
+
## addStartupSystem — function @public
```
(system: SystemDef): void
@@ -9662,7 +9637,7 @@ EventBindingPlugin
(s: TileStamp): TileStamp
```
-## flushPendingSystems — function @experimental
+## flushPendingRegistrations — function @experimental
```
(app: App): void
```
@@ -10462,6 +10437,16 @@ ParticlePlugin
PerceptionPlugin
```
+## platformCanPay — function @experimental
+```
+(): boolean
+```
+
+## platformCanShare — function @experimental
+```
+(): boolean
+```
+
## platformFetch — function @experimental
```
(url: string, options?: PlatformRequestOptions): Promise<PlatformResponse>
@@ -10477,6 +10462,11 @@ PerceptionPlugin
(pathOrBuffer: string | ArrayBuffer, imports: WebAssembly.Imports): Promise<WasmInstantiateResult>
```
+## platformOnShareRequest — function @experimental
+```
+(provide: () => PlatformShareOptions): boolean
+```
+
## platformReadFile — function @experimental
```
(path: string): Promise<ArrayBuffer>
@@ -10487,6 +10477,16 @@ PerceptionPlugin
(path: string): Promise<string>
```
+## platformRequestPayment — function @experimental
+```
+(request: PlatformPaymentRequest): Promise<void>
+```
+
+## platformShare — function @experimental
+```
+(options: PlatformShareOptions): boolean
+```
+
## playModeOnly — function @experimental
```
(): boolean
diff --git a/sdk/src/app/app.ts b/sdk/src/app/app.ts
index 73d3985dd..daa98f575 100644
--- a/sdk/src/app/app.ts
+++ b/sdk/src/app/app.ts
@@ -1410,7 +1410,26 @@ export function createWebApp(module: ESEngineModule, options?: WebAppOptions): A
return app;
}
-export function flushPendingSystems(app: App): void {
- const drained = getDefaultContext().drainPendingSystems();
- app.addBundleSystems(drained as ReadonlyArray<{ schedule: number; system: SystemDef }>);
+/**
+ * Install a {@link Plugin} from a project bundle — the module-level twin of
+ * {@link App.addPlugin}, and the door a plugin PACKAGE is installed through: a
+ * bundle is imported before an App exists.
+ *
+ * @experimental
+ */
+export function addPlugin(plugin: Plugin): void {
+ getDefaultContext().pendingPlugins.push(plugin);
+}
+
+/**
+ * Install everything a project bundle registered at module level. One door, so a
+ * host cannot drain half of it — plugins first, because a project's own system
+ * may read a resource one of them inserts.
+ *
+ * @experimental
+ */
+export function flushPendingRegistrations(app: App): void {
+ const context = getDefaultContext();
+ for (const plugin of context.drainPendingPlugins()) app.addPlugin(plugin as Plugin);
+ app.addBundleSystems(context.drainPendingSystems() as ReadonlyArray<{ schedule: number; system: SystemDef }>);
}
diff --git a/sdk/src/core-content.ts b/sdk/src/core-content.ts
index e648554ce..54f133ba3 100644
--- a/sdk/src/core-content.ts
+++ b/sdk/src/core-content.ts
@@ -427,15 +427,13 @@ export {
export {
Achievements, AchievementsAPI, createLocalAchievements,
Ads, AdsAPI, createMockAdProvider, createTakeover,
- Share, ShareAPI,
Leaderboard, LeaderboardAPI, createLocalLeaderboard,
- Identity, IdentityAPI, Payment, PaymentAPI,
+ Identity, IdentityAPI,
ServicesPlugin, servicesPlugin,
type AchievementProvider,
- type AdProvider, type MockAdProviderOptions, type ShareCard, type Takeover, type TakeoverHost,
+ type AdProvider, type MockAdProviderOptions, type Takeover, type TakeoverHost,
type LeaderboardOptions, type LeaderboardProvider, type LeaderboardScope,
type LeaderboardStyle, type LocalLeaderboardOptions, type LoginResult,
- type PaymentRequest, type PaymentFailure,
} from './services';
// =============================================================================
diff --git a/sdk/src/core-runtime.ts b/sdk/src/core-runtime.ts
index 7effe9d42..9ca707631 100644
--- a/sdk/src/core-runtime.ts
+++ b/sdk/src/core-runtime.ts
@@ -394,7 +394,8 @@ export { writePtrField, readPtrField } from './ecs/bridge/BuiltinBridge';
export {
App,
- flushPendingSystems,
+ addPlugin,
+ flushPendingRegistrations,
type FrameCosts,
type Plugin,
type PluginDependency,
diff --git a/sdk/src/core-sys.ts b/sdk/src/core-sys.ts
index 5b0b8d378..025b71405 100644
--- a/sdk/src/core-sys.ts
+++ b/sdk/src/core-sys.ts
@@ -107,6 +107,18 @@ export {
// Platform (base functions only)
// =============================================================================
+// Host CAPABILITIES, as opposed to the base functions below: the seams a service
+// is built on. Public because a service can live outside the engine, and there is
+// no second way to reach a host. Exported as a shipped plugin holds each one up.
+export {
+ platformShare,
+ platformCanShare,
+ platformOnShareRequest,
+ platformCanPay,
+ platformRequestPayment,
+} from './platform';
+export type { PlatformShareOptions, PlatformPaymentRequest } from './platform/types';
+
export {
getPlatform,
getPlatformType,
diff --git a/sdk/src/ecs/context.ts b/sdk/src/ecs/context.ts
index dd61dbbaa..960123bca 100644
--- a/sdk/src/ecs/context.ts
+++ b/sdk/src/ecs/context.ts
@@ -55,6 +55,9 @@ export interface WasmErrorState {
export class AppContext {
readonly componentRegistry = new Map<string, any>();
readonly pendingSystems: PendingSystemEntry[] = [];
+ /** Plugins a project bundle installed at module level, drained with the
+ * systems: a bundle is imported before an App exists. */
+ readonly pendingPlugins: unknown[] = [];
editorBridge: EditorBridge | null = null;
readonly wasmError: WasmErrorState = { handler: null, lastReportTime: 0, suppressedCount: 0 };
@@ -75,9 +78,15 @@ export class AppContext {
return drained;
}
+ /** @brief Drain all pending plugins and clear the queue */
+ drainPendingPlugins(): unknown[] {
+ return this.pendingPlugins.splice(0);
+ }
+
/** @brief Reset all mutable state for a new session */
reset(): void {
this.pendingSystems.length = 0;
+ this.pendingPlugins.length = 0;
this.componentRegistry.clear();
this.editorBridge = null;
this.wasmError.handler = null;
diff --git a/sdk/src/runtime/runtimeLoader.ts b/sdk/src/runtime/runtimeLoader.ts
index 25c9b6cd9..8f4d19d82 100644
--- a/sdk/src/runtime/runtimeLoader.ts
+++ b/sdk/src/runtime/runtimeLoader.ts
@@ -34,7 +34,7 @@ import { VideoPlayer } from '../video/VideoAPI';
import { Localization, matchLocale } from '../i18n/Localization';
import { LocalizationPlugin } from '../i18n/LocalizationPlugin';
import { platformLanguage } from '../platform';
-import { flushPendingSystems } from '../app/app';
+import { flushPendingRegistrations } from '../app/app';
import { installHotUpdateRebind } from '../hotUpdateRebind';
import { requireResourceManager } from '../wasm/resourceManager';
import { log } from '../util/logger';
@@ -534,7 +534,7 @@ export interface RuntimeInitConfig {
export async function initRuntime(config: RuntimeInitConfig): Promise<void> {
const { app, firstScene, aspectRatio } = config;
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
// Install the per-App runtime Assets up front (scene loads reuse it) and
// hand it the manifest so on-demand loadGroup works from the first frame.
diff --git a/sdk/src/services/index.ts b/sdk/src/services/index.ts
index 96a5407f4..a9fbca9ac 100644
--- a/sdk/src/services/index.ts
+++ b/sdk/src/services/index.ts
@@ -5,7 +5,6 @@ export {
type AdProvider, type MockAdProviderOptions,
} from './ads';
export { createTakeover, type Takeover, type TakeoverHost } from './takeover';
-export { Share, ShareAPI, type ShareCard } from './share';
export {
Leaderboard, LeaderboardAPI, createLocalLeaderboard,
type LeaderboardOptions, type LeaderboardProvider, type LeaderboardScope,
@@ -15,5 +14,4 @@ export {
Achievements, AchievementsAPI, createLocalAchievements, type AchievementProvider,
} from './achievements';
export { Identity, IdentityAPI, type LoginResult } from './identity';
-export { Payment, PaymentAPI, type PaymentRequest, type PaymentFailure } from './payment';
export { ServicesPlugin, servicesPlugin } from './servicesPlugin';
diff --git a/sdk/src/services/servicesPlugin.ts b/sdk/src/services/servicesPlugin.ts
index 3667e3572..e92cf95b6 100644
--- a/sdk/src/services/servicesPlugin.ts
+++ b/sdk/src/services/servicesPlugin.ts
@@ -19,11 +19,9 @@ import type { App, Plugin } from '../app/app';
import { Audio } from '../audio';
import { Schedule, defineSystem } from '../ecs/system';
import { Ads, AdsAPI } from './ads';
-import { Share, ShareAPI } from './share';
import { Leaderboard, LeaderboardAPI } from './leaderboard';
import { Achievements, AchievementsAPI } from './achievements';
import { Identity, IdentityAPI } from './identity';
-import { Payment, PaymentAPI } from './payment';
import { createTakeover } from './takeover';
import { getPlatform } from '../platform';
@@ -51,10 +49,8 @@ export class ServicesPlugin implements Plugin {
getPlatform().onStoreOverlay?.((covered) => {
if (covered) takeover.begin(); else takeover.end();
});
- app.insertResource(Share, new ShareAPI());
app.insertResource(Achievements, new AchievementsAPI());
app.insertResource(Identity, new IdentityAPI());
- app.insertResource(Payment, new PaymentAPI());
// Resolved per call rather than captured: the module is attached by
// connectCpp, which can run after the plugins have built.
app.insertResource(Leaderboard, new LeaderboardAPI(() => app.wasmModule));
diff --git a/sdk/tests/app-lifecycle-vocabulary.test.ts b/sdk/tests/app-lifecycle-vocabulary.test.ts
index 760c3e959..ccf7e718b 100644
--- a/sdk/tests/app-lifecycle-vocabulary.test.ts
+++ b/sdk/tests/app-lifecycle-vocabulary.test.ts
@@ -10,7 +10,7 @@
* numbers looking sensible.
*/
import { describe, it, expect, beforeEach } from 'vitest';
-import { App, flushPendingSystems } from '../src/app/app';
+import { App, addPlugin, flushPendingRegistrations } from '../src/app/app';
import {
Schedule, defineSystem, defineSystemSet, addStartupSystem,
addSystemToSchedule, addSystemSetToSchedule,
@@ -71,7 +71,7 @@ describe('module-level registration', () => {
addSystemToSchedule(Schedule.PostUpdate, trace('bundle-post', order));
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
await app.tick(1 / 60);
expect(order).toEqual(['bundle-startup', 'bundle-post']);
@@ -89,7 +89,7 @@ describe('module-level registration', () => {
addSystemSetToSchedule(Schedule.Update, set);
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
await app.tick(1 / 60);
expect(order).toEqual([]);
@@ -103,14 +103,47 @@ describe('module-level registration', () => {
addSystemToSchedule(Schedule.Update, trace('once', order));
const first = App.new();
- flushPendingSystems(first);
+ flushPendingRegistrations(first);
const second = App.new();
- flushPendingSystems(second);
+ flushPendingRegistrations(second);
await first.tick(1 / 60);
await second.tick(1 / 60);
expect(order).toEqual(['once']);
});
+
+ it('carries a project bundle PLUGIN too, before its own systems run', async () => {
+ // A plugin package is installed from the bundle, which is imported before
+ // an App exists — the same reason systems have a module-level door. And a
+ // project system may read what the plugin inserted, so plugins go first.
+ const order: string[] = [];
+ addPlugin({
+ name: 'FromBundle',
+ build: (app) => {
+ order.push('plugin-built');
+ app.addStartupSystem(trace('plugin-startup', order));
+ },
+ });
+ addStartupSystem(trace('bundle-startup', order));
+
+ const app = App.new();
+ flushPendingRegistrations(app);
+ await app.tick(1 / 60);
+
+ expect(order[0]).toBe('plugin-built');
+ expect(order).toContain('plugin-startup');
+ expect(order).toContain('bundle-startup');
+ });
+
+ it('drains the plugins, so a second app does not build them again', async () => {
+ const built: string[] = [];
+ addPlugin({ name: 'Once', build: () => built.push('built') });
+
+ flushPendingRegistrations(App.new());
+ flushPendingRegistrations(App.new());
+
+ expect(built).toEqual(['built']);
+ });
});
/** Sets `Time.scale` once, on the frame whose number it is given. */
diff --git a/sdk/tests/behavior.test.ts b/sdk/tests/behavior.test.ts
index 874a8db59..72d2b37d4 100644
--- a/sdk/tests/behavior.test.ts
+++ b/sdk/tests/behavior.test.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, it, expect, beforeEach } from 'vitest';
-import { App, flushPendingSystems } from '../src/app/app';
+import { App, flushPendingRegistrations } from '../src/app/app';
import { defineBehavior } from '../src/behavior';
import { AppContext, setDefaultContext } from '../src/ecs/context';
import { getUserComponents } from '../src/ecs/component';
@@ -30,7 +30,7 @@ describe('defineBehavior', () => {
});
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
const e = app.world.spawn('e1');
app.world.insert(e, Bhv, { n: 0 });
@@ -48,7 +48,7 @@ describe('defineBehavior', () => {
let starts = 0;
const Bhv = defineBehavior('Once', { start() { starts++; } });
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
const e = app.world.spawn();
app.world.insert(e, Bhv, {});
@@ -63,7 +63,7 @@ describe('defineBehavior', () => {
let destroyed = 0;
const Bhv = defineBehavior('OnRemove', { destroy() { destroyed++; } });
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
const e = app.world.spawn();
app.world.insert(e, Bhv, {});
@@ -80,7 +80,7 @@ describe('defineBehavior', () => {
const started: string[] = [];
const Bhv = defineBehavior('Spawned', { start(ctx) { started.push(`e${ctx.entity}`); } });
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
await app.tick(1 / 60); // nothing yet
expect(started).toEqual([]);
@@ -95,9 +95,9 @@ describe('defineBehavior', () => {
const order: string[] = [];
defineBehavior('Fixed', { schedule: Schedule.FixedUpdate, update() { order.push('fixed'); } });
const app = App.new();
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
const Other = defineBehavior('Var', { update() { order.push('var'); } });
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
const e = app.world.spawn();
app.world.insert(e, getUserComponents().get('Fixed')!, {});
app.world.insert(e, Other, {});
diff --git a/sdk/tests/loop-integration.test.ts b/sdk/tests/loop-integration.test.ts
index 98f933c15..ed57d6b9a 100644
--- a/sdk/tests/loop-integration.test.ts
+++ b/sdk/tests/loop-integration.test.ts
@@ -8,7 +8,7 @@
* runtime scheduler (not just the per-unit tests).
*/
import { describe, it, expect, beforeEach } from 'vitest';
-import { App, flushPendingSystems } from '../src/app/app';
+import { App, flushPendingRegistrations } from '../src/app/app';
import { Input, InputState, GamepadButton, GamepadAxis } from '../src/input/input';
import { defineInputMap, Axis2D, Button, Keys2D, Stick, Key, GpButton } from '../src/input/inputMap';
import { defineBehavior } from '../src/behavior';
@@ -45,7 +45,7 @@ describe('gameplay loop integration (input map + behavior + scheduler)', () => {
const app = App.new();
const input = new InputState();
app.insertResource(Input, input); // no inputPlugin (no platform in tests) — drive the state directly
- flushPendingSystems(app); // InputMapEval (PreUpdate) + Behavior:Player (Update)
+ flushPendingRegistrations(app); // InputMapEval (PreUpdate) + Behavior:Player (Update)
const e = app.world.spawn();
app.world.insert(e, Player, { x: 0, y: 0, speed: 10 });
@@ -82,7 +82,7 @@ describe('gameplay loop integration (input map + behavior + scheduler)', () => {
});
const app = App.new();
app.insertResource(Input, new InputState());
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
const e = app.world.spawn();
app.world.insert(e, Enemy, {});
diff --git a/sdk/tests/payment.test.ts b/sdk/tests/payment.test.ts
index 11e9de670..9314b4bbe 100644
--- a/sdk/tests/payment.test.ts
+++ b/sdk/tests/payment.test.ts
@@ -8,7 +8,7 @@
* that read the API's existence would open and then fail at the tap.
*/
import { describe, it, expect } from 'vitest';
-import { PaymentAPI } from '../src/services/payment';
+import { platformCanPay, platformRequestPayment } from '../src/platform';
import { MiniGamePlatformAdapter } from '../src/platform/minigame/adapter';
import { setPlatform } from '../src/platform/base';
import type { MiniGameGlobal, MiniGameProfile } from '../src/platform/minigame/api';
@@ -16,8 +16,12 @@ import type { PlatformAdapter } from '../src/platform/types';
type PayOpts = Parameters<NonNullable<MiniGameGlobal['requestMidasPayment']>>[0];
+/** The service façade these rules are read through lives in
+ * estella-plugin-minigame-services; what is pinned here is the ADAPTER under it. */
+const api = { get available() { return platformCanPay(); }, request: platformRequestPayment };
+
function host(opts: { where?: string; pay?: (o: PayOpts) => void } = {}): {
- api: PaymentAPI; calls: PayOpts[];
+ api: typeof api; calls: PayOpts[];
} {
const calls: PayOpts[] = [];
const profile: MiniGameProfile = {
@@ -31,16 +35,16 @@ function host(opts: { where?: string; pay?: (o: PayOpts) => void } = {}): {
} as unknown as MiniGameGlobal,
};
setPlatform(new MiniGamePlatformAdapter(profile));
- return { api: new PaymentAPI(), calls };
+ return { api, calls };
}
/** A mini-game host with no purchase API at all. */
-function hostWithoutPay(): PaymentAPI {
+function hostWithoutPay(): typeof api {
setPlatform(new MiniGamePlatformAdapter({
id: 'wechat', hostLabel: 'Test',
global: { getSystemInfoSync: () => ({ platform: 'android' }) } as unknown as MiniGameGlobal,
}));
- return new PaymentAPI();
+ return api;
}
describe('available', () => {
@@ -66,7 +70,7 @@ describe('available', () => {
it('is false with no purchase API, and off-platform', () => {
expect(hostWithoutPay().available).toBe(false);
setPlatform({ name: 'web', devicePixelRatio: () => 1 } as unknown as PlatformAdapter);
- expect(new PaymentAPI().available).toBe(false);
+ expect(api.available).toBe(false);
});
});
diff --git a/sdk/tests/services-ads.test.ts b/sdk/tests/services-ads.test.ts
index 003f2d967..f099aaaab 100644
--- a/sdk/tests/services-ads.test.ts
+++ b/sdk/tests/services-ads.test.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/**
- * @file Platform services: the ads takeover ceremony and the share card.
+ * @file Platform services: the ads takeover ceremony.
*
* The contract under test is the part every game hand-rolls wrong: the game
* clock pauses and the audio device suspends for exactly the span of the ad,
@@ -11,7 +11,6 @@
import { describe, it, expect } from 'vitest';
import { AdsAPI, createMockAdProvider, type AdProvider } from '../src/services/ads';
import { createTakeover, type TakeoverHost } from '../src/services/takeover';
-import { ShareAPI } from '../src/services/share';
function recordingHost(): TakeoverHost & { events: string[]; paused: boolean } {
const h = {
@@ -101,21 +100,3 @@ describe('AdsAPI takeover ceremony', () => {
expect(created).toBe(2);
});
});
-
-describe('ShareAPI', () => {
- it('is honestly unavailable off-platform, and share() says so', () => {
- const share = new ShareAPI();
- expect(share.available).toBe(false);
- expect(share.share({ title: 'hi' })).toBe(false);
- });
-
- it('resolves a functional default card at share time', () => {
- const share = new ShareAPI();
- let score = 1;
- share.setShareCard(() => ({ title: `score ${score}` }));
- score = 42;
- // Off-platform share() returns false, but the card resolution itself is
- // what passive shares consume — reach it through the resolver.
- expect((share as unknown as { resolveCard_(): { title: string } }).resolveCard_().title).toBe('score 42');
- });
-});
diff --git a/sdk/tests/system-ordering.test.ts b/sdk/tests/system-ordering.test.ts
index 2cf95cf44..5eb9835e1 100644
--- a/sdk/tests/system-ordering.test.ts
+++ b/sdk/tests/system-ordering.test.ts
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
import { describe, it, expect, beforeEach } from 'vitest';
-import { App, flushPendingSystems } from '../src/app/app';
+import { App, flushPendingRegistrations } from '../src/app/app';
import { addSystem, defineSystem, Schedule } from '../src/ecs/system';
describe('System Dependency Ordering', () => {
@@ -222,7 +222,7 @@ describe('System Dependency Ordering', () => {
addSystem(camera);
addSystem(move);
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
(app as any).runner_ = { run: (sys: any) => sys._fn() };
await (app as any).runSchedule(Schedule.Update);
diff --git a/sdk/tests/ui-drag-plugin.test.ts b/sdk/tests/ui-drag-plugin.test.ts
index d05e8f073..439c039d0 100644
--- a/sdk/tests/ui-drag-plugin.test.ts
+++ b/sdk/tests/ui-drag-plugin.test.ts
@@ -10,7 +10,7 @@
* the emitted events.
*/
import { describe, it, expect, beforeEach } from 'vitest';
-import { flushPendingSystems } from '../src/app/app';
+import { flushPendingRegistrations } from '../src/app/app';
import type { App } from '../src/app/app';
import { Transform } from '../src/ecs/component';
import { Input, InputState } from '../src/input/input';
@@ -38,7 +38,7 @@ beforeEach(() => {
worldMouseX: 0, worldMouseY: 0, valid: true,
} as UICameraData);
dragPlugin.build(app); // reads UIEvents; registers Draggable/DragState; adds DragSystem
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
});
function draggable(opts: Partial<{ enabled: boolean; dragThreshold: number; lockX: boolean; lockY: boolean; hovered: boolean }> = {}): Entity {
diff --git a/sdk/tests/ui-focus-plugin.test.ts b/sdk/tests/ui-focus-plugin.test.ts
index 1e5c0e59a..b2a19bc85 100644
--- a/sdk/tests/ui-focus-plugin.test.ts
+++ b/sdk/tests/ui-focus-plugin.test.ts
@@ -9,7 +9,7 @@
* the harness satisfies.
*/
import { describe, it, expect, beforeEach } from 'vitest';
-import { flushPendingSystems } from '../src/app/app';
+import { flushPendingRegistrations } from '../src/app/app';
import type { App } from '../src/app/app';
import { Input, InputState } from '../src/input/input';
import { UIEvents, UIEventQueue } from '../src/ui/core/events';
@@ -26,7 +26,7 @@ beforeEach(() => {
app.insertResource(Input, new InputState()); // fresh, so key state can't leak between tests
app.insertResource(UIEvents, new UIEventQueue());
focusPlugin.build(app); // registers Focusable, inserts a fresh FocusManager, adds FocusSystem
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
});
/** A focusable entity. `enabled` drives the (builtin) Interactable gate. */
diff --git a/sdk/tests/ui-visibility-events.test.ts b/sdk/tests/ui-visibility-events.test.ts
index 091dec60d..b6d2511cd 100644
--- a/sdk/tests/ui-visibility-events.test.ts
+++ b/sdk/tests/ui-visibility-events.test.ts
@@ -9,7 +9,7 @@
* reads the watcher makes, not just the events it emits.
*/
import { describe, it, expect, beforeEach, vi } from 'vitest';
-import { flushPendingSystems } from '../src/app/app';
+import { flushPendingRegistrations } from '../src/app/app';
import type { App } from '../src/app/app';
import { EntityEventQueue } from '../src/ecs/entityEvents';
import { UIEvents, UIEventQueue, UIEventType } from '../src/ui/core/events';
@@ -96,7 +96,7 @@ describe('UIVisibilityPlugin', () => {
events = new UIEventQueue();
app.insertResource(UIEvents, events);
uiVisibilityPlugin.build(app);
- flushPendingSystems(app);
+ flushPendingRegistrations(app);
});
/** A UI node, on screen unless told otherwise. */