Broadcast a message when the board lang changes

This commit is contained in:
Raphaël Jakse 2020-05-16 10:59:54 +02:00
parent 3a20d898ab
commit 1aa3835a76
5 changed files with 63 additions and 18 deletions

View File

@ -172,3 +172,8 @@ msgstr "Allemand"
msgid "Spanish"
msgstr "Espagnol"
msgid "You changed the language of the board to {0}"
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}"

View File

@ -175,3 +175,8 @@ msgstr ""
msgid "Spanish"
msgstr ""
msgid "You changed the language of the board to {0}"
msgstr ""
msgid "{0} changed the language of the board to {1}"
msgstr ""

File diff suppressed because one or more lines are too long

View File

@ -49,8 +49,8 @@
const trivabble = window.trivabble = {l10n: _};
function format(s, v) {
return s.replace("{0}", v);
function format(s, v1, v2) {
return s.replace("{0}", v1).replace("{1}", v2);
}
let board;
@ -647,24 +647,42 @@
return msgDom;
}
function infoMessage(info) {
const content = document.createElement("div");
content.appendChild(document.createElement("span"));
content.lastChild.className = "info";
content.lastChild.textContent = info;
chatMessage("", content);
return content;
}
function handleChatMessage(msg) {
if (msg.specialMsg) {
if (msg.specialMsg.type === "rack") {
const content = document.createElement("div");
content.appendChild(document.createElement("span"));
content.lastChild.className = "info";
content.lastChild.textContent = format(_("{0} shows their rack:"), msg.sender);
switch (msg.specialMsg.type) {
case "rack": {
const content = infoMessage(format(_("{0} shows their rack:"), msg.sender));
const letters = document.createElement("div");
letters.className = "tile-list";
const letters = document.createElement("div");
letters.className = "tile-list";
for (let i = 0; i < msg.specialMsg.rack.length; i++) {
letters.appendChild(makeLetter(msg.specialMsg.rack[i], false, true));
for (let i = 0; i < msg.specialMsg.rack.length; i++) {
letters.appendChild(makeLetter(msg.specialMsg.rack[i], false, true));
}
content.appendChild(letters);
return;
}
content.appendChild(letters);
chatMessage("", content);
return;
case "changeBoardLang": {
const newLang = boardLangSelect.querySelector("[value=" + msg.specialMsg.newBoardLang + "]").textContent;
infoMessage(
(msg.sender === localStorage.trivabblePlayerName)
? format(_("You changed the language of the board to {0}"), newLang)
: format(_("{0} changed the language of the board to {1}"), msg.sender, newLang)
);
return;
}
}
}
@ -1347,7 +1365,7 @@
function onChangeBoardLang() {
const code = document.getElementById("board-lang").value;
const lang = document.getElementById("board-lang").textContent;
const lang = boardLangSelect.selectedOptions[0].textContent;
myConfirm(
format(_("Are you sure you want to change board to '{0}'? This will put all the tiles back in the bag and start another game."), _(lang)),
@ -1355,7 +1373,7 @@
sendCmds([{cmd: "changeBoard", lang: code}]);
},
function () {
document.getElementById("board-lang").value = localStorage.trivabbleBoardLang;
boardLangSelect.value = localStorage.trivabbleBoardLang;
}
);
}

View File

@ -668,7 +668,24 @@ function handleCommand(cmdNumber, message, response) {
case "changeBoard": {
game.lang = cmd.lang || DEFAULT_BOARD_LANG;
game.reset();
reply(message, response, cmdNumber, {error: 0, boardLang: game.lang, letterValues: game.letterValues});
reply(message, response, cmdNumber, {
error: 0,
boardLang: game.lang,
letterValues: game.letterValues
});
game.pendingEvents.push({
msg: {
sender: playerName,
content: "I changed the language of the board to " + game.lang,
specialMsg: {
type: "changeBoardLang",
newBoardLang: game.lang
}
}
});
break;
}