Merge branch 'timer' into 'develop'

Timer

See merge request raphj/trivabble!11
This commit is contained in:
Raphaël Jakse 2020-12-12 12:18:16 +00:00
commit 2bcac05534
6 changed files with 164 additions and 16 deletions

View File

@ -172,6 +172,9 @@ msgstr "Vous avez changé la langue du plateau en {0}"
msgid "{0} changed the language of the board to {1}"
msgstr "{0} a changé la langue du plateau en {1}"
msgid "Settings"
msgstr "Paramètres"
msgid "Check spelling for new words"
msgstr "Vérifier l'orthographe des mots nouveaux"
@ -232,7 +235,7 @@ 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."
@ -240,3 +243,21 @@ msgstr "La vérification orthographique n'est pas disponible dans cette langue."
msgid "Score new words"
msgstr "Compter les points"
msgid "Turn:"
msgstr "Tour :"
msgid "{0}d"
msgstr "{0}j"
msgid "{0}h {1}' {2}''"
msgstr "{0} h {1} min {2} s"
msgid "{0}' {1}''"
msgstr "{0} min {1}"
msgid "Show the timer"
msgstr "Chronométrer la partie"
msgid "To measure playing time, activate the timer."
msgstr "Pour mesurer les temps de jeu, activez le chronomètre."

View File

@ -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 ""
@ -172,6 +178,9 @@ msgstr ""
msgid "{0} changed the language of the board to {1}"
msgstr ""
msgid "Settings"
msgstr ""
msgid "Check spelling for new words"
msgstr ""
@ -225,12 +234,6 @@ 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 ""
@ -245,3 +248,21 @@ msgstr ""
msgid "Score new words"
msgstr ""
msgid "Turn:"
msgstr ""
msgid "{0}d"
msgstr ""
msgid "{0}h {1}' {2}''"
msgstr ""
msgid "{0}' {1}''"
msgstr ""
msgid "Show the timer"
msgstr ""
msgid "To measure playing time, activate the timer."
msgstr ""

View File

@ -41,6 +41,9 @@ window.TrivabbleConf = {
// Score is automically affected to last player. If false, score is automatically affected to the player who pressed the Score button
SCORE_LAST_PLAYER: true,
// Timer activation
ENABLE_TIMER: false,
// I don't like trailing commas, here is a nice message for you reading this file :-)
HAVE_FUN: true
};

View File

@ -55,18 +55,21 @@
<h1 data-l10n="text-content">Settings</h1>
<button class="modal-button" id="btn-settings-close">&#215;</button>
</div>
<div>
<p><label><input type="checkbox" id="enable-timer" /> <span data-l10n="text-content">Show the timer</span></label></p>
</div>
<div>
<p><label><input type="checkbox" id="tiles-sound" /><span data-l10n="text-content">Sound of the tiles</span></label></p>
<p><label><input type="checkbox" id="msg-sound" /><span data-l10n="text-content">Sound of messages</span></label></p>
</div>
<div>
<p id="disable-spell-checker-p" hide="true">
<p id="disable-spell-checker-p" hidden="true">
<label>
<input type="checkbox" id="disable-spell-checker" />
<span data-l10n="text-content">Disable the spell checker</span>
</label>
</p>
<p id="no-spell-checker-p" hide="false">
<p id="no-spell-checker-p" hidden="false">
<span data-l10n="text-content">Spell checking is not available for this language.</span>
</p>
</div>
@ -111,8 +114,11 @@
</div>
<div id="panel" class="panel">
<div id="btn-settings-wrapper">
<div id="btn-settings-and-timer">
<button id="btn-settings" data-l10n="text-content">Settings</button>
<p id="timer" hidden="true">
<span data-l10n="text-content">Turn:</span> <span id="timer-turn">--</span> / <span id="timer-game">--</span>
</p>
</div>
<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>
@ -135,6 +141,7 @@
<p data-l10n="text-content" hidden="true">Who's turn? Click on the Turn button!</p>
<p data-l10n="text-content" hidden="true">Click on (+) to increase someone's score.</p>
<p data-l10n="text-content" hidden="true">Show a cell to everyone by double-clicking on it.</p>
<p data-l10n="text-content" hidden="true">To measure playing time, activate the timer.</p>
</div>
<button id="next-help-msg" class="minibutton" data-l10n="title" title="Next tip"></button>
</div>

View File

