From bef8cd8d59b1d40df0763ccaa5c97baff50b5c2b Mon Sep 17 00:00:00 2001 From: AlecM33 Date: Sat, 8 Apr 2023 16:01:39 -0400 Subject: [PATCH] fix bug with redundant play/pause events, fix spec, tweak current moderator css --- .../modules/game_state/states/InProgress.js | 3 +- client/src/styles/game.css | 6 ++-- package.json | 2 +- server/modules/ServerTimer.js | 29 ++++++++++--------- server/modules/singletons/EventManager.js | 2 +- spec/unit/server/modules/ServerTimer_Spec.js | 5 ++-- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/client/src/modules/game_state/states/InProgress.js b/client/src/modules/game_state/states/InProgress.js index fb8588e..21892e2 100644 --- a/client/src/modules/game_state/states/InProgress.js +++ b/client/src/modules/game_state/states/InProgress.js @@ -188,7 +188,8 @@ export class InProgress { toast('You have been killed!', 'warning', true, true, 'medium'); } else { toast(killedPlayer.name + ' was killed!', 'warning', true, true, 'medium'); - if (killedPlayer.userType === globals.USER_TYPES.MODERATOR) { + if (killedPlayer.userType === globals.USER_TYPES.MODERATOR + && this.stateBucket.currentGameState.client.userType !== globals.USER_TYPES.TEMPORARY_MODERATOR) { SharedStateUtil.displayCurrentModerator(killedPlayer); } } diff --git a/client/src/styles/game.css b/client/src/styles/game.css index f02acb1..0d5e7d8 100644 --- a/client/src/styles/game.css +++ b/client/src/styles/game.css @@ -21,8 +21,8 @@ border-radius: 5px; color: #d7d7d7; background-color: #16141e; - width: fit-content; - padding: 0 20px; + padding: 0 10px; + width: 90%; margin-bottom: 0.5em; } @@ -74,7 +74,7 @@ flex-wrap: wrap; display: flex; width: 100%; - margin: 1em auto 140px auto; + margin: 0 auto 140px auto; } #game-state-container h2 { diff --git a/package.json b/package.json index b7b83e8..eb6d0c1 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "build:dev": "webpack --watch --config client/webpack/webpack-dev.config.js --mode=development", "start:dev": "NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js", "start:dev:no-hot-reload": "NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js", - "start:dev:windows": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js", + "start:dev:windows": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && nodemon index.js -- loglevel=debug", "start:dev:windows:no-hot-reload:debug": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && node --inspect index.js", "start:dev:windows:no-hot-reload": "SET NODE_ENV=development && webpack --config client/webpack/webpack-dev.config.js --mode=development && node index.js", "start": "NODE_ENV=production node index.js -- loglevel=debug", diff --git a/server/modules/ServerTimer.js b/server/modules/ServerTimer.js index 6f08ea8..8d6b69e 100644 --- a/server/modules/ServerTimer.js +++ b/server/modules/ServerTimer.js @@ -66,26 +66,29 @@ class ServerTimer { } stopTimer () { - this.logger.debug('STOPPING TIMER'); if (this.ticking) { + this.logger.debug('STOPPING TIMER'); clearTimeout(this.ticking); + this.ticking = null; } } resumeTimer () { - this.logger.debug('RESUMING TIMER FOR ' + this.currentTimeInMillis + 'ms'); - this.start = Date.now(); - this.totalTime = this.currentTimeInMillis; - const expected = Date.now() + this.tickInterval; - const instance = this; - this.ticking = setTimeout(function () { - stepFn( - instance, - expected - ); - }, this.tickInterval); + if (!this.ticking) { + this.logger.debug('RESUMING TIMER FOR ' + this.currentTimeInMillis + 'ms'); + this.start = Date.now(); + this.totalTime = this.currentTimeInMillis; + const expected = Date.now() + this.tickInterval; + const instance = this; + this.ticking = setTimeout(function () { + stepFn( + instance, + expected + ); + }, this.tickInterval); - return this.timesUpPromise; + return this.timesUpPromise; + } } } diff --git a/server/modules/singletons/EventManager.js b/server/modules/singletons/EventManager.js index 6c65e62..951be2e 100644 --- a/server/modules/singletons/EventManager.js +++ b/server/modules/singletons/EventManager.js @@ -59,7 +59,7 @@ class EventManager { try { messageComponents = message.split(';', 3); if (messageComponents[messageComponents.length - 1] === this.instanceId) { - this.logger.trace('Disregarding self-authored message'); + this.logger.debug('Disregarding self-authored message'); return; } args = JSON.parse( diff --git a/spec/unit/server/modules/ServerTimer_Spec.js b/spec/unit/server/modules/ServerTimer_Spec.js index 460e57b..ce296b6 100644 --- a/spec/unit/server/modules/ServerTimer_Spec.js +++ b/spec/unit/server/modules/ServerTimer_Spec.js @@ -21,12 +21,11 @@ describe('ServerTimer', () => { serverTimer = new ServerTimer(1, 0, 10, logger); spyOn(global, 'clearTimeout'); serverTimer.runTimer(false).then(() => { - fail(); + serverTimer.stopTimer(); + expect(clearTimeout).toHaveBeenCalledWith(serverTimer.ticking); }).catch((e) => { fail(e); }); - serverTimer.stopTimer(); - expect(clearTimeout).toHaveBeenCalledWith(serverTimer.ticking); }); it('should stop and resume the timer', async () => {