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(agent): a key already held answers that it produced no press edge
yhh71a51bff81c5
diff --git a/desktop/electron/surfaceDriver.ts b/desktop/electron/surfaceDriver.tsindex 11d4620bb..58aacb64d 100644--- a/desktop/electron/surfaceDriver.ts+++ b/desktop/electron/surfaceDriver.ts@@ -331,7 +331,7 @@ export function createSurfaceDriver(down: `i.down(${x},${y},${button});`,up: `i.up(${button});`,wheel: `i.wheel(${x},${y});`,- key_down: `i.keyDown(${code});`,+ key_down: `return i.keyDown(${code});`,key_up: `i.keyUp(${code});`,tap: `i.touchStart(${id},${x},${y}); i.touchEnd(${id});`,// A pad is HELD until released — a game reads it every frame, so a@@ -356,7 +356,10 @@ export function createSurfaceDriver(return unwrap(await frame.executeJavaScript(carryError(`(() => { const p = window.__estellaPlay; if (!p || !p.input) `+ `throw new Error('this play realm publishes no input door — it predates play_input'); `- + `const i = p.input; ${call} return 'ok'; })()`,+ // A kind that has something to say answers with it; the rest, and any+ // realm older than the one that started answering, keep 'ok'.+ + `const i = p.input; const r = (() => { ${call} })(); `+ + `return r === undefined ? 'ok' : r; })()`,)));}// — What the TypeScript compiler knows. Main-process because the languagediff --git a/desktop/shared/toolCatalog.mjs b/desktop/shared/toolCatalog.mjsindex b112eb19d..b5ebe3db3 100644--- a/desktop/shared/toolCatalog.mjs+++ b/desktop/shared/toolCatalog.mjs@@ -701,6 +701,7 @@ const ATOMS = [+ 'ask the camera (CameraView.screenToWorld / UICameraInfo.worldMouseX) for where that is in the world rather than converting by hand. '+ '`code` is a KeyboardEvent code for the key kinds. It goes through the platform binding\'s own callbacks, so UI gets first refusal exactly as it would for a real event. '+ 'A pressed EDGE (isMouseButtonPressed / isKeyPressed) lasts one frame: call step() right after, then read the result. '+ + 'A key stays DOWN until you send key_up for it, and `key_down` on one already held makes no new edge — it answers `pressEdge: false` and the game does not react, while everything you read back afterwards looks perfectly normal. '+ 'Calling the game\'s own handler instead proves only that the handler works — not that a click reaches it.',schema: obj({kind: { type: 'string' }, x: { type: 'number' }, y: { type: 'number' },diff --git a/desktop/src/playHost.ts b/desktop/src/playHost.tsindex 99dd419a6..51177caba 100644--- a/desktop/src/playHost.ts+++ b/desktop/src/playHost.ts@@ -582,7 +582,16 @@ async function buildAppAndRun(msg: InitMessage): Promise<void> {down: (x: number, y: number, button = 0) => injected.onPointerDown?.(button, x, y),up: (button = 0) => injected.onPointerUp?.(button),wheel: (dx: number, dy: number) => injected.onWheel?.(dx, dy),- keyDown: (code: string) => injected.onKeyDown?.(code),+ // A key already held produces no press edge, and `isKeyPressed` is what a+ // game reads for "jump". Answered rather than swallowed: everything the+ // caller reads back afterwards looks perfectly healthy.+ keyDown: (code: string) => {+ const held = inputState()?.isKeyDown(code) === true;+ injected.onKeyDown?.(code);+ return held+ ? { ok: true, pressEdge: false, note: `${code} was already down — no press edge this frame. Send key_up first, then key_down.` }+ : { ok: true, pressEdge: true };+ },keyUp: (code: string) => injected.onKeyUp?.(code),touchStart: (id: number, x: number, y: number) => injected.onTouchStart?.(id, x, y),touchMove: (id: number, x: number, y: number) => injected.onTouchMove?.(id, x, y),