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.

fix(test): forward mini-game touch gestures in package verification

yhhbc74dc61c675
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f1d78344b..6e668a449 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,8 @@ published separately; it ships inside the editor.
### Fixed
+- **Mini-game verification forwards touch gestures.** The package launch host forwards real canvas touch events and unregisters individual subscribers. The UI controls project now verifies the mini-game touch path alongside Web mouse input, using the modal button's current position instead of the dropdown below it.
+
- **Inertial scrolling travels consistently across frame rates.** Coast displacement integrates the exponentially decaying velocity instead of using its initial value for the whole frame. Frames that cross the stopping threshold integrate only the remaining motion, so a slow frame no longer extends a fling. Constant-speed and immediate-stop settings remain finite.
- **WASM video progress reaches the decoded endpoint.** Playback ending after a seek or a large update no longer leaves the clock at its previous position. The decoder derives the final duration from the last frame, and the SDK refreshes it before notifying end-of-playback listeners. Looping and seeking back to the beginning retain their normal clocks.
diff --git a/tools/goldenProjects.mjs b/tools/goldenProjects.mjs
index d1d039d7b..e76865f6c 100644
--- a/tools/goldenProjects.mjs
+++ b/tools/goldenProjects.mjs
@@ -898,10 +898,11 @@ export const GOLDEN = [
{
id: 'ui-controls',
certifies: ['ui-layout', 'text', 'ui-widgets'],
- targets: ['web', 'desktop'],
+ targets: ['web', 'wechat', 'desktop'],
tier: 'pr',
// Opens the modal — a whole-panel change, so the response is unmistakable.
- interact: { pointer: { x: 0.625, y: 0.675 }, frames: 40 },
+ interact: { pointer: { x: 0.67, y: 0.585 }, frames: 40 },
+ interactByTarget: { wechat: { touches: [{ from: 4, to: 8, x: 0.67, y: 0.585 }], frames: 40 } },
},
{
id: 'tilemap-demo',
@@ -1161,15 +1162,16 @@ export function subpackageFor(g) {
return g.subpackage ?? null;
}
-export function interactFor(g) {
- if (g.interactGap || !g.interact) return null;
+export function interactFor(g, target) {
+ const gesture = g.interactByTarget?.[target] ?? g.interact;
+ if (g.interactGap || !gesture) return null;
return {
- keys: g.interact.keys ?? [],
- pointer: g.interact.pointer ?? null,
- touches: g.interact.touches ?? null,
- pad: g.interact.pad ?? null,
- frames: g.interact.frames ?? 40,
- responds: g.interact.responds ?? DEFAULT_RESPONDS,
+ keys: gesture.keys ?? [],
+ pointer: gesture.pointer ?? null,
+ touches: gesture.touches ?? null,
+ pad: gesture.pad ?? null,
+ frames: gesture.frames ?? 40,
+ responds: gesture.responds ?? DEFAULT_RESPONDS,
};
}
diff --git a/tools/launchers/minigameHost.mjs b/tools/launchers/minigameHost.mjs
index 140bebb8e..17e4ca228 100644
--- a/tools/launchers/minigameHost.mjs
+++ b/tools/launchers/minigameHost.mjs
@@ -18,6 +18,31 @@
* fails when the contract grows a member the shim has not got.
*/
+/** Forward real canvas touch events through the vendor callback contract. */
+export function miniGameTouchBridge(canvas) {
+ const api = {};
+ const list = touches => Array.from(touches ?? [], touch => ({
+ identifier: touch.identifier, clientX: touch.clientX, clientY: touch.clientY,
+ }));
+ for (const phase of ['Start', 'Move', 'End', 'Cancel']) {
+ const kind = 'touch' + phase.toLowerCase();
+ const listeners = new Map();
+ api['onTouch' + phase] = callback => {
+ if (listeners.has(callback)) return;
+ const listener = event => callback({ touches: list(event.touches), changedTouches: list(event.changedTouches) });
+ listeners.set(callback, listener);
+ canvas.addEventListener(kind, listener, { passive: false });
+ };
+ api['offTouch' + phase] = callback => {
+ const listener = listeners.get(callback);
+ if (!listener) return;
+ canvas.removeEventListener(kind, listener);
+ listeners.delete(callback);
+ };
+ }
+ return api;
+}
+
/**
* The page source; `BASE` is substituted with the served root.
*
@@ -40,6 +65,7 @@ export const HOST_PAGE = (entry, failSubpackage = null) => `<!doctype html>
screenCanvas.width = window.innerWidth;
screenCanvas.height = window.innerHeight;
document.body.appendChild(screenCanvas);
+ const touchBridge = (${miniGameTouchBridge.toString()})(screenCanvas);
let screenTaken = false;
const makeCanvas = () => {
if (!screenTaken) { screenTaken = true; return screenCanvas; }
@@ -134,9 +160,7 @@ export const HOST_PAGE = (entry, failSubpackage = null) => `<!doctype html>
offOpen: noop, offClose: noop, offError: noop, offMessage: noop,
};
},
- onTouchStart: noop, onTouchMove: noop, onTouchEnd: noop,
- offTouchStart: noop, offTouchMove: noop, offTouchEnd: noop,
- onTouchCancel: noop, offTouchCancel: noop,
+ ...touchBridge,
// Keyboard: forwarded from the real DOM so a driven run can reach the game.
onKeyDown: (cb) => window.addEventListener('keydown', (e) => cb({ code: e.code, key: e.key })),
onKeyUp: (cb) => window.addEventListener('keyup', (e) => cb({ code: e.code, key: e.key })),
diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjs
index f541a943d..64af1e610 100644
--- a/tools/releaseNotes.mjs
+++ b/tools/releaseNotes.mjs
@@ -28,6 +28,8 @@ export const NOTES_FLOOR = 'v0.65.0';
* the reader recognises anyway.
*/
export const NOTED = {
+ 'fix(test): forward mini-game touch gestures in package verification':
+ { note: 'Mini-game verification forwards touch gestures.' },
'fix(ui): integrate inertial scroll distance across frame rates':
{ note: 'Inertial scrolling travels consistently across frame rates.' },
'fix(video): synchronize the decoded endpoint before playback ends':
diff --git a/tools/tests/minigame-touch-bridge.test.ts b/tools/tests/minigame-touch-bridge.test.ts
new file mode 100644
index 000000000..5c709e28e
--- /dev/null
+++ b/tools/tests/minigame-touch-bridge.test.ts
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+import { expect, it, vi } from 'vitest';
+import { miniGameTouchBridge, HOST_PAGE } from '../launchers/minigameHost.mjs';
+import { GOLDEN, interactFor } from '../goldenProjects.mjs';
+
+it('drives mini-game UI with touch and web UI with its mouse path', () => {
+ const ui = GOLDEN.find(project => project.id === 'ui-controls')!;
+ expect(ui.targets).toContain('wechat');
+ expect(interactFor(ui, 'wechat')?.pointer).toBeNull();
+ expect(interactFor(ui, 'wechat')?.touches).toHaveLength(1);
+ expect(interactFor(ui, 'web')?.pointer).toEqual({ x: 0.67, y: 0.585 });
+ expect(interactFor(ui)).toEqual(interactFor(ui, 'web'));
+});
+
+it('forwards independent touch identities and coordinates, including end and cancellation', () => {
+ const canvas = new EventTarget(), bridge = miniGameTouchBridge(canvas);
+ const touch = { identifier: 0, clientX: 123, clientY: 456 };
+ const other = { identifier: 7, clientX: 20, clientY: 40 };
+ for (const phase of ['Start', 'Move', 'End', 'Cancel']) {
+ const callback = vi.fn(); bridge['onTouch' + phase](callback);
+ const event = new Event('touch' + phase.toLowerCase());
+ Object.defineProperties(event, { touches: { value: [other] }, changedTouches: { value: [touch] } });
+ canvas.dispatchEvent(event);
+ expect(callback).toHaveBeenCalledWith({ touches: [other], changedTouches: [touch] });
+ bridge['offTouch' + phase](callback); canvas.dispatchEvent(event);
+ expect(callback).toHaveBeenCalledOnce();
+ }
+});
+
+it('removes exactly the selected subscriber and avoids duplicate registration', () => {
+ const canvas = new EventTarget(), bridge = miniGameTouchBridge(canvas);
+ const first = vi.fn(), second = vi.fn();
+ bridge.onTouchStart(first); bridge.onTouchStart(first); bridge.onTouchStart(second);
+ canvas.dispatchEvent(new Event('touchstart'));
+ expect(first).toHaveBeenCalledOnce(); expect(second).toHaveBeenCalledOnce();
+ bridge.offTouchStart(first); canvas.dispatchEvent(new Event('touchstart'));
+ expect(first).toHaveBeenCalledOnce(); expect(second).toHaveBeenCalledTimes(2);
+ expect(HOST_PAGE('game.js')).toContain(miniGameTouchBridge.toString());
+});
diff --git a/tools/verify-golden.mjs b/tools/verify-golden.mjs
index 391bf0404..52b22c379 100644
--- a/tools/verify-golden.mjs
+++ b/tools/verify-golden.mjs
@@ -565,7 +565,7 @@ for (const { id, target } of pairs) {
// Does the package answer a keyboard? An A/B against the undriven capture, not
// a before/after: a game animates on its own, so only "it differs BECAUSE of
// the key" is a claim. The worst-cell reducer is what sees a sprite move.
- const input = interactFor(golden);
+ const input = interactFor(golden, target);
if (!input) {
results.push({ id, target, stage: 'parity', ok: true });
console.log(`✓ ${id} ${target} — parity ${distance.toFixed(4)}`