Main menu
This commit is contained in:
@@ -96,6 +96,8 @@ export class InputManager {
|
||||
static mouse_ungrab_timer = 0;
|
||||
static mouse_ungrab_timeout = -1;
|
||||
static pointer_lock_waiting = false;
|
||||
// the browser let go of the mouse while the game wanted it, like escape or switching windows
|
||||
static #lost_pointer_lock = false;
|
||||
|
||||
static initialize(canvas: HTMLCanvasElement) {
|
||||
self.addEventListener("keydown", (e) => {
|
||||
@@ -164,6 +166,7 @@ export class InputManager {
|
||||
if (!grab) {
|
||||
if (this.pointer_lock_flag) {
|
||||
this.mouse_ungrab_timer = performance.now();
|
||||
this.#lost_pointer_lock = true;
|
||||
}
|
||||
}
|
||||
this.pointer_lock_flag = grab;
|
||||
@@ -266,6 +269,13 @@ export class InputManager {
|
||||
}
|
||||
}
|
||||
|
||||
// whether the mouse was taken away since the last call, browsers eat the escape that does it
|
||||
static take_lost_pointer_lock() {
|
||||
const lost = this.#lost_pointer_lock;
|
||||
this.#lost_pointer_lock = false;
|
||||
return lost;
|
||||
}
|
||||
|
||||
static is_mouse_grabbed() {
|
||||
return document.hasFocus() && document.pointerLockElement === canvas;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user