Skip to content

Commit

Permalink
Merge pull request #182 from AlecM33/fix-startability
Browse files Browse the repository at this point in the history
Fix logic that determines if a game is startable when first constructed
  • Loading branch information
AlecM33 committed Nov 28, 2023
2 parents 008116d + 95d0cee commit 2a52bd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 1 addition & 5 deletions server/model/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Game {
hasDedicatedModerator,
originalModeratorId,
createTime,
timerParams = null,
isTestGame = false
timerParams = null
) {
this.accessCode = accessCode;
this.status = status;
Expand All @@ -27,9 +26,6 @@ class Game {
this.previousModeratorId = null;
this.createTime = createTime;
this.timerParams = timerParams;
this.isStartable = (this.gameSize === 1 && !this.hasDedicatedModerator)
|| (this.gameSize === 0 && this.hasDedicatedModerator)
|| isTestGame;
this.timeRemaining = null;
}
}
Expand Down
6 changes: 4 additions & 2 deletions server/modules/singletons/GameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ class GameManager {
req.hasDedicatedModerator,
moderator.id,
new Date().toJSON(),
req.timerParams,
req.isTestGame
req.timerParams
);
newGame.people = initializePeopleForGame(req.deck, moderator, this.shuffle, req.isTestGame, newGame.gameSize);
newGame.isStartable = newGame.people.filter(person => person.userType === USER_TYPES.PLAYER
|| person.userType === USER_TYPES.TEMPORARY_MODERATOR
|| person.userType === USER_TYPES.BOT).length === newGame.gameSize;
await this.eventManager.publisher.set(newAccessCode, JSON.stringify(newGame), {
EX: PRIMITIVES.STALE_GAME_SECONDS
});
Expand Down
3 changes: 3 additions & 0 deletions spec/unit/server/modules/Events_Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ describe('Events', () => {
new Date().toJSON(),
null
);
game.isStartable = game.people.filter(person => person.userType === USER_TYPES.PLAYER
|| person.userType === USER_TYPES.TEMPORARY_MODERATOR
|| person.userType === USER_TYPES.BOT).length === game.gameSize;
spyOn(namespace, 'to').and.callThrough();
spyOn(namespace, 'in').and.callThrough();
spyOn(socket, 'to').and.callThrough();
Expand Down

0 comments on commit 2a52bd0

Please sign in to comment.