Skip to content

Commit 27d6065

Browse files
committed
Fix gameover scoreboard not displaying score and rank correctly
1 parent 7e1c9fe commit 27d6065

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

internal/frontend/lobby.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ function getCachedPlayer(playerID) {
999999
}
10001000

10011001
for (let i = 0; i < cachedPlayers.length; i++) {
1002-
let player = cachedPlayers[i];
1002+
const player = cachedPlayers[i];
10031003
if (player.id === playerID) {
10041004
return player;
10051005
}
@@ -1073,7 +1073,7 @@ function handleReadyEvent(ready) {
10731073

10741074
//These two are required for displaying the "game over / win / tie" message.
10751075
let countOfRankOnePlayers = 0;
1076-
let isSelfRankOne = false;
1076+
let selfPlayer;
10771077
for (let i = 0; i < players.length; i++) {
10781078
const player = players[i];
10791079
if (!player.connected || player.state === "spectating") {
@@ -1082,13 +1082,12 @@ function handleReadyEvent(ready) {
10821082

10831083
if (player.rank === 1) {
10841084
countOfRankOnePlayers++;
1085-
if (player.id === ownID) {
1086-
isSelfRankOne = true;
1087-
}
1085+
}
1086+
if (player.id === ownID) {
1087+
selfPlayer = player;
10881088
}
10891089

1090-
//Even if we don't want to show a player-entry, we still need to iterate
1091-
//over all players to handle the dialog titles.
1090+
// We only display the first 5 players on the scoreboard.
10921091
if (player.rank <= 5) {
10931092
const newScoreboardEntry = document.createElement("div");
10941093
newScoreboardEntry.classList.add("gameover-scoreboard-entry");
@@ -1115,14 +1114,15 @@ function handleReadyEvent(ready) {
11151114
}
11161115
}
11171116

1118-
if (isSelfRankOne) {
1117+
if (selfPlayer.rank === 1) {
11191118
if (countOfRankOnePlayers >= 2) {
11201119
gameOverDialogTitle.innerText = `{{.Translation.Get "game-over-tie"}}`;
11211120
} else {
11221121
gameOverDialogTitle.innerText = `{{.Translation.Get "game-over-win"}}`;
11231122
}
11241123
} else {
1125-
gameOverDialogTitle.innerText = `{{.Translation.Get "game-over"}}`.format(player.rank, player.score);
1124+
gameOverDialogTitle.innerText = `{{.Translation.Get "game-over"}}`
1125+
.format(selfPlayer.rank, selfPlayer.score);
11261126
}
11271127
} else if (ready.gameState === "ongoing") {
11281128
// Lack of wordHints implies that word has been chosen yet.

0 commit comments

Comments
 (0)