mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
Merge pull request #156 from AlecM33/display-current-moderator
Display current moderator
This commit is contained in:
@@ -88,6 +88,10 @@ export const HTMLFragments = {
|
||||
<p>(Double-click here again to hide)</p>
|
||||
</div>
|
||||
<div id='game-people-container'>
|
||||
<div id="current-moderator" class="moderator">
|
||||
<div id="current-moderator-name"></div>
|
||||
<div id="current-moderator-type"></div>
|
||||
</div>
|
||||
<label id='players-alive-label'></label>
|
||||
<div id="spectator-count" tabindex="0"></div>
|
||||
<div id='game-player-list'></div>
|
||||
@@ -118,6 +122,10 @@ export const HTMLFragments = {
|
||||
</div>
|
||||
</div>
|
||||
<div id='game-people-container'>
|
||||
<div id="current-moderator" class="moderator">
|
||||
<div id="current-moderator-name"></div>
|
||||
<div id="current-moderator-type"></div>
|
||||
</div>
|
||||
<label id='players-alive-label'></label>
|
||||
<div id="spectator-count" tabindex="0"></div>
|
||||
<div id='game-player-list'></div>
|
||||
@@ -294,6 +302,10 @@ export const HTMLFragments = {
|
||||
</div>
|
||||
</div>
|
||||
<div id='game-people-container'>
|
||||
<div id="current-moderator" class="moderator">
|
||||
<div id="current-moderator-name"></div>
|
||||
<div id="current-moderator-type"></div>
|
||||
</div>
|
||||
<label id='players-alive-label'></label>
|
||||
<div id='game-player-list'></div>
|
||||
</div>`,
|
||||
|
||||
@@ -88,6 +88,9 @@ export class InProgress {
|
||||
}
|
||||
}
|
||||
renderPlayerRole(this.stateBucket.currentGameState);
|
||||
displayCurrentModerator(this.stateBucket.currentGameState.people
|
||||
.find((person) => person.userType === globals.USER_TYPES.MODERATOR
|
||||
|| person.userType === globals.USER_TYPES.TEMPORARY_MODERATOR));
|
||||
this.renderPlayersWithNoRoleInformationUnlessRevealed(false);
|
||||
}
|
||||
|
||||
@@ -162,38 +165,38 @@ export class InProgress {
|
||||
}
|
||||
|
||||
renderSpectatorView () {
|
||||
displayCurrentModerator(this.stateBucket.currentGameState.people
|
||||
.find((person) => person.userType === globals.USER_TYPES.MODERATOR
|
||||
|| person.userType === globals.USER_TYPES.TEMPORARY_MODERATOR));
|
||||
this.renderPlayersWithNoRoleInformationUnlessRevealed();
|
||||
}
|
||||
|
||||
setSocketHandlers () {
|
||||
this.socket.on(globals.EVENT_IDS.KILL_PLAYER, (id) => {
|
||||
const killedPerson = this.stateBucket.currentGameState.people.find((person) => person.id === id);
|
||||
if (killedPerson) {
|
||||
killedPerson.out = true;
|
||||
killedPerson.killed = true;
|
||||
killedPerson.userType = killedPerson.userType === globals.USER_TYPES.BOT
|
||||
? globals.USER_TYPES.KILLED_BOT
|
||||
: globals.USER_TYPES.KILLED_PLAYER;
|
||||
if (this.stateBucket.currentGameState.client.userType === globals.USER_TYPES.MODERATOR) {
|
||||
toast(killedPerson.name + ' killed.', 'success', true, true, 'medium');
|
||||
this.renderPlayersWithRoleAndAlignmentInfo(this.stateBucket.currentGameState.status === globals.STATUS.ENDED);
|
||||
this.socket.on(globals.EVENT_IDS.KILL_PLAYER, (killedPlayer) => {
|
||||
this.stateBucket.currentGameState.people = this.stateBucket.currentGameState.people
|
||||
.map(person => person.id === killedPlayer.id ? killedPlayer : person);
|
||||
if (this.stateBucket.currentGameState.client.userType === globals.USER_TYPES.MODERATOR) {
|
||||
toast(killedPlayer.name + ' killed.', 'success', true, true, 'medium');
|
||||
this.renderPlayersWithRoleAndAlignmentInfo(this.stateBucket.currentGameState.status === globals.STATUS.ENDED);
|
||||
} else {
|
||||
if (killedPlayer.id === this.stateBucket.currentGameState.client.id) {
|
||||
const clientUserType = document.getElementById('client-user-type');
|
||||
if (clientUserType) {
|
||||
clientUserType.innerText = globals.USER_TYPES.KILLED_PLAYER + ' \uD83D\uDC80';
|
||||
}
|
||||
this.updatePlayerCardToKilledState();
|
||||
toast('You have been killed!', 'warning', true, true, 'medium');
|
||||
} else {
|
||||
if (killedPerson.id === this.stateBucket.currentGameState.client.id) {
|
||||
const clientUserType = document.getElementById('client-user-type');
|
||||
if (clientUserType) {
|
||||
clientUserType.innerText = globals.USER_TYPES.KILLED_PLAYER + ' \uD83D\uDC80';
|
||||
}
|
||||
this.updatePlayerCardToKilledState();
|
||||
toast('You have been killed!', 'warning', true, true, 'medium');
|
||||
} else {
|
||||
toast(killedPerson.name + ' was killed!', 'warning', true, true, 'medium');
|
||||
}
|
||||
if (this.stateBucket.currentGameState.client.userType === globals.USER_TYPES.TEMPORARY_MODERATOR) {
|
||||
this.removePlayerListEventListeners(false);
|
||||
} else {
|
||||
this.renderPlayersWithNoRoleInformationUnlessRevealed(false);
|
||||
toast(killedPlayer.name + ' was killed!', 'warning', true, true, 'medium');
|
||||
if (killedPlayer.userType === globals.USER_TYPES.MODERATOR) {
|
||||
displayCurrentModerator(killedPlayer);
|
||||
}
|
||||
}
|
||||
if (this.stateBucket.currentGameState.client.userType === globals.USER_TYPES.TEMPORARY_MODERATOR) {
|
||||
this.removePlayerListEventListeners(false);
|
||||
} else {
|
||||
this.renderPlayersWithNoRoleInformationUnlessRevealed(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -478,6 +481,11 @@ function removeExistingPlayerElements (killPlayerHandlers, revealRoleHandlers) {
|
||||
});
|
||||
}
|
||||
|
||||
function displayCurrentModerator (moderator) {
|
||||
document.getElementById('current-moderator-name').innerText = moderator.name;
|
||||
document.getElementById('current-moderator-type').innerText = moderator.userType + globals.USER_TYPE_ICONS[moderator.userType];
|
||||
}
|
||||
|
||||
function createEndGamePromptComponent (socket, stateBucket) {
|
||||
if (document.querySelector('#game-control-prompt') === null) {
|
||||
const div = document.createElement('div');
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.lobby-player, #moderator, .spectator, .potential-moderator {
|
||||
.lobby-player, #moderator, .spectator, .potential-moderator, #current-moderator {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
@@ -14,7 +14,16 @@
|
||||
}
|
||||
|
||||
.moderator {
|
||||
border: 2px solid #c58f13;
|
||||
border: 2px solid #c58f13 !important;
|
||||
}
|
||||
|
||||
#current-moderator {
|
||||
border-radius: 5px;
|
||||
color: #d7d7d7;
|
||||
background-color: #16141e;
|
||||
width: fit-content;
|
||||
padding: 0 20px;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.potential-moderator {
|
||||
@@ -51,7 +60,7 @@
|
||||
border: 2px solid #21ba45;
|
||||
}
|
||||
|
||||
.lobby-player div:nth-child(2), .spectator div:nth-child(2), .potential-moderator div:nth-child(2) {
|
||||
.lobby-player div:nth-child(2), .spectator div:nth-child(2), .potential-moderator div:nth-child(2), #current-moderator div:nth-child(2) {
|
||||
color: #21ba45;
|
||||
}
|
||||
|
||||
@@ -648,7 +657,7 @@ canvas {
|
||||
justify-content: flex-end;
|
||||
}
|
||||
|
||||
.game-player-name, .lobby-player-name, .spectator-name, .potential-mod-name {
|
||||
.game-player-name, .lobby-player-name, .spectator-name, .potential-mod-name, #current-moderator-name {
|
||||
position: relative;
|
||||
min-width: 6em;
|
||||
max-width: 10em;
|
||||
|
||||
@@ -15,7 +15,7 @@ module.exports = {
|
||||
filename: "[name]-bundle.js",
|
||||
},
|
||||
plugins: [new CompressionPlugin({
|
||||
exclude: [/.map$/, /521-bundle.js$/]
|
||||
exclude: [/.map$/, /Timer_js-bundle.js$/]
|
||||
})],
|
||||
mode: "development",
|
||||
node: false,
|
||||
|
||||
@@ -96,7 +96,7 @@ const Events = [
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
const person = game.people.find((person) => person.id === socketArgs.personId);
|
||||
if (person) {
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, person.id);
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, person);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -189,9 +189,9 @@ const Events = [
|
||||
const moderatorSocket = vars.gameManager.namespace.sockets.get(moderator?.socketId);
|
||||
if (moderator && moderatorSocket) {
|
||||
vars.gameManager.namespace.to(moderator.socketId).emit(globals.EVENTS.SYNC_GAME_STATE);
|
||||
moderatorSocket.to(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, game.currentModeratorId);
|
||||
moderatorSocket.to(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, moderator);
|
||||
} else {
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, game.currentModeratorId);
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, moderator);
|
||||
}
|
||||
const previousModerator = vars.gameManager.findPersonByField(game, 'id', game.previousModeratorId);
|
||||
if (previousModerator && previousModerator.id !== moderator.id && vars.gameManager.namespace.sockets.get(previousModerator.socketId)) {
|
||||
|
||||
@@ -140,7 +140,7 @@ const ServerBootstrapper = {
|
||||
app.use('', router);
|
||||
|
||||
app.use('/dist', (req, res, next) => {
|
||||
if (req.url !== '/521-bundle.js') { // this is the bundled web worker, which was introducing compatibility problems with webpack compression.
|
||||
if (req.url.includes('.js.gz')) {
|
||||
res.set('Content-Encoding', 'gzip');
|
||||
}
|
||||
next();
|
||||
|
||||
@@ -393,6 +393,7 @@ async function addSpectator (game, name, logger, namespace, eventManager, instan
|
||||
name,
|
||||
globals.USER_TYPES.SPECTATOR
|
||||
);
|
||||
spectator.assigned = true;
|
||||
logger.trace('new spectator: ' + spectator.name);
|
||||
game.people.push(spectator);
|
||||
await refreshGame(game);
|
||||
|
||||
@@ -240,7 +240,14 @@ describe('game page', () => {
|
||||
mockGames.moderatorGame.accessCode,
|
||||
{ personId: 'pTtVXDJaxtXcrlbG8B43Wom67snoeO24RNEkO6eB2BaIftTdvpnfe1QR65DVj9A6I3VOoKZkYQW' }
|
||||
);
|
||||
mockSocket.eventHandlers.killPlayer('pTtVXDJaxtXcrlbG8B43Wom67snoeO24RNEkO6eB2BaIftTdvpnfe1QR65DVj9A6I3VOoKZkYQW');
|
||||
mockSocket.eventHandlers.killPlayer({
|
||||
id: 'pTtVXDJaxtXcrlbG8B43Wom67snoeO24RNEkO6eB2BaIftTdvpnfe1QR65DVj9A6I3VOoKZkYQW',
|
||||
userType: globals.USER_TYPES.KILLED_PLAYER,
|
||||
out: true,
|
||||
killed: true,
|
||||
revealed: false,
|
||||
alignment: 'good'
|
||||
});
|
||||
expect(document.querySelector('div[data-pointer="pTtVXDJaxtXcrlbG8B43Wom67snoeO24RNEkO6eB2BaIftTdvpnfe1QR65DVj9A6I3VOoKZkYQW"].game-player.killed')
|
||||
).not.toBeNull();
|
||||
});
|
||||
|
||||
@@ -263,7 +263,7 @@ describe('Events', () => {
|
||||
expect(namespace.in).toHaveBeenCalledWith(game.accessCode);
|
||||
expect(namespace.in().emit).toHaveBeenCalledWith(
|
||||
EVENT_IDS.KILL_PLAYER,
|
||||
'b'
|
||||
game.people.find(p => p.id === 'b')
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -433,7 +433,7 @@ describe('Events', () => {
|
||||
expect(namespace.to().emit).toHaveBeenCalledWith(EVENT_IDS.SYNC_GAME_STATE);
|
||||
// verify the "kill player" event is sent to everyone but the sender
|
||||
expect(mockSocket.to).toHaveBeenCalledWith(game.accessCode);
|
||||
expect(socketToObj.emit).toHaveBeenCalledWith(EVENT_IDS.KILL_PLAYER, 'a');
|
||||
expect(socketToObj.emit).toHaveBeenCalledWith(EVENT_IDS.KILL_PLAYER, game.people.find(p => p.id === 'a'));
|
||||
});
|
||||
it('should not communicate to the current or previous mod if their sockets are not found', async () => {
|
||||
game.currentModeratorId = 'a';
|
||||
@@ -461,7 +461,7 @@ describe('Events', () => {
|
||||
expect(namespace.to().emit).not.toHaveBeenCalled();
|
||||
// verify the "kill player" event is sent to everyone in the room (as opposed to everyone but the sender)
|
||||
expect(namespace.in).toHaveBeenCalledWith(game.accessCode);
|
||||
expect(namespace.in().emit).toHaveBeenCalledWith(EVENT_IDS.KILL_PLAYER, 'a');
|
||||
expect(namespace.in().emit).toHaveBeenCalledWith(EVENT_IDS.KILL_PLAYER, game.people.find(p => p.id === 'a'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user