remove localStorage usage

This commit is contained in:
Laurent Mazet 2020-12-07 22:28:39 +01:00
parent b059eaf9e9
commit 9c7a3b3e2a
4 changed files with 32 additions and 22 deletions

View 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"

View File

@ -252,7 +252,7 @@ msgstr ""
msgid "Turn timer:"
msgstr ""
msgid "Global timer:"
msgid "Game timer:"
msgstr ""
msgid "{0}d"

View File

@ -121,8 +121,8 @@
<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>

View File

@ -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);
}
}