From 9c7a3b3e2a9d68623fcb542d4d2406c867ef727e Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Mon, 7 Dec 2020 22:28:39 +0100 Subject: [PATCH] remove localStorage usage --- l10n/po/fr/trivabble.po | 2 +- l10n/pot/trivabble.pot | 2 +- public/index.html | 4 ++-- public/trivabble.js | 46 +++++++++++++++++++++++++---------------- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/l10n/po/fr/trivabble.po b/l10n/po/fr/trivabble.po index f9c022f..4ee0c1a 100644 --- a/l10n/po/fr/trivabble.po +++ b/l10n/po/fr/trivabble.po @@ -247,7 +247,7 @@ msgstr "Compter les points" msgid "Turn timer:" msgstr "Temps du tour :" -msgid "Global timer:" +msgid "Game timer:" msgstr "Temp global :" msgid "{0}d" diff --git a/l10n/pot/trivabble.pot b/l10n/pot/trivabble.pot index 380a197..afbd73b 100644 --- a/l10n/pot/trivabble.pot +++ b/l10n/pot/trivabble.pot @@ -252,7 +252,7 @@ msgstr "" msgid "Turn timer:" msgstr "" -msgid "Global timer:" +msgid "Game timer:" msgstr "" msgid "{0}d" diff --git a/public/index.html b/public/index.html index 974fd70..a95ecf2 100644 --- a/public/index.html +++ b/public/index.html @@ -121,8 +121,8 @@ Turn timer: 0
- Global timer: - 0 + Game timer: + 0

Number of tiles in the bag:
102

diff --git a/public/trivabble.js b/public/trivabble.js index e0b30ff..c95147e 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -149,7 +149,11 @@ GameNumber: "number", BoardLang: "string", Lang: "string", - PlayerName: "string" + PlayerName: "string", + Timer: "number", + TimerEnable: "boolean", + TimerGameDate: "number", + TimerTurnDate: "number" }; const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) { @@ -927,7 +931,7 @@ function setCurrentPlayer(player) { if (currentPlayer && tablePlayers[currentPlayer]) { tablePlayers[currentPlayer].classList.remove("current-player"); - localStorage.timerTurnDate = timerDate(); + setSetting("TimerTurnDate", timerDate()); } currentPlayer = player; @@ -1617,7 +1621,9 @@ myConfirm( _("Are you sure you want to put all the tiles back in the bag (in order to play another game)?"), function () { - localStorage.timerGlobalDate = localStorage.timerTurnDate = timerDate(); + const currentTimer = timerDate(); + setSetting("TimerGameDate", currentTimer); + setSetting("TimerTurnDate", currentTimer); sendCmds([{cmd: "resetGame"}]); } ); @@ -2240,37 +2246,41 @@ } function initTimer() { - if (!Object.prototype.hasOwnProperty.call(localStorage, "timerTurnDate")) { - localStorage.timerTurnDate = timerDate(); + const currentTimer = timerDate(); + if (!isSetting("TimerTurnDate")) { + setSetting("TimerTurnDate", currentTimer); } - if (!Object.prototype.hasOwnProperty.call(localStorage, "timerGlobalDate")) { - localStorage.timerGlobalDate = timerDate(); + if (!isSetting("TimerGameDate")) { + setSetting("TimerGameDate", currentTimer); } - if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) { - localStorage.timerEnable = getSetting("ENABLE_TIMER"); + if (!isSetting("TimerEnable")) { + setSetting("TimerEnable", getSetting("ENABLE_TIMER")); } document.getElementById("enable-timer").onclick = function () { setTimerState(document.getElementById("enable-timer").checked); }; - setTimerState(localStorage.timerEnable); + setTimerState(getSetting("TimerEnable")); } function setTimerState(state) { if (state) { document.getElementById("timer").style.display = "block"; document.getElementById("enable-timer").checked = true; - localStorage.timer = setInterval(function () { - document.getElementById("timer-turn").textContent = timerString(timerDate() - Number(localStorage.timerTurnDate)); - document.getElementById("timer-global").textContent = timerString(timerDate() - Number(localStorage.timerGlobalDate)); - }, 1000); + setSetting("Timer", setInterval(function () { + const currentTimer = timerDate(); + document.getElementById("timer-turn").textContent = timerString(currentTimer - getSetting("TimerTurnDate")); + document.getElementById("timer-game").textContent = timerString(currentTimer - getSetting("TimerGameDate")); + }, 1000)); } else { document.getElementById("timer").style.display = "none"; document.getElementById("enable-timer").checked = false; - if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) { - clearInterval(localStorage.timer); - delete localStorage.timer; + if (isSetting("Timer")) { + clearInterval(getSetting("Timer")); + unsetSetting("Timer"); } - localStorage.timerGlobalDate = localStorage.timerTurnDate = timerDate(); + const currentTimer = timerDate(); + setSetting("TimerGameDate", currentTimer); + setSetting("TimerTurnDate", currentTimer); } } -- 2.30.2