From: Laurent Mazet Date: Sun, 18 Oct 2020 17:21:36 +0000 (+0200) Subject: Merge branch 'develop' into automatic_scoring X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=faf78ca9327338022826392f080327062b5a38de;p=trivabble.git Merge branch 'develop' into automatic_scoring --- faf78ca9327338022826392f080327062b5a38de diff --cc public/index.html index 28c3216,c56bccf..514f39c --- a/public/index.html +++ b/public/index.html @@@ -78,13 -117,25 +117,26 @@@ ParticipantRackScoreTurn Waiting for other participants… -

Click on someone's score to change it.

-

Who's turn? Click on the Turn button!

- - - - - +
+ + + ++ +
+
+

Tip!

+
+
+ + + + + +
+ +
+
+ diff --cc public/trivabble.js index b181f41,30dce5d..2100d7d --- a/public/trivabble.js +++ b/public/trivabble.js @@@ -1719,69 -1822,12 +1822,74 @@@ } } + function getRowIndex(tr) { + // tr.rowIndex is -1 on WebKit-based browsers in Debian Jessie, hence this function + return [].indexOf.call(tr.parentNode.rows, tr); + } + + function scoreWords() { + let totalScore = 0; + + const newWords = searchNewWords(); + for (const k of Object.keys(newWords)) { + let wordFactor = 1; + let wordScore = 0; + + const word = newWords[k]; + for (let l = 0; l < word.letters.length; l++) { + const index = ((word.row + (l * word.incRow)) * 15) + word.col + (l * word.incCol); + + /* Letter score */ + const tilePlaceholder = boardCells[index].getElementsByClassName("tile-placeholder")[0]; + const tile = tilePlaceholder.getElementsByClassName("tile")[0]; + const letterScore = tile.lastChild.textContent; + let letterFactor = 1; + + /* Is a freshly played letter? */ + if (currentTilePlayed[index] === word.letters[l]) { + + /* Letter factor */ + if (boardCells[index].classList.contains("special-cell-doubleLetter")) { + letterFactor = 2; + } else if (boardCells[index].classList.contains("special-cell-tripleLetter")) { + letterFactor = 3; + } + + /* Word factor */ + if (boardCells[index].classList.contains("special-cell-doubleWord")) { + wordFactor *= 2; + } else if (boardCells[index].classList.contains("special-cell-tripleWord")) { + wordFactor *= 3; + } + + } + + wordScore += letterScore * letterFactor; + } + + totalScore += wordScore * wordFactor; + } + + /* Check for trivabble */ + if (Object.keys(currentTilePlayed).length === 7) { + totalScore += 50; + } + + /* Confirm score */ + myConfirm( + _("Do you want to add score to active player?") + " " + totalScore, + function () { + const scoreCell = tablePlayers[currentPlayer].childNodes[2].childNodes[0]; + sendCmds([{ + cmd: "score", + player: currentPlayer, + score: parseInt(scoreCell.textContent) + totalScore + }]); + } + ); + } + - function triggerLaser(cell) { + function triggerFlashLight(cell) { if (!cell) { return; } @@@ -2119,11 -2191,15 +2253,16 @@@ document.getElementById("clear-rack").onclick = clearRack; document.getElementById("show-rack").onclick = showRack; document.getElementById("check-spelling").onclick = checkSpellingClicked; - document.getElementById("score-words").onclick = scoreWords; - helpClear.onclick = clearGame; - document.getElementById("btn-settings").onclick = showSettings; - document.getElementById("btn-settings-close").onclick = showSettings; + document.getElementById("btn-settings-close").onclick = hideSettings; + document.getElementById("next-help-msg").onclick = nextHelpMessage; + document.getElementById("disable-spell-checker").onclick = toggleSpellChecker; ++ document.getElementById("score-words").onclick = scoreWords; + window.addEventListener("keydown", function (e) { + if (e.key === "Escape") { + document.querySelector(".modal").classList.remove("show-modal"); + } + }); } function initGame() {