mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
Spectator bugfixes (#188)
* fix spectator bugs * fix import spacing * remove log * fix redundant parens * remove comma
This commit is contained in:
@@ -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
|
||||
];
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
@@ -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();
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user