From: Laurent Mazet Date: Sun, 30 Aug 2020 19:40:57 +0000 (+0200) Subject: use date differents instead of interval increments X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=65d7ca684a8a0cd8ecca8c2ab2933706984e8033;p=trivabble.git use date differents instead of interval increments --- diff --git a/public/trivabble.js b/public/trivabble.js index 5cde17d..cea2e1f 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -770,7 +770,7 @@ function setCurrentPlayer(player) { if (currentPlayer && tablePlayers[currentPlayer]) { tablePlayers[currentPlayer].classList.remove("current-player"); - localStorage.timerTurn = 0; + localStorage.timerTurnDate = timerDate(); } currentTilePlayed = {}; @@ -1434,7 +1434,7 @@ myConfirm( _("Are you sure you want to put all the tiles back in the bag (in order to play another game)?"), function () { - localStorage.timerGlobal = localStorage.timerTurn = 0; + localStorage.timerGlobalDate = localStorage.timerTurnDate = timerDate(); sendCmds([{cmd: "resetGame"}]); } ); @@ -1793,12 +1793,16 @@ format(_("{0}' {1}''"), m, s); } + function timerDate() { + return Math.floor(Date.now() / 1000); + } + function initTimer() { - if (!Object.prototype.hasOwnProperty.call(localStorage, "timerTurn")) { - localStorage.timerTurn = 0; + if (!Object.prototype.hasOwnProperty.call(localStorage, "timerTurnDate")) { + localStorage.timerTurnDate = timerDate(); } - if (!Object.prototype.hasOwnProperty.call(localStorage, "timerGlobal")) { - localStorage.timerGlobal = 0; + if (!Object.prototype.hasOwnProperty.call(localStorage, "timerGlobalDate")) { + localStorage.timerGlobalDate = timerDate(); } if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) { localStorage.timerEnable = Conf.ENABLE_TIMER; @@ -1814,8 +1818,8 @@ document.getElementById("timer").style.display = "block"; document.getElementById("enable-timer").checked = true; localStorage.timer = setInterval(function () { - document.getElementById("timer-turn").textContent = timerString(++localStorage.timerTurn); - document.getElementById("timer-global").textContent = timerString(++localStorage.timerGlobal); + document.getElementById("timer-turn").textContent = timerString(timerDate() - localStorage.timerTurnDate); + document.getElementById("timer-global").textContent = timerString(timerDate() - localStorage.timerGlobalDate); }, 1000); } else { document.getElementById("timer").style.display = "none"; @@ -1824,7 +1828,7 @@ clearInterval(localStorage.timer); delete localStorage.timer; } - localStorage.timerGlobal = localStorage.timerTurn = 0; + localStorage.timerGlobalDate = localStorage.timerTurnDate = timerDate(); } }