From: Laurent Mazet Date: Sun, 6 Dec 2020 16:59:03 +0000 (+0100) Subject: Merge branch 'develop' into timer X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=b059eaf9e9e1f91131f03dcaa74c3e69e1c59b36;p=trivabble.git Merge branch 'develop' into timer --- b059eaf9e9e1f91131f03dcaa74c3e69e1c59b36 diff --cc l10n/po/fr/trivabble.po index 50a414f,571bc21..f9c022f --- a/l10n/po/fr/trivabble.po +++ b/l10n/po/fr/trivabble.po @@@ -229,20 -232,11 +235,29 @@@ msgstr "Astuce ! msgid "Next tip" msgstr "Astuce suivante" -msgid "Disable the spell checker" ++msgid "Disable the spell checker" + msgstr "Désactiver la vérification orthographique" + + msgid "Spell checking is not available for this language." + msgstr "La vérification orthographique n'est pas disponible dans cette langue." + + msgid "Score new words" + msgstr "Compter les points" ++ +msgid "Turn timer:" +msgstr "Temps du tour :" + +msgid "Global timer:" +msgstr "Temp global :" + +msgid "{0}d" +msgstr "{0}j" + +msgid "{0}h" +msgstr "{0}h" + +msgid "{0}' {1}''" +msgstr "{0}' {1}''" + +msgid "Enable timer" +msgstr "Activer le timer" diff --cc l10n/pot/trivabble.pot index 89d41ed,7b04271..380a197 --- a/l10n/pot/trivabble.pot +++ b/l10n/pot/trivabble.pot @@@ -142,6 -142,6 +142,12 @@@ msgstr " msgid "Who's turn? Click on the Turn button!" msgstr "" ++msgid "Click on (+) to increase someone's score." ++msgstr "" ++ ++msgid "Show a cell to everyone by double-clicking on it." ++msgstr "" ++ msgid "Show my rack to other players" msgstr "" @@@ -222,32 -225,23 +234,35 @@@ msgstr " msgid "Flash light color" msgstr "" --msgid "Click on (+) to increase someone's score." -msgstr "" - -msgid "Show a cell to everyone by double-clicking on it." -msgstr "" - + msgid "Tip!" msgstr "" - msgid "Show a cell to everyone by double-clicking on it." + msgid "Next tip" msgstr "" - msgid "Tip!" + msgid "Disable the spell checker" msgstr "" - msgid "Next tip" + msgid "Spell checking is not available for this language." + msgstr "" + + msgid "Score new words" msgstr "" + +msgid "Turn timer:" +msgstr "" + +msgid "Global timer:" +msgstr "" + +msgid "{0}d" +msgstr "" + +msgid "{0}h" +msgstr "" + +msgid "{0}' {1}''" +msgstr "" + +msgid "Enable timer" +msgstr "" diff --cc public/trivabble.js index e74c3f8,0873324..e0b30ff --- a/public/trivabble.js +++ b/public/trivabble.js @@@ -58,12 -59,9 +59,15 @@@ setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]); setConf("FLASH_LIGHT_DURATION", middle("FLASH_LIGHT_DURATIONS")); setConf("FLASH_LIGHT_COLOR", "#ee6633"); + setConf("API_ENTRY_POINT", Conf.APP_PATH + "/:trivabble"); + setConf("PREMIUM_SEVEN_TILES", 50); + setConf("SCORE_LAST_PLAYER", true); + setConf("ENABLE_TIMER", true); + + function isSetting(key) { + return Object.prototype.hasOwnProperty.call(Conf, key) || + Object.prototype.hasOwnProperty.call(localStorage, key); + } function getSetting(key) { let type; @@@ -920,10 -921,8 +927,9 @@@ function setCurrentPlayer(player) { if (currentPlayer && tablePlayers[currentPlayer]) { tablePlayers[currentPlayer].classList.remove("current-player"); + localStorage.timerTurnDate = timerDate(); } - currentTilePlayed = {}; currentPlayer = player; refreshCurrentPlayer(); } @@@ -2097,57 -2217,8 +2225,57 @@@ } } + function timerString(delta) { + const d = Math.floor(delta / (60 * 60 * 24)); + const h = Math.floor((delta % (60 * 60 * 24)) / (60 * 60)); + const m = Math.floor((delta % (60 * 60)) / 60); + const s = Math.floor(delta % 60); + return ((d > 0) ? format(_("{0}d "), d) : "") + + ((h > 0) ? format(_("{0}h "), h) : "") + + format(_("{0}' {1}''"), m, s); + } + + function timerDate() { + return Math.floor(Date.now() / 1000); + } + + function initTimer() { + if (!Object.prototype.hasOwnProperty.call(localStorage, "timerTurnDate")) { + localStorage.timerTurnDate = timerDate(); + } + if (!Object.prototype.hasOwnProperty.call(localStorage, "timerGlobalDate")) { + localStorage.timerGlobalDate = timerDate(); + } + if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) { + localStorage.timerEnable = getSetting("ENABLE_TIMER"); + } + document.getElementById("enable-timer").onclick = function () { + setTimerState(document.getElementById("enable-timer").checked); + }; + setTimerState(localStorage.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); + } 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; + } + localStorage.timerGlobalDate = localStorage.timerTurnDate = timerDate(); + } + } + function repromptName(f) { - if (getSetting("trivabblePlayerName") && getSetting("trivabblePlayerName").trim()) { + if (getSetting("PlayerName") && getSetting("PlayerName").trim()) { f(); } else { myPrompt(