benjivers/val Public Public: anyone can read this; the crew can change it.
Never let a refused pointer lock break the view
A browser rejects requestPointerLock when it is asked again too soon after Escape, and an unhandled rejection in the click handler is a console error for something that is only a shrug: the hint stays up and the next click takes. A browser without pointer lock at all drops to the top-down view rather than leaving somebody in a first-person view they cannot aim in. Co-Authored-By: Claude Opus 5 <[email protected]>
1 file
changed +6
−1
static/val.js +6 −1
| @@ -130,7 +130,12 @@ addEventListener("blur", () => { | ||
| 130 | 130 | // look, Escape gives it back. The angle sent is the same angle as ever. |
| 131 | 131 | view.addEventListener("click", () => { |
| 132 | 132 | beeper.wake(); |
| 133 | if (mode === "fp" && !locked && view.requestPointerLock) view.requestPointerLock(); | |
| 133 | if (mode !== "fp" || locked) return; | |
| 134 | if (!view.requestPointerLock) return setMode("top"); // no lock, no first person | |
| 135 | // Asked for too soon after the last release, a browser rejects this; that | |
| 136 | // is a shrug, not an error, and the hint stays up until it takes. | |
| 137 | const asked = view.requestPointerLock(); | |
| 138 | if (asked && asked.catch) asked.catch(() => {}); | |
| 134 | 139 | }); |
| 135 | 140 | document.addEventListener("pointerlockchange", () => { |
| 136 | 141 | locked = document.pointerLockElement === view; |