From 6250f71819887ebeb54bc1bbd42236d0d8dddaa0 Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Sat, 17 Dec 2022 14:52:21 -0500 Subject: [PATCH 1/4] don't emit killed event to person receiving mod powers --- server/modules/GameManager.js | 10 ++++++---- server/modules/SocketManager.js | 2 +- spec/unit/server/modules/GameManager_Spec.js | 17 +++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/server/modules/GameManager.js b/server/modules/GameManager.js index 3910704..8a2b6aa 100644 --- a/server/modules/GameManager.js +++ b/server/modules/GameManager.js @@ -175,12 +175,13 @@ class GameManager { : accessCode; }; - transferModeratorPowers = (game, person, namespace, logger) => { + transferModeratorPowers = (socket, game, person, namespace, logger) => { if (person && (person.out || person.userType === globals.USER_TYPES.SPECTATOR)) { logger.debug('game ' + game.accessCode + ': transferring mod powers to ' + person.name); if (game.moderator === person) { person.userType = globals.USER_TYPES.MODERATOR; this.namespace.to(person.socketId).emit(globals.EVENTS.SYNC_GAME_STATE); + socket.to(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, person.id); } else { const oldModerator = game.moderator; if (game.moderator.userType === globals.USER_TYPES.TEMPORARY_MODERATOR) { @@ -204,17 +205,18 @@ class GameManager { } }; - killPlayer = (game, person, namespace, logger) => { + killPlayer = (socket, game, person, namespace, logger) => { if (person && !person.out) { logger.debug('game ' + game.accessCode + ': killing player ' + person.name); if (person.userType !== globals.USER_TYPES.TEMPORARY_MODERATOR) { person.userType = globals.USER_TYPES.KILLED_PLAYER; } person.out = true; - namespace.in(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, person.id); // temporary moderators will transfer their powers automatically to the first person they kill. if (game.moderator.userType === globals.USER_TYPES.TEMPORARY_MODERATOR) { - this.transferModeratorPowers(game, person, namespace, logger); + this.transferModeratorPowers(socket, game, person, namespace, logger); + } else { + namespace.in(game.accessCode).emit(globals.EVENT_IDS.KILL_PLAYER, person.id); } } }; diff --git a/server/modules/SocketManager.js b/server/modules/SocketManager.js index c540dbf..9b5afc7 100644 --- a/server/modules/SocketManager.js +++ b/server/modules/SocketManager.js @@ -75,7 +75,7 @@ class SocketManager { gameManager.getTimeRemaining(game, socket); break; case EVENT_IDS.KILL_PLAYER: - gameManager.killPlayer(game, game.people.find((person) => person.id === args.personId), namespace, this.logger); + gameManager.killPlayer(socket, game, game.people.find((person) => person.id === args.personId), namespace, this.logger); break; case EVENT_IDS.REVEAL_PLAYER: gameManager.revealPlayer(game, args.personId); diff --git a/spec/unit/server/modules/GameManager_Spec.js b/spec/unit/server/modules/GameManager_Spec.js index 96b33a3..9286824 100644 --- a/spec/unit/server/modules/GameManager_Spec.js +++ b/spec/unit/server/modules/GameManager_Spec.js @@ -9,7 +9,7 @@ const GameStateCurator = require('../../../../server/modules/GameStateCurator'); const logger = require('../../../../server/modules/Logger.js')(false); describe('GameManager', () => { - let gameManager, namespace; + let gameManager, namespace, socket; beforeAll(() => { spyOn(logger, 'debug'); @@ -17,6 +17,7 @@ describe('GameManager', () => { const inObj = { emit: () => {} }; namespace = { in: () => { return inObj; }, to: () => { return inObj; } }; + socket = { id: '123', emit: () => {}, to: () => { return { emit: () => {} }; } }; gameManager = new GameManager(logger, globals.ENVIRONMENT.PRODUCTION).getInstance(); gameManager.setGameSocketNamespace(namespace); }); @@ -43,7 +44,7 @@ describe('GameManager', () => { moderator.id, new Date().toJSON() ); - gameManager.transferModeratorPowers(game, personToTransferTo, namespace, logger); + gameManager.transferModeratorPowers(socket, game, personToTransferTo, namespace, logger); expect(game.moderator).toEqual(personToTransferTo); expect(personToTransferTo.userType).toEqual(USER_TYPES.MODERATOR); @@ -69,7 +70,7 @@ describe('GameManager', () => { new Date().toJSON() ); game.spectators.push(personToTransferTo); - gameManager.transferModeratorPowers(game, personToTransferTo, namespace, logger); + gameManager.transferModeratorPowers(socket, game, personToTransferTo, namespace, logger); expect(game.moderator).toEqual(personToTransferTo); expect(personToTransferTo.userType).toEqual(USER_TYPES.MODERATOR); @@ -95,7 +96,7 @@ describe('GameManager', () => { tempMod.id, new Date().toJSON() ); - gameManager.transferModeratorPowers(game, personToTransferTo, namespace, logger); + gameManager.transferModeratorPowers(socket, game, personToTransferTo, namespace, logger); expect(game.moderator).toEqual(personToTransferTo); expect(personToTransferTo.userType).toEqual(USER_TYPES.MODERATOR); @@ -120,7 +121,7 @@ describe('GameManager', () => { tempMod.id, new Date().toJSON() ); - gameManager.transferModeratorPowers(game, personToTransferTo, namespace, logger); + gameManager.transferModeratorPowers(socket, game, personToTransferTo, namespace, logger); expect(game.moderator).toEqual(personToTransferTo); expect(personToTransferTo.userType).toEqual(USER_TYPES.MODERATOR); @@ -146,7 +147,7 @@ describe('GameManager', () => { mod.id, new Date().toJSON() ); - gameManager.killPlayer(game, player, namespace, logger); + gameManager.killPlayer(socket, game, player, namespace, logger); expect(player.out).toEqual(true); expect(player.userType).toEqual(USER_TYPES.KILLED_PLAYER); @@ -169,11 +170,11 @@ describe('GameManager', () => { tempMod.id, new Date().toJSON() ); - gameManager.killPlayer(game, tempMod, namespace, logger); + gameManager.killPlayer(socket, game, tempMod, namespace, logger); expect(tempMod.out).toEqual(true); expect(tempMod.userType).toEqual(USER_TYPES.TEMPORARY_MODERATOR); - expect(namespace.in().emit).toHaveBeenCalled(); + expect(namespace.in().emit).not.toHaveBeenCalled(); expect(gameManager.transferModeratorPowers).toHaveBeenCalled(); }); }); From 3b37585640dd8d0fe47194a51b059762ad38743f Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Sat, 17 Dec 2022 15:12:23 -0500 Subject: [PATCH 2/4] fix number of arguments to function call --- client/src/styles/game.css | 14 +++++++++++--- server/modules/SocketManager.js | 2 +- spec/unit/server/modules/GameManager_Spec.js | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/client/src/styles/game.css b/client/src/styles/game.css index b667334..fcc2c4f 100644 --- a/client/src/styles/game.css +++ b/client/src/styles/game.css @@ -382,7 +382,7 @@ h1 { #role-description { overflow: auto; position: absolute; - bottom: 8%; + bottom: 6%; left: 50%; transform: translate(-50%, 0); font-size: 15px; @@ -785,6 +785,14 @@ canvas { font-size: 18px; } + #game-people-container { + padding: 5px; + } + + #players-alive-label { + font-size: 20px; + } + #client-name { font-size: 20px; } @@ -810,8 +818,8 @@ canvas { /* padding: 5px;*/ /*}*/ - .game-player-name { - font-size: 16px; + .game-player-name, .game-player-role { + font-size: 14px; } #game-timer { diff --git a/server/modules/SocketManager.js b/server/modules/SocketManager.js index 9b5afc7..428aa77 100644 --- a/server/modules/SocketManager.js +++ b/server/modules/SocketManager.js @@ -85,7 +85,7 @@ class SocketManager { if (!person) { person = game.spectators.find((spectator) => spectator.id === args.personId); } - gameManager.transferModeratorPowers(game, person, namespace, this.logger); + gameManager.transferModeratorPowers(socket, game, person, namespace, this.logger); break; case EVENT_IDS.CHANGE_NAME: gameManager.changeName(game, args.data, ackFn); diff --git a/spec/unit/server/modules/GameManager_Spec.js b/spec/unit/server/modules/GameManager_Spec.js index 9286824..ac6d265 100644 --- a/spec/unit/server/modules/GameManager_Spec.js +++ b/spec/unit/server/modules/GameManager_Spec.js @@ -24,6 +24,7 @@ describe('GameManager', () => { beforeEach(() => { spyOn(namespace, 'to').and.callThrough(); + spyOn(socket, 'to').and.callThrough(); }); describe('#transferModerator', () => { @@ -127,6 +128,7 @@ describe('GameManager', () => { expect(personToTransferTo.userType).toEqual(USER_TYPES.MODERATOR); expect(tempMod.userType).toEqual(USER_TYPES.MODERATOR); expect(namespace.to).toHaveBeenCalledOnceWith(personToTransferTo.socketId); + expect(socket.to).toHaveBeenCalledWith(game.accessCode); }); }); From 6b81e4616af330f3efd1a46fe36e1b075b0d0448 Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Sat, 17 Dec 2022 15:18:05 -0500 Subject: [PATCH 3/4] move toast to top of screen, fix button height --- client/src/modules/game_state/states/Lobby.js | 2 +- client/src/styles/game.css | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/client/src/modules/game_state/states/Lobby.js b/client/src/modules/game_state/states/Lobby.js index 10ce765..21ecad8 100644 --- a/client/src/modules/game_state/states/Lobby.js +++ b/client/src/modules/game_state/states/Lobby.js @@ -76,7 +76,7 @@ export class Lobby { setSocketHandlers () { this.socket.on(globals.EVENT_IDS.PLAYER_JOINED, (player, gameIsFull) => { - toast(player.name + ' joined!', 'success', false, true, 'short'); + toast(player.name + ' joined!', 'success', true, true, 'short'); this.stateBucket.currentGameState.people.push(player); this.stateBucket.currentGameState.isFull = gameIsFull; this.populatePlayers(); diff --git a/client/src/styles/game.css b/client/src/styles/game.css index fcc2c4f..5787330 100644 --- a/client/src/styles/game.css +++ b/client/src/styles/game.css @@ -642,6 +642,7 @@ canvas { text-shadow: 0 3px 4px rgb(0 0 0 / 55%); margin: 5px 0 5px 25px; width: 65px; + height: 2px; } #game-link:hover { From 9cc06811ebaf0d2f42a1ebf5872e3055806b69cd Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Sat, 17 Dec 2022 15:18:34 -0500 Subject: [PATCH 4/4] fix type --- client/src/styles/game.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/styles/game.css b/client/src/styles/game.css index 5787330..c058c5e 100644 --- a/client/src/styles/game.css +++ b/client/src/styles/game.css @@ -642,7 +642,7 @@ canvas { text-shadow: 0 3px 4px rgb(0 0 0 / 55%); margin: 5px 0 5px 25px; width: 65px; - height: 2px; + height: 25px; } #game-link:hover {