diff --git a/common/GameCommon.js b/common/GameCommon.js index 197143d..b2d9e7a 100644 --- a/common/GameCommon.js +++ b/common/GameCommon.js @@ -61,10 +61,20 @@ function playerExists(gameId, playerId) { return !!GAMES[gameId].players[playerId] } +function getRelevantPlayers(gameId) { + const ts = Util.timestamp() + const minTs = ts - 30000 + return getAllPlayers(gameId).filter(player => { + return player.ts >= minTs || player.points > 0 + }) +} + function getActivePlayers(gameId) { const ts = Util.timestamp() const minTs = ts - 30000 - return getAllPlayers(gameId).filter(player => player.ts >= minTs) + return getAllPlayers(gameId).filter(player => { + return player.ts >= minTs + }) } function addPlayer(gameId, playerId) { @@ -606,6 +616,7 @@ export default { newGame, exists, playerExists, + getRelevantPlayers, getActivePlayers, addPlayer, socketExists, diff --git a/game/Game.js b/game/Game.js index 27f654e..8f7222d 100644 --- a/game/Game.js +++ b/game/Game.js @@ -2,6 +2,7 @@ import GameCommon from './../common/GameCommon.js' export default { newGame: GameCommon.newGame, + getRelevantPlayers: GameCommon.getRelevantPlayers, getActivePlayers: GameCommon.getActivePlayers, handleInput: GameCommon.handleInput, getPlayerBgColor: GameCommon.getPlayerBgColor, diff --git a/game/game.js b/game/game.js index 6edd9f2..0075a27 100644 --- a/game/game.js +++ b/game/game.js @@ -142,20 +142,33 @@ function addMenuToDom(gameId) { const scoresListEl = document.createElement('table') const updateScores = () => { - const activePlayers = Game.getActivePlayers(gameId) - const scores = activePlayers.map(p => ({ - name: p.name, - points: p.points, - color: p.color, - })) - scores.sort((a, b) => b.points - a.points) + const ts = Util.timestamp() + const minTs = ts - 30000 + + const players = Game.getRelevantPlayers(gameId) + const actives = players.filter(player => player.ts >= minTs) + const nonActives = players.filter(player => player.ts < minTs) + + actives.sort((a, b) => b.points - a.points) + nonActives.sort((a, b) => b.points - a.points) + scoresListEl.innerHTML = '' - for (let score of scores) { + for (let player of actives) { const r = row( - document.createTextNode(score.name), - document.createTextNode(score.points) + document.createTextNode('⚡'), + document.createTextNode(player.name), + document.createTextNode(player.points) ) - r.style.color = score.color + r.style.color = player.color + scoresListEl.appendChild(r) + } + for (let player of nonActives) { + const r = row( + document.createTextNode('💤'), + document.createTextNode(player.name), + document.createTextNode(player.points) + ) + r.style.color = player.color scoresListEl.appendChild(r) } } diff --git a/server/Game.js b/server/Game.js index 377ce43..b804b68 100644 --- a/server/Game.js +++ b/server/Game.js @@ -86,6 +86,7 @@ export default { addSocket, handleInput, getAllGames: GameCommon.getAllGames, + getRelevantPlayers: GameCommon.getRelevantPlayers, getActivePlayers: GameCommon.getActivePlayers, getFinishedTileCount: GameCommon.getFinishedTileCount, getImageUrl: GameCommon.getImageUrl,