remove localStorage usage
authorLaurent Mazet <mazet@softndesign.org>
Mon, 7 Dec 2020 21:28:39 +0000 (22:28 +0100)
committerLaurent Mazet <mazet@softndesign.org>
Mon, 7 Dec 2020 21:28:39 +0000 (22:28 +0100)
l10n/po/fr/trivabble.po
l10n/pot/trivabble.pot
public/index.html
public/trivabble.js

index f9c022fc2ab10ed304492c28f85189246c5c702b..4ee0c1af5560c56b07911b83f178c9b8bd5d2367 100644 (file)
@@ -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"
index 380a1974f91556b68a9cc2f6e8b972ce336ea11c..afbd73b46100e4a67a5810fb0a23083f595c347d 100644 (file)
@@ -252,7 +252,7 @@ msgstr ""
 msgid  "Turn timer:"
 msgstr ""
 
-msgid  "Global timer:"
+msgid  "Game timer:"
 msgstr ""
 
 msgid  "{0}d"
index 974fd70a5710026cb2bfa7cb16b3496b031e57c2..a95ecf23cda11294f9759a54f04632f8a64fcbe5 100644 (file)
                 <span data-l10n="text-content">Turn timer:</span>
                 <span id="timer-turn">0</span>
                 <br />
-                <span data-l10n="text-content">Global timer:</span>
-                <span id="timer-global">0</span>
+                <span data-l10n="text-content">Game timer:</span>
+                <span id="timer-game">0</span>
             </p>
             <div id="bag"></div>
             <p><span data-l10n="text-content">Number of tiles in the bag:</span><br /><span id="remaining-letters">102</span></p>
index e0b30ff55b3fcc9112255e8e2ea29fe2466d9669..c95147e932ab16daed06474f6326f8f040d689ec 100644 (file)
         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) {
     function setCurrentPlayer(player) {
         if (currentPlayer && tablePlayers[currentPlayer]) {
             tablePlayers[currentPlayer].classList.remove("current-player");
-            localStorage.timerTurnDate = timerDate();
+            setSetting("TimerTurnDate", timerDate());
         }
 
         currentPlayer = player;
         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"}]);
             }
         );
     }
 
     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);
         }
     }