<button data-l10n="text-content" id="join-game">Join adversaries</button>
<p id="p-name"> <span data-l10n="text-content">You are:</span> <span id="name" data-l10n="text-content">(name to give)</span><br /><button class="minibutton" id="change-name" data-l10n="text-content">Change</button></p>
<button id="clear-game" data-l10n="text-content">Put back all the tiles in the bag</button>
- <p><span data-l10n="text-content">Board language: </span><span id="board-lang" data-l10n="text-content">(pending)</span></p>
- <p>
+ <p id="p-name"><span data-l10n="text-content">Board language:</span> <span id="board-lang" data-l10n="text-content">(pending)</span><br />
<button data-l10n="text-content" id="change-de-board">German</button>
<button data-l10n="text-content" id="change-en-board">English</button>
<button data-l10n="text-content" id="change-fr-board">French</button>
const VERSION = 202005011900;
+ const langName = {"de": "German", "en": "English", "es": "Spanish", "fr": "French"};
+
const Conf = window.TrivabbleConf || {};
function setConf(parameterName, defaultValue) {
document.getElementById("number").textContent = localStorage.trivabbleGameNumber = value;
break;
case "boardLang":
- document.getElementById("board-lang").textContent = localStorage.trivabbleBoardLang = value;
+ document.getElementById("board-lang").textContent =
+ langName[localStorage.trivabbleBoardLang = value];
break;
}
}
function changeBoardLang(lang) {
myConfirm(
- _("Are you sure you want to change board to '" + lang + "'? This will put all the tiles back in the bag an start another game."),
+ _("Are you sure you want to change board to '" + langName[lang] + "'? This will put all the tiles back in the bag an start another game."),
function () {
sendCmds([{cmd: "changeBoard", lang: lang}]);
}
document.getElementById("board-lang").textContent = localStorage.trivabbleBoardLang;
}
- startGame(localStorage.trivabbleGameNumber);
+ startGame(localStorage.trivabbleGameNumber, localStorage.trivabbleBoardLang);
}
function initLang() {
"es": require ("./es.js"),
"fr": require ("./fr.js")
};
-var boardLang = "fr";
+const defaultLang = "fr";
/* eslint-enable quote-props */
-var bag = boardPieces[boardLang].bag;
-var values = boardPieces[boardLang].values;
-
const games = {};
let saveTimeout = null;
}
function Game() {
- this.letterValues = values;
this.init();
this.listeningPlayers = [];
this.pendingEvents = [];
return res;
}
-Game.prototype.init = function () {
+Game.prototype.init = function (lang) {
this.board = newBoard();
- this.bag = bag.slice();
+ this.lang = lang || defaultLang;
+ this.bag = boardPieces[this.lang].bag.slice();
+ this.values = boardPieces[this.lang].values;
this.racks = {};
this.scores = {};
this.lastUpdated = new Date();
Game.prototype.toJSON = function () {
return {
board: this.board,
+ lang: this.lang,
bag: this.bag,
racks: this.racks,
scores: this.scores,
Game.fromJSON = function (obj) {
const game = new Game();
game.board = obj.board || newBoard();
- game.bag = obj.bag || bag.slice();
+ game.lang = obj.lang || defaultLang;
+ game.bag = boardPieces[game.lang].bag.slice();
+ game.values = boardPieces[game.lang].values;
game.racks = obj.racks || {};
game.scores = obj.scores || {};
game.lastUpdated = obj.lastUpdated ? new Date(obj.lastUpdated) : new Date();
};
Game.prototype.reset = function (player) {
- this.init();
+ this.init(this.lang);
this.pendingEvents.push({
player: player,
action: "reset",
error: 0,
gameNumber: gameNumber,
playerName: playerName,
- boardLang: boardLang,
+ boardLang: game.lang,
currentPlayer: game.currentPlayer,
rack: game.getPlayerRack(playerName),
board: game.board,
remainingLetters: game.bag.length,
- letterValues: values,
+ letterValues: game.values,
version: VERSION
});
break;
case "hello": {
game.playerJoined(playerName);
- reply(message, response, cmdNumber, {error: 0, version: VERSION});
+ reply(message, response, cmdNumber, {error: 0, boardLang: game.lang, version: VERSION});
break;
}
}
case "changeBoard": {
- boardLang = cmd.lang;
- bag = boardPieces[boardLang].bag;
- values = boardPieces[boardLang].values;
+ game.lang = cmd.lang || defaultLang;
game.reset();
- reply(message, response, cmdNumber, {error: 0});
+ reply(message, response, cmdNumber, {error: 0, boardLang: game.lang});
break;
}
playerName: message.playerName,
currentPlayer: game.currentPlayer,
gameNumber: gameNumber,
- boardLang: boardLang,
- letterValues: game.letterValues,
+ boardLang: game.lang,
+ letterValues: game.values,
rack: game.getPlayerRack(message.playerName),
board: game.board,
remainingLetters: game.bag.length,