From 8384b8d268cf1a32bceff542c3ef580fbeb1143b Mon Sep 17 00:00:00 2001 From: "Eevee (Evelyn Woods)" Date: Thu, 3 Sep 2020 13:53:22 -0600 Subject: [PATCH] Auto-pause when losing focus --- js/main.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/js/main.js b/js/main.js index b850748..a38ce07 100644 --- a/js/main.js +++ b/js/main.js @@ -1284,6 +1284,13 @@ class Game { this.input_action_elements[action] = el; } + // Auto pause when we lose focus + window.addEventListener('blur', ev => { + if (this.state === 'playing' || this.state === 'rewinding') { + this.set_state('paused'); + } + }); + this._advance_bound = this.advance.bind(this); this._redraw_bound = this.redraw.bind(this); // Used to determine where within a tic we are, for animation purposes