clock & onblur

This commit is contained in:
Adrien MALINGREY 2023-04-22 14:56:19 +02:00
parent 1a372a2d9f
commit 1ed3394d4e

15
app.js
View File

@ -420,7 +420,7 @@ class Stats {
this.highScore = Number(localStorage["highScore"]) || 0 this.highScore = Number(localStorage["highScore"]) || 0
this.combo = -1 this.combo = -1
this.b2b = -1 this.b2b = -1
this.startTime = 0 this._time = 0
} }
set score(score) { set score(score) {
@ -470,8 +470,12 @@ class Stats {
return this._goal return this._goal
} }
set time(time) {
this._time = time - this._time
}
get time() { get time() {
return new Date() - this.startTime return new Date() - this._time
} }
clock() { clock() {
@ -567,12 +571,11 @@ function pause() {
scheduler.clearTimeout(repeat) scheduler.clearTimeout(repeat)
scheduler.clearInterval(autorepeat) scheduler.clearInterval(autorepeat)
scheduler.clearInterval(clock) scheduler.clearInterval(clock)
stats.startTime = stats.time stats.time = new Date()
resumeButton.disabled = false resumeButton.disabled = false
settings.modal.show() settings.modal.show()
} }
onblur = pause
window.onblur = pause()
pause() pause()
@ -598,7 +601,7 @@ function resume(event) {
document.onkeydown = onkeydown document.onkeydown = onkeydown
document.onkeyup = onkeyup document.onkeyup = onkeyup
stats.startTime = stats.time stats.time = new Date()
scheduler.setInterval(clock, 1000) scheduler.setInterval(clock, 1000)
if (stats.fallPeriod) scheduler.setInterval(fall, stats.fallPeriod) if (stats.fallPeriod) scheduler.setInterval(fall, stats.fallPeriod)
} }