From: Laurent Mazet Date: Sat, 5 Sep 2020 06:20:50 +0000 (+0200) Subject: Merge branch 'develop' into timer X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=a58dd247ada5686f57d376078acfb207b8eb3669;p=trivabble.git Merge branch 'develop' into timer --- a58dd247ada5686f57d376078acfb207b8eb3669 diff --cc l10n/po/fr/trivabble.po index d5f5f3d,d990adf..a12c96f --- a/l10n/po/fr/trivabble.po +++ b/l10n/po/fr/trivabble.po @@@ -196,20 -193,26 +196,44 @@@ msgstr "La vérification orthographiqu msgid "Spell checking is based on:" msgstr "La vérification orthographique est basée sur :" + msgid "Settings" + msgstr "Paramètres" + + msgid "Configuration window" + msgstr "Fenêtre de configuration" + + msgid "Look at:" + msgstr "Regardez ici :" + + msgid "Double tap duration" + msgstr "Durée de la double tape" + + msgid "(slow)" + msgstr "(lent)" + + msgid "(fast)" + msgstr "(rapide)" + + msgid "Flash light duration" + msgstr "Durée du flash laser" + + msgid "Flash light color" + msgstr "Couleur du flash laser" ++ +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 662c5ed,4904eb3..69976b6 --- a/l10n/pot/trivabble.pot +++ b/l10n/pot/trivabble.pot @@@ -202,20 -199,25 +202,43 @@@ msgstr " msgid "Spell checking is based on:" msgstr "" + msgid "Settings" + msgstr "" + + msgid "Configuration window" + + msgid "Look at:" + msgstr "" + + msgid "Double tap duration" + msgstr "" + + msgid "(slow)" + msgstr "" + + msgid "(fast)" + msgstr "" + + msgid "Flash light duration" + msgstr "" + + msgid "Flash light color" + 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/index.html index 8d0308d,d97ccec..76d95bd --- a/public/index.html +++ b/public/index.html @@@ -54,8 -54,10 +54,11 @@@

+

+

+

+

- + diff --cc public/trivabble.css index 7ead290,280b50a..9528819 --- a/public/trivabble.css +++ b/public/trivabble.css @@@ -550,8 -562,3 +562,7 @@@ td.blink #info-spell-checking a { color:black; } + +#timer { + text-align: center; +} - diff --cc public/trivabble.js index f47c14d,24bf947..3502851 --- a/public/trivabble.js +++ b/public/trivabble.js @@@ -43,7 -43,9 +43,10 @@@ setConf("MAX_WEBSOCKET_ERRORS", 1); setConf("APP_PATH", ""); setConf("ENABLE_SPELL_CHECKER", false); + setConf("DOUBLE_TAP_DURATIONS", [650, 1100, 1800, 3000, 5000]); + setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]); + setConf("FLASH_LIGHT_COLOR", "#E3E"); + setConf("ENABLE_TIMER", true); const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) { return s; @@@ -1783,55 -1897,73 +1900,122 @@@ } } + function translateDuration(x, values) { + if (x < 0) { + return null; + } + + if (x < values.length) { + return values[Math.floor(x)]; + } + + for (let i = 0; i < values.length; i++) { + if (x <= values[i]) { + return i; + } + } + return values.length - 1; + } + + function initLaserPointer() { + document.body.addEventListener("dblclick", laserDblClick); + document.body.addEventListener("touchstart", laserTouch); + + if (!Object.prototype.hasOwnProperty.call(localStorage, "doubleTapDuration")) { + localStorage.doubleTapDuration = Conf.DOUBLE_TAP_DURATIONS[Math.floor(Conf.DOUBLE_TAP_DURATIONS.length / 2)]; + } + const doubleTapDuration = document.getElementById("double-tap-duration"); + if (doubleTapDuration) { + doubleTapDuration.max = Conf.DOUBLE_TAP_DURATIONS.length - 1; + doubleTapDuration.value = translateDuration(localStorage.doubleTapDuration, Conf.DOUBLE_TAP_DURATIONS); + doubleTapDuration.onchange = function () { + localStorage.doubleTapDuration = translateDuration( + document.getElementById("double-tap-duration").value, + Conf.DOUBLE_TAP_DURATIONS + ); + }; + } + + if (!Object.prototype.hasOwnProperty.call(localStorage, "flashLightDuration")) { + localStorage.flashLightDuration = Conf.FLASH_LIGHT_DURATIONS[Math.floor(Conf.FLASH_LIGHT_DURATIONS.length / 2)]; + } + const flashLightDuration = document.getElementById("flash-light-duration"); + if (flashLightDuration) { + flashLightDuration.max = Conf.FLASH_LIGHT_DURATIONS.length - 1; + flashLightDuration.value = translateDuration(localStorage.flashLightDuration, Conf.FLASH_LIGHT_DURATIONS); + flashLightDuration.onchange = function () { + localStorage.flashLightDuration = translateDuration( + document.getElementById("flash-light-duration").value, + Conf.FLASH_LIGHT_DURATIONS + ); + }; + } + + if (!Object.prototype.hasOwnProperty.call(localStorage, "flashLightColor")) { + localStorage.flashLightColor = Conf.FLASH_LIGHT_COLOR; + } + const flashLightColor = document.getElementById("flash-light-color"); + if (flashLightColor) { + flashLightColor.value = localStorage.flashLightColor; + flashLightColor.onchange = function () { + localStorage.flashLightColor = document.getElementById("flash-light-color").value; + const style = document.createElement("style"); + style.textContent = ".laser-highlight {background-color: " + localStorage.flashLightColor + ";}"; + document.body.appendChild(style); + }; + flashLightColor.onchange(); + } + } + + 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 = Conf.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 (localStorage.trivabblePlayerName && localStorage.trivabblePlayerName.trim()) { f(); @@@ -2050,7 -2184,7 +2236,8 @@@ initGame(); initSound(); initSpellChecker(); + initLaserPointer(); + initTimer(); }; trivabble.l10nError = trivabble.run;