From e96d58ab407e704c1cf33b3309a925f83aabb02c Mon Sep 17 00:00:00 2001 From: Aotumuri Date: Wed, 1 Oct 2025 03:10:17 +0900 Subject: [PATCH] Hide dead players from the leaderboard (#2114) ## Description: Update leaderboard logic to exclude dead players. Players (including myPlayer) are only shown if alive. https://github.com/user-attachments/assets/0a5c0422-4844-41ae-ae0b-3d7d8473491c ## Please complete the following: - [x] I have added screenshots for all UI updates - [x] I process any text displayed to the user through translateText() and I've added it to the en.json file - [x] I have added relevant tests to the test directory - [x] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: aotumuri --- src/client/graphics/layers/Leaderboard.ts | 39 +++++++++++------------ 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/src/client/graphics/layers/Leaderboard.ts b/src/client/graphics/layers/Leaderboard.ts index 513aa2711..30e0539d5 100644 --- a/src/client/graphics/layers/Leaderboard.ts +++ b/src/client/graphics/layers/Leaderboard.ts @@ -99,13 +99,13 @@ export class Leaderboard extends LitElement implements Layer { const numTilesWithoutFallout = this.game.numLandTiles() - this.game.numTilesWithFallout(); - const playersToShow = this.showTopFive ? sorted.slice(0, 5) : sorted; + const alivePlayers = sorted.filter((player) => player.isAlive()); + const playersToShow = this.showTopFive + ? alivePlayers.slice(0, 5) + : alivePlayers; this.players = playersToShow.map((player, index) => { - let troops = player.troops() / 10; - if (!player.isAlive()) { - troops = 0; - } + const troops = player.troops() / 10; return { name: player.displayName(), position: index + 1, @@ -131,22 +131,21 @@ export class Leaderboard extends LitElement implements Layer { } } - let myPlayerTroops = myPlayer.troops() / 10; - if (!myPlayer.isAlive()) { - myPlayerTroops = 0; + if (myPlayer.isAlive()) { + const myPlayerTroops = myPlayer.troops() / 10; + this.players.pop(); + this.players.push({ + name: myPlayer.displayName(), + position: place, + score: formatPercentage( + myPlayer.numTilesOwned() / this.game.numLandTiles(), + ), + gold: renderNumber(myPlayer.gold()), + troops: renderNumber(myPlayerTroops), + isMyPlayer: true, + player: myPlayer, + }); } - this.players.pop(); - this.players.push({ - name: myPlayer.displayName(), - position: place, - score: formatPercentage( - myPlayer.numTilesOwned() / this.game.numLandTiles(), - ), - gold: renderNumber(myPlayer.gold()), - troops: renderNumber(myPlayerTroops), - isMyPlayer: true, - player: myPlayer, - }); } this.requestUpdate();