refine spectator count

This commit is contained in:
AlecM33
2022-12-26 14:31:50 -05:00
parent da5b531952
commit 1c156b0a55
4 changed files with 28 additions and 43 deletions

View File

@@ -46,6 +46,11 @@ export class Lobby {
const playerCount = this.container.querySelector('#game-player-count');
playerCount.innerText = this.stateBucket.currentGameState.gameSize + ' Players';
setNumberOfSpectators(
this.stateBucket.currentGameState.spectators.length,
this.container.querySelector('#spectator-count')
)
const gameCode = this.container.querySelector('#game-code');
gameCode.innerHTML = 'Or enter this code on the homepage: <span>' +
this.stateBucket.currentGameState.accessCode + '</span>';
@@ -91,6 +96,10 @@ export class Lobby {
this.socket.on(globals.EVENT_IDS.NEW_SPECTATOR, (spectator) => {
this.stateBucket.currentGameState.spectators.push(spectator);
setNumberOfSpectators(
this.stateBucket.currentGameState.spectators.length,
document.getElementById('spectator-count')
);
});
// this.socket.on(globals.EVENT_IDS.PLAYER_LEFT, (player) => {
@@ -127,6 +136,12 @@ export class Lobby {
}
}
function setNumberOfSpectators(number, el) {
el.innerText = '+ ' + (number === 1
? number + ' Spectator'
: number + ' Spectators');
}
function enableOrDisableStartButton (gameState, buttonContainer, handler) {
if (gameState.isFull) {
buttonContainer.querySelector('#start-game-button').addEventListener('click', handler);