keep idle/dc players displayed

This commit is contained in:
Zutatensuppe 2020-12-21 02:29:14 +01:00
parent 1727705189
commit 3ff375dbb4
4 changed files with 38 additions and 12 deletions

View file

@ -61,10 +61,20 @@ function playerExists(gameId, playerId) {
return !!GAMES[gameId].players[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) { function getActivePlayers(gameId) {
const ts = Util.timestamp() const ts = Util.timestamp()
const minTs = ts - 30000 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) { function addPlayer(gameId, playerId) {
@ -606,6 +616,7 @@ export default {
newGame, newGame,
exists, exists,
playerExists, playerExists,
getRelevantPlayers,
getActivePlayers, getActivePlayers,
addPlayer, addPlayer,
socketExists, socketExists,

View file

@ -2,6 +2,7 @@ import GameCommon from './../common/GameCommon.js'
export default { export default {
newGame: GameCommon.newGame, newGame: GameCommon.newGame,
getRelevantPlayers: GameCommon.getRelevantPlayers,
getActivePlayers: GameCommon.getActivePlayers, getActivePlayers: GameCommon.getActivePlayers,
handleInput: GameCommon.handleInput, handleInput: GameCommon.handleInput,
getPlayerBgColor: GameCommon.getPlayerBgColor, getPlayerBgColor: GameCommon.getPlayerBgColor,

View file

@ -142,20 +142,33 @@ function addMenuToDom(gameId) {
const scoresListEl = document.createElement('table') const scoresListEl = document.createElement('table')
const updateScores = () => { const updateScores = () => {
const activePlayers = Game.getActivePlayers(gameId) const ts = Util.timestamp()
const scores = activePlayers.map(p => ({ const minTs = ts - 30000
name: p.name,
points: p.points, const players = Game.getRelevantPlayers(gameId)
color: p.color, const actives = players.filter(player => player.ts >= minTs)
})) const nonActives = players.filter(player => player.ts < minTs)
scores.sort((a, b) => b.points - a.points)
actives.sort((a, b) => b.points - a.points)
nonActives.sort((a, b) => b.points - a.points)
scoresListEl.innerHTML = '' scoresListEl.innerHTML = ''
for (let score of scores) { for (let player of actives) {
const r = row( const r = row(
document.createTextNode(score.name), document.createTextNode('⚡'),
document.createTextNode(score.points) 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) scoresListEl.appendChild(r)
} }
} }

View file

@ -86,6 +86,7 @@ export default {
addSocket, addSocket,
handleInput, handleInput,
getAllGames: GameCommon.getAllGames, getAllGames: GameCommon.getAllGames,
getRelevantPlayers: GameCommon.getRelevantPlayers,
getActivePlayers: GameCommon.getActivePlayers, getActivePlayers: GameCommon.getActivePlayers,
getFinishedTileCount: GameCommon.getFinishedTileCount, getFinishedTileCount: GameCommon.getFinishedTileCount,
getImageUrl: GameCommon.getImageUrl, getImageUrl: GameCommon.getImageUrl,