mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
Merge pull request #182 from AlecM33/fix-startability
Fix logic that determines if a game is startable when first constructed
This commit is contained in:
@@ -9,8 +9,7 @@ class Game {
|
|||||||
hasDedicatedModerator,
|
hasDedicatedModerator,
|
||||||
originalModeratorId,
|
originalModeratorId,
|
||||||
createTime,
|
createTime,
|
||||||
timerParams = null,
|
timerParams = null
|
||||||
isTestGame = false
|
|
||||||
) {
|
) {
|
||||||
this.accessCode = accessCode;
|
this.accessCode = accessCode;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
@@ -27,9 +26,6 @@ class Game {
|
|||||||
this.previousModeratorId = null;
|
this.previousModeratorId = null;
|
||||||
this.createTime = createTime;
|
this.createTime = createTime;
|
||||||
this.timerParams = timerParams;
|
this.timerParams = timerParams;
|
||||||
this.isStartable = (this.gameSize === 1 && !this.hasDedicatedModerator)
|
|
||||||
|| (this.gameSize === 0 && this.hasDedicatedModerator)
|
|
||||||
|| isTestGame;
|
|
||||||
this.timeRemaining = null;
|
this.timeRemaining = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,10 +91,12 @@ class GameManager {
|
|||||||
req.hasDedicatedModerator,
|
req.hasDedicatedModerator,
|
||||||
moderator.id,
|
moderator.id,
|
||||||
new Date().toJSON(),
|
new Date().toJSON(),
|
||||||
req.timerParams,
|
req.timerParams
|
||||||
req.isTestGame
|
|
||||||
);
|
);
|
||||||
newGame.people = initializePeopleForGame(req.deck, moderator, this.shuffle, req.isTestGame, newGame.gameSize);
|
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), {
|
await this.eventManager.publisher.set(newAccessCode, JSON.stringify(newGame), {
|
||||||
EX: PRIMITIVES.STALE_GAME_SECONDS
|
EX: PRIMITIVES.STALE_GAME_SECONDS
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -42,6 +42,9 @@ describe('Events', () => {
|
|||||||
new Date().toJSON(),
|
new Date().toJSON(),
|
||||||
null
|
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, 'to').and.callThrough();
|
||||||
spyOn(namespace, 'in').and.callThrough();
|
spyOn(namespace, 'in').and.callThrough();
|
||||||
spyOn(socket, 'to').and.callThrough();
|
spyOn(socket, 'to').and.callThrough();
|
||||||
|
|||||||
Reference in New Issue
Block a user