Merge branch 'develop' into timer
authorLaurent Mazet <mazet@softndesign.org>
Sat, 5 Sep 2020 06:20:50 +0000 (08:20 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Sat, 5 Sep 2020 06:20:50 +0000 (08:20 +0200)
1  2 
l10n/po/fr/trivabble.po
l10n/pot/trivabble.pot
public/index.html
public/trivabble.css
public/trivabble.js

index d5f5f3dea8572712d24581de651b54d64c923bd0,d990adffaab0d8e6b7f50a337f5cf52345f05488..a12c96f5047cce660a4afe2d449cf04f1cbf55e7
@@@ -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"
index 662c5ed5d8bc0562c1d71c2f9fb12046d0d51139,4904eb36e3fd1d72d4b2dd785a76dcde8c5096bc..69976b6e95b88ea5a0db05d89574510bbbfb3a8a
@@@ -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 ""
index 8d0308dca8fde2b17dee95893036891bb9f0e27c,d97ccec761cb1b9595bac7a677f4c4e712be5220..76d95bd641bb2b55c3182c693596bbee9105099b
                      <p><label><input type="checkbox" id="tiles-sound" checked="checked" /><span data-l10n="text-content">Sound of the tiles</span></label></p>
                      <p><label><input type="checkbox" id="msg-sound" checked="checked" /><span data-l10n="text-content">Sound of messages</span></label></p>
                      <p id="enable-spell-checker-outer" style="display:none"><label><input type="checkbox" id="enable-spell-checker" /> <span data-l10n="text-content">Enable spell checker</span></label></p>
-                 </div>
+                           <p><label><span data-l10n="text-content">(fast)</span><input type="range" min="0" max="0" id="double-tap-duration"/><span data-l10n="text-content">(slow)</span><br/><span data-l10n="text-content">Double tap duration</span></label></p>
+                           <p><label><span data-l10n="text-content">(fast)</span><input type="range" min="0" max="0" id="flash-light-duration"/><span data-l10n="text-content">(slow)</span><br/><span data-l10n="text-content">Flash light duration</span></label></p>
+                     <p><label><input type="text" size="6" id="flash-light-color"/> <span data-l10n="text-content">Flash light color</span></label></p>
 +                    <p><label><input type="checkbox" id="enable-timer" /> <span data-l10n="text-content">Enable timer</span></label></p>
+                       </div>
              </div>
          </div>
  
index 7ead290efab4909ffd4d52c562c1b0cba690a1d1,280b50a2af629fd26b6ec81f49b7d9a9db253174..9528819aab3c16c04046c87765abe48daf138803
@@@ -550,8 -562,3 +562,7 @@@ td.blink 
  #info-spell-checking a {
      color:black;
  }
- 
 +
 +#timer {
 +    text-align: center;
 +}
index f47c14dd151181cdb33c3cb8b9dcfa1a41ba0dd6,24bf94761cf895f0de7e421825dce7cad3c326b7..35028515061f66be4c1f96efe83fd67422f15cce
      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;
          }
      }
  
+     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();
          initGame();
          initSound();
          initSpellChecker();
+         initLaserPointer();
 +        initTimer();
      };
  
      trivabble.l10nError = trivabble.run;