@ -179,6 +179,7 @@ button {
#rack {
background:#EEC;
z-index:10;
font-size:0;
border-radius:4px;
display:inline-block;
@ -624,9 +625,10 @@ td.blink {
border:none;
margin:0;
min-height: 2em;
float:right
}
#panel #btn-settings-wrapper {
#panel #btn-settings-and-timer {
text-align:right;
}
@ -732,3 +734,18 @@ button#next-help-msg:hover {
display:flex;
flex-direction:column;
}
#timer {
font-size:x-small;
text-align:center;
margin:0;
margin-right:1ex;
}
#timer > span {
white-space:nowrap;
}
#timer > span:first-child {
color:gray;
}

View File

@ -62,8 +62,14 @@
setConf("API_ENTRY_POINT", Conf.APP_PATH + "/:trivabble");
setConf("PREMIUM_SEVEN_TILES", 50);
setConf("SCORE_LAST_PLAYER", true);
setConf("ENABLE_TIMER", false);
function getSetting(key) {
function isSetting(key) {
return Object.prototype.hasOwnProperty.call(Conf, key) ||
Object.prototype.hasOwnProperty.call(localStorage, "trivabble" + key);
}
function getSetting(key, defaultValue) {
let type;
let value;
@ -96,6 +102,8 @@
} else {
console.error("Unsupported type");
}
} else if (defaultValue !== undefined) {
return defaultValue;
}
return value;
@ -143,7 +151,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) {
@ -152,8 +164,8 @@
const trivabble = window.trivabble = {l10n: _};
function format(s, v1, v2) {
return s.replace("{0}", v1).replace("{1}", v2);
function format(s, v1, v2, v3) {
return s.replace("{0}", v1).replace("{1}", v2).replace("{2}", v3);
}
let board;
@ -921,6 +933,7 @@
function setCurrentPlayer(player) {
if (currentPlayer && tablePlayers[currentPlayer]) {
tablePlayers[currentPlayer].classList.remove("current-player");
setSetting("TimerTurnDate", timerDate());
}
currentPlayer = player;
@ -1077,7 +1090,8 @@
case "popBag": //TODO
break;
case "reset": //TODO
case "reset":
setTimerDate(true);
tablePlayers = {};
while (participants.rows[1]) {
participants.removeChild(participants.rows[1]);
@ -2217,6 +2231,70 @@
}
}
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);
const sec = (s < 10) ? "0" + s : s;
const min = (m < 10) ? "0" + m : m;
const hour = (h < 10) ? "0" + h : h;
return ((d > 0) ? format(_("{0}d"), d) + " " : "") +
((h + d > 0) ? format(_("{0}h {1}' {2}''"), (d > 0) ? hour : h, min, sec) : format(_("{0}' {1}''"), m, sec));
}
function timerDate() {
return Math.floor(Date.now() / 1000);
}
function setTimerDate(force) {
const currentTimer = timerDate();
if (force || !isSetting("TimerTurnDate")) {
setSetting("TimerTurnDate", currentTimer);
}
if (force || !isSetting("TimerGameDate")) {
setSetting("TimerGameDate", currentTimer);
}
}
function initTimer() {
setTimerDate();
document.getElementById("enable-timer").onclick = function () {
setTimerState(document.getElementById("enable-timer").checked);
};
setTimerState(getSetting("TimerEnable", getSetting("ENABLE_TIMER")));
}
let timerTimeout = 0
function updateTimer() {
const currentTimer = timerDate();
document.getElementById("timer-turn").textContent = timerString(currentTimer - getSetting("TimerTurnDate"));
document.getElementById("timer-game").textContent = timerString(currentTimer - getSetting("TimerGameDate"));
}
function setTimerState(enabled) {
setSetting("TimerEnable", enabled);
if (timerTimeout) {
clearInterval(timerTimeout);
timerTimeout = 0
}
if (enabled) {
document.getElementById("timer").hidden = false;
document.getElementById("enable-timer").checked = true;
timerTimeout = setInterval(updateTimer, 1000);
updateTimer();
} else {
document.getElementById("timer").hidden = true;
document.getElementById("enable-timer").checked = false;
setTimerDate();
}
}
function repromptName(f) {
if (getSetting("PlayerName") && getSetting("PlayerName").trim()) {
f();
@ -2449,6 +2527,7 @@
initSpellChecker();
initFlashLight();
nextHelpMessage();
initTimer();
};
trivabble.l10nError = trivabble.run;