From cc28f3683e1ab00d04c593009643382d5f7c2b7a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Jakse?= Date: Mon, 5 Oct 2020 23:46:47 +0200 Subject: [PATCH] Fix the empty rack button --- public/trivabble.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/public/trivabble.js b/public/trivabble.js index ae18510..4441ee5 100644 --- a/public/trivabble.js +++ b/public/trivabble.js @@ -1597,15 +1597,21 @@ myConfirm( _("Are you sure you want to put all your tiles back in the bag?"), function () { - sendCmds([ - {cmd: "moveLetter", from: "rack", indexFrom: 0, to: "bag", indexTo: -1}, - {cmd: "moveLetter", from: "rack", indexFrom: 1, to: "bag", indexTo: -1}, - {cmd: "moveLetter", from: "rack", indexFrom: 2, to: "bag", indexTo: -1}, - {cmd: "moveLetter", from: "rack", indexFrom: 3, to: "bag", indexTo: -1}, - {cmd: "moveLetter", from: "rack", indexFrom: 4, to: "bag", indexTo: -1}, - {cmd: "moveLetter", from: "rack", indexFrom: 5, to: "bag", indexTo: -1}, - {cmd: "moveLetter", from: "rack", indexFrom: 6, to: "bag", indexTo: -1} - ]); + const cmds = []; + + for (let i = 0; i < playerLetters.length; i++) { + if (playerLetters[i].getElementsByClassName("tile")[0]) { + cmds.push({ + cmd: "moveLetter", + from: "rack", + indexFrom: i, + to: "bag", + indexTo: -1 + }); + } + } + + sendCmds(cmds); setRack(""); } ); -- 2.30.2