Skip to content

Commit

Permalink
feat: Add method to show player disconnected in GameUI
Browse files Browse the repository at this point in the history
- Added the `showPlayerDisconnected` method to the `GameUI` class in `game.js`.
- This method is responsible for displaying a disconnected player in the UI by applying a grayscale filter to their avatar image.
- The method takes the player ID as a parameter and retrieves the corresponding player element and avatar image.
- This enhancement improves the visual representation of disconnected players in the game UI.
  • Loading branch information
TKanX committed Sep 3, 2024
1 parent b6fc39d commit 979357e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions public/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,17 @@ class GameUI {
playerAvatar.style.borderColor = rankColor[rank - 1] || "blue";
}

/**
* Show player disconnected.
* @param {string} playerId - The player ID.
*/
showPlayerDisconnected(playerId) {
const playerElement = document.getElementById(`game-player-${playerId}`);
const playerAvatar = playerElement.querySelector("img");

playerAvatar.style.filter = "grayscale(100%)";
}

/**
* Clear player rank.
*/
Expand Down Expand Up @@ -1809,6 +1820,10 @@ class Game {
this.ui.showPlayerRank(playerId, rank);
});

this.network.addListener("game-client:disconnected", (data) => {
this.ui.showPlayerDisconnected(data.player);
});

this.network.addListener("game:end", (data) => {
const reason = data.reason;
const rankedPlayers = data.rankedPlayers;
Expand Down

0 comments on commit 979357e

Please sign in to comment.