keep idle/dc players displayed
This commit is contained in:
parent
1727705189
commit
3ff375dbb4
4 changed files with 38 additions and 12 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
35
game/game.js
35
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,7 @@ export default {
|
|||
addSocket,
|
||||
handleInput,
|
||||
getAllGames: GameCommon.getAllGames,
|
||||
getRelevantPlayers: GameCommon.getRelevantPlayers,
|
||||
getActivePlayers: GameCommon.getActivePlayers,
|
||||
getFinishedTileCount: GameCommon.getFinishedTileCount,
|
||||
getImageUrl: GameCommon.getImageUrl,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue