fix(host): attachInput 补 keydown/keyup window 桥接(getInput 契约 key 两态)

boot-game-host.js attachInput() 原只桥 pointerdown/move/up,漏 keydown/keyup → ctx.getInput() 键盘通道空,所有方向键/空格游戏(2048/Tetris/Asteroids)输入死。对齐同仓 host-dev/host.js:427-428 范式挂 window 桥 ev.key。纯增量、零兼容风险(inputBridge _assertType 白名单已含 keydown/keyup)。W-G1 scale-20 两轮对抗诊断实证:失败严格沿键盘 vs 指针分界。属 L0 域冻结契约修复,经创始人授权隔离执行,供 cherry-pick 到 dev/2.0.0。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lili 2026-06-14 10:34:43 -07:00
parent 4836a6f519
commit d754b71e65

View File

@ -306,6 +306,11 @@ export async function bootGameHost(opts) {
targetCanvas.addEventListener('pointerup', (ev) => {
inputBridge._emit('pointerup', toCanvasXY(ev.clientX, ev.clientY));
});
// 键盘桥接:挂 window(键盘无 canvas rect,坐标无关),补齐 getInput 契约的 key 两态。
// 对齐同仓 host-dev/host.js:427-428 已有范式;W-G1 scale-20 两轮对抗诊断实证:
// 原 attachInput 漏此桥 → 所有方向键/空格游戏(2048/Tetris/Asteroids)输入永远收不到、score≈0、phase 永久 playing。
window.addEventListener('keydown', (ev) => { unlockAudioOnce(); inputBridge._emit('keydown', { key: ev.key }); });
window.addEventListener('keyup', (ev) => inputBridge._emit('keyup', { key: ev.key }));
}
/* ── RAF(stub play 模式)── */