setConf("ENABLE_EVENT_SOURCE", true);
setConf("MAX_WEBSOCKET_ERRORS", 1);
setConf("APP_PATH", "");
+ setConf("APP_PATH", "");
+ setConf("ENABLE_TIMER", true);
const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {
return s;
const trivabble = window.trivabble = {l10n: _};
- function format(s, v1, v2) {
- return s.replace("{0}", v1).replace("{1}", v2);
+ function format(s, v1, v2, v3, v4) {
+ return s.replace("{0}", v1).replace("{1}", v2).replace("{2}", v3).replace("{3}", v4);
}
let board;
myConfirm(
_("Are you sure you want to put all the tiles back in the bag (in order to play another game)?"),
function () {
+ localStorage.timerGlobal = localStorage.timerTurn = 0;
sendCmds([{cmd: "resetGame"}]);
}
);
}
}
+ function timerString(delta) {
+ let d = Math.floor(delta / (60 * 60 * 24));
+ let h = Math.floor((delta % (60 * 60 * 24)) / (60 * 60));
+ let m = Math.floor((delta % (60 * 60)) / 60);
+ let s = Math.floor(delta % 60);
+ return format(_("{0}d {1}h {2}m {3}s"), d, h, m, s);
+ }
+
+ function initTimer() {
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerTurn")) {
+ localStorage.timerTurn = 0;
+ }
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerGlobal")) {
+ localStorage.timerGlobal = 0;
+ }
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) {
+ localStorage.timerEnable = Conf.ENABLE_TIMER;
+ }
+ if (localStorage.timerEnable) {
+ activateTimer();
+ } else {
+ desactivateTimer();
+ }
+ }
+
+ function activateTimer() {
+ document.getElementById("timer").style.display = "block";
+ localStorage.timer = setInterval(function() {
+ document.getElementById("timer-turn").innerHTML = timerString(++localStorage.timerTurn)
+ document.getElementById("timer-global").innerHTML = timerString(++localStorage.timerGlobal);
+ }, 1000);
+ }
+
+ function desactivateTimer() {
+ document.getElementById("timer").style.display = "none";
+ if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) {
+ clearInterval(localStorage.timer);
+ delete(localStorage.timer);
+ }
+ }
+
+
function repromptName(f) {
if (localStorage.trivabblePlayerName && localStorage.trivabblePlayerName.trim()) {
f();
_("It seems your did not give your name. You need to do it for the game to run properly."),
function (name) {
if (name && name.trim()) {
- localStorage.trivabblePlayerName = name.trim();
+ localStorage.trivabblePlayerName = name1111111111111.trim();
}
repromptName(f);
initChat();
initGame();
initSound();
+ initTimer();
};
trivabble.l10nError = trivabble.run;