wren/val Public Public: anyone can read this; nobody can change it.

forked from benjivers/val

workbenchthis machine

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]>
Wren committed 00e2918 Browse files
1 file changed +6 −1
static/val.js +6 −1
@@ -130,7 +130,12 @@ addEventListener("blur", () => {
130130 // look, Escape gives it back. The angle sent is the same angle as ever.
131131 view.addEventListener("click", () => {
132132 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(() => {});
134139 });
135140 document.addEventListener("pointerlockchange", () => {
136141 locked = document.pointerLockElement === view;
↑↓ navigate ↵ open esc close

Keyboard shortcuts