remove static langName

This commit is contained in:
Laurent Mazet 2020-05-06 23:28:09 +02:00
parent 333a537ce7
commit fe7da515b7
7 changed files with 61 additions and 28 deletions

View File

@ -42,10 +42,7 @@
<label>
<span data-l10n="text-content">Board language: </span>
<select id="board-lang">
<option value="en">English</option>
<option value="fr">French</option>
<option value="de">German</option>
<option value="es">Spanish</option>
</select>
</label>
</div>

View File

@ -29,8 +29,6 @@
const VERSION = 202005011900;
const langName = {"de": "German", "en": "English", "es": "Spanish", "fr": "French"};
const Conf = window.TrivabbleConf || {};
function setConf(parameterName, defaultValue) {
@ -58,6 +56,7 @@
let board;
let rack;
const boardCells = [];
let langName;
let scoreOf;
let bag;
@ -871,6 +870,11 @@
set("boardLang", data.boardLang);
}
if (data.langName) {
langName = data.langName;
createLangBoardSelect(langName);
}
if (data.letterValues) {
scoreOf = data.letterValues;
}
@ -1518,19 +1522,29 @@
}
}
trivabble.run();
};
function createLangBoardSelect(langName) {
var newLangName = [];
for (const key in langName) {
newLangName.push({"key": key, "value": _(langName[key])});
}
newLangName = newLangName.sort((a, b) => (a.value > b.value) ? 1 : ((b.value > a.value) ? -1 : 0));
const select = document.getElementById("board-lang");
for (var i = 0; i < newLangName.length; i++) {
select.options[i] = new Option(newLangName[i].value, newLangName[i].key);
}
select.value = localStorage.trivabbleBoardLang;
trivabble.run();
};
const select = document.getElementById("board-lang");
for (var i = select.options.length - 1; i >=0; i--) {
select.remove(i);
}
for (var i = 0; i < newLangName.length; i++) {
select.add(new Option(newLangName[i].value, newLangName[i].key));
}
select.value = localStorage.trivabbleBoardLang;
}
function langSelectionChange(e) {
localStorage.trivabbleLang = e.target.value;

View File

@ -24,6 +24,9 @@
module.exports = {
code: "de",
name: "German",
/*
102 jetons:
- 0 point: Joker *2

View File

@ -23,6 +23,10 @@
*/
module.exports = {
code: "en",
name: "English",
/*
100 jetons:
- 0 point: Blank *2

View File

@ -23,6 +23,10 @@
*/
module.exports = {
code: "es",
name: "Spanish",
/*
100 jetons:
- 0 point: Comodin *2

View File

@ -23,16 +23,20 @@
*/
module.exports = {
/*
102 jetons
- 0 point : Joker *2
- 1 point : E *15, A *9, I *8, N *6, O *6, R *6, S *6, T *6, U *6, L *5
- 2 points : D *3, M *3, G *2
- 3 points : B *2, C *2, P *2
- 4 points : F *2, H *2, V *2
- 8 points : J *1, Q *1
- 10 points : K *1, W *1, X *1, Y *1, Z *1
*/
code: "fr",
name: "French",
/*
102 jetons
- 0 point : Joker *2
- 1 point : E *15, A *9, I *8, N *6, O *6, R *6, S *6, T *6, U *6, L *5
- 2 points : D *3, M *3, G *2
- 3 points : B *2, C *2, P *2
- 4 points : F *2, H *2, V *2
- 8 points : J *1, Q *1
- 10 points : K *1, W *1, X *1, Y *1, Z *1
*/
bag: [
" ", " ", // Jokers

View File

@ -58,12 +58,14 @@ const REQUEST_TYPE_WEBSOCKET = 3;
/* eslint-disable quote-props */
/* Manage multi language board */
const boardPieces = {
"de": require ("./lang/de.js"),
"en": require ("./lang/en.js"),
"es": require ("./lang/es.js"),
"fr": require ("./lang/fr.js")
};
var boardPieces = {};
var langName = {};
var langFiles = fs.readdirSync("./lang");
for (var i in langFiles) {
const data = require("./lang/" + langFiles[i]);
boardPieces[data.code] = data;
langName[data.code] = data.name;
}
const defaultLang = "fr";
/* eslint-enable quote-props */
@ -213,6 +215,7 @@ function newBoard() {
Game.prototype.init = function (lang) {
this.board = newBoard();
this.lang = lang || defaultLang;
this.langName = langName;
this.bag = boardPieces[this.lang].bag.slice();
this.letterValues = boardPieces[this.lang].letterValues;
this.racks = {};
@ -227,6 +230,7 @@ Game.prototype.toJSON = function () {
return {
board: this.board,
lang: this.lang,
langName: this.langName,
bag: this.bag,
racks: this.racks,
scores: this.scores,
@ -239,6 +243,7 @@ Game.fromJSON = function (obj) {
const game = new Game();
game.board = obj.board || newBoard();
game.lang = obj.lang || defaultLang;
game.langName = obj.langName;
game.bag = boardPieces[game.lang].bag.slice();
game.letterValues = boardPieces[game.lang].letterValues;
game.racks = obj.racks || {};
@ -475,6 +480,7 @@ function handleCommand(cmdNumber, message, response) {
gameNumber: gameNumber,
playerName: playerName,
boardLang: game.lang,
langName: langName,
currentPlayer: game.currentPlayer,
rack: game.getPlayerRack(playerName),
board: game.board,
@ -704,6 +710,7 @@ function handleCommands(message, responseAndType) {
currentPlayer: game.currentPlayer,
gameNumber: gameNumber,
boardLang: game.lang,
langName: langName,
letterValues: game.letterValues,
rack: game.getPlayerRack(message.playerName),
board: game.board,