Skip to content

Commit

Permalink
Spectator bugfixes (#188)
Browse files Browse the repository at this point in the history
* fix spectator bugs

* fix import spacing

* remove log

* fix redundant parens

* remove comma
  • Loading branch information
AlecM33 committed Mar 6, 2024
1 parent 613a16e commit 7e71bbb
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
3 changes: 2 additions & 1 deletion client/src/config/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const IN_PROGRESS_EVENTS = function () {
return [
EVENT_IDS.KILL_PLAYER,
EVENT_IDS.REVEAL_PLAYER,
EVENT_IDS.ADD_SPECTATOR
EVENT_IDS.ADD_SPECTATOR,
EVENT_IDS.KICK_PERSON
];
};
32 changes: 32 additions & 0 deletions client/src/modules/game_state/states/InProgress.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ export class InProgress {
break;
case USER_TYPES.MODERATOR:
document.getElementById('transfer-mod-prompt').innerHTML = HTMLFragments.TRANSFER_MOD_MODAL;
document.getElementById('player-options-prompt').innerHTML = HTMLFragments.PLAYER_OPTIONS_MODAL;
this.container.innerHTML = HTMLFragments.MODERATOR_GAME_VIEW;
this.renderModeratorView();
break;
case USER_TYPES.TEMPORARY_MODERATOR:
document.getElementById('transfer-mod-prompt').innerHTML = HTMLFragments.TRANSFER_MOD_MODAL;
document.getElementById('player-options-prompt').innerHTML = HTMLFragments.PLAYER_OPTIONS_MODAL;
this.container.innerHTML = HTMLFragments.TEMP_MOD_GAME_VIEW;
this.renderTempModView();
break;
Expand Down Expand Up @@ -257,6 +259,14 @@ export class InProgress {
}
});

this.socket.on(EVENT_IDS.KICK_PERSON, (kickedId, gameIsStartable) => {
if (kickedId === this.stateBucket.currentGameState.client.id) {
window.location = '/?message=' + encodeURIComponent('You were kicked by the moderator.');
} else {
this.handleSpectatorExiting(kickedId);
}
});

if (this.stateBucket.currentGameState.timerParams) {
if (this.stateBucket.timerWorker) {
this.stateBucket.timerWorker.terminate();
Expand Down Expand Up @@ -390,6 +400,28 @@ export class InProgress {
}
}

handleSpectatorExiting (id) {
const index = this.stateBucket.currentGameState.people.findIndex(person => person.id === id);
if (index >= 0) {
this.stateBucket.currentGameState.people
.splice(index, 1);
}
SharedStateUtil.setNumberOfSpectators(
this.stateBucket.currentGameState.people.filter(p => p.userType === USER_TYPES.SPECTATOR).length,
document.getElementById('spectator-count')
);
if (this.stateBucket.currentGameState.client.userType === USER_TYPES.MODERATOR
|| this.stateBucket.currentGameState.client.userType === USER_TYPES.TEMPORARY_MODERATOR) {
toast(
'Spectator kicked.',
'success',
true,
true,
'short'
);
}
}

displayAvailableModerators () {
document.getElementById('transfer-mod-modal-content').innerText = '';
document.querySelectorAll('.potential-moderator').forEach((el) => {
Expand Down
7 changes: 2 additions & 5 deletions client/src/modules/game_state/states/Lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,8 @@ export class Lobby {
document.getElementById('spectator-count')
);
this.populatePlayers();
if ((
this.stateBucket.currentGameState.client.userType === USER_TYPES.MODERATOR
|| this.stateBucket.currentGameState.client.userType === USER_TYPES.TEMPORARY_MODERATOR
)
) {
if (this.stateBucket.currentGameState.client.userType === USER_TYPES.MODERATOR
|| this.stateBucket.currentGameState.client.userType === USER_TYPES.TEMPORARY_MODERATOR) {
toast(
event === EVENT_IDS.LEAVE_ROOM ? 'A player left.' : 'Player kicked.',
event === EVENT_IDS.LEAVE_ROOM ? 'warning' : 'success',
Expand Down

0 comments on commit 7e71bbb

Please sign in to comment.