mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
fix expectations, remove outdated specs
This commit is contained in:
@@ -7,19 +7,14 @@ const Events = [
|
||||
{
|
||||
id: EVENT_IDS.PLAYER_JOINED,
|
||||
stateChange: async (game, socketArgs, vars) => {
|
||||
const toBeAssignedIndex = game.people.findIndex(
|
||||
(person) => person.id === socketArgs.id && person.assigned === false
|
||||
);
|
||||
if (toBeAssignedIndex >= 0) {
|
||||
game.people[toBeAssignedIndex] = socketArgs;
|
||||
game.isFull = vars.gameManager.isGameFull(game);
|
||||
}
|
||||
game.people.push(socketArgs);
|
||||
game.isStartable = vars.gameManager.isGameStartable(game);
|
||||
},
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(
|
||||
globals.EVENTS.PLAYER_JOINED,
|
||||
GameStateCurator.mapPerson(socketArgs),
|
||||
game.isFull
|
||||
game.isStartable
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -31,14 +26,14 @@ const Events = [
|
||||
);
|
||||
if (toBeClearedIndex >= 0) {
|
||||
game.people.splice(toBeClearedIndex, 1);
|
||||
game.isFull = vars.gameManager.isGameFull(game);
|
||||
game.isStartable = vars.gameManager.isGameStartable(game);
|
||||
}
|
||||
},
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(
|
||||
EVENT_IDS.KICK_PERSON,
|
||||
socketArgs.personId,
|
||||
game.isFull
|
||||
game.isStartable
|
||||
);
|
||||
}
|
||||
},
|
||||
@@ -51,7 +46,7 @@ const Events = [
|
||||
(accumulator, currentValue) => accumulator + currentValue.quantity,
|
||||
0
|
||||
);
|
||||
game.isFull = vars.gameManager.isGameFull(game);
|
||||
game.isStartable = vars.gameManager.isGameStartable(game);
|
||||
}
|
||||
},
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
@@ -109,7 +104,7 @@ const Events = [
|
||||
{
|
||||
id: EVENT_IDS.START_GAME,
|
||||
stateChange: async (game, socketArgs, vars) => {
|
||||
if (game.isFull) {
|
||||
if (game.isStartable) {
|
||||
game.status = globals.STATUS.IN_PROGRESS;
|
||||
vars.gameManager.deal(game);
|
||||
if (game.hasTimer) {
|
||||
|
||||
@@ -71,7 +71,7 @@ function getGameStateBasedOnPermissions (game, person) {
|
||||
gameSize: game.gameSize,
|
||||
people: GameStateCurator.mapPeopleForModerator(game.people, client),
|
||||
timerParams: game.timerParams,
|
||||
isFull: game.isFull
|
||||
isStartable: game.isStartable
|
||||
};
|
||||
case globals.USER_TYPES.TEMPORARY_MODERATOR:
|
||||
case globals.USER_TYPES.SPECTATOR:
|
||||
@@ -90,7 +90,7 @@ function getGameStateBasedOnPermissions (game, person) {
|
||||
})
|
||||
.map((filteredPerson) => GameStateCurator.mapPerson(filteredPerson)),
|
||||
timerParams: game.timerParams,
|
||||
isFull: game.isFull
|
||||
isStartable: game.isStartable
|
||||
};
|
||||
default:
|
||||
break;
|
||||
|
||||
@@ -181,7 +181,7 @@ class GameManager {
|
||||
&& game.people.filter(person => person.userType === globals.USER_TYPES.SPECTATOR).length === globals.MAX_SPECTATORS
|
||||
) {
|
||||
return Promise.reject({ status: 400, reason: 'There are too many people already spectating.' });
|
||||
} else if (joinAsSpectator || this.isGameFull(game)) {
|
||||
} else if (joinAsSpectator || this.isGameStartable(game)) {
|
||||
console.log('game is full');
|
||||
return await addSpectator(game, name, this.logger, this.namespace, this.eventManager, this.instanceId, this.refreshGame);
|
||||
}
|
||||
@@ -206,12 +206,12 @@ class GameManager {
|
||||
newPlayer.assigned = true;
|
||||
game.people.push(newPlayer);
|
||||
}
|
||||
game.isFull = this.isGameFull(game);
|
||||
game.isStartable = this.isGameStartable(game);
|
||||
await this.refreshGame(game);
|
||||
this.namespace.in(game.accessCode).emit(
|
||||
globals.EVENTS.PLAYER_JOINED,
|
||||
GameStateCurator.mapPerson(moderator || newPlayer),
|
||||
game.isFull
|
||||
game.isStartable
|
||||
);
|
||||
await this.eventManager.publisher?.publish(
|
||||
globals.REDIS_CHANNELS.ACTIVE_GAME_STREAM,
|
||||
@@ -318,7 +318,7 @@ class GameManager {
|
||||
}
|
||||
}
|
||||
|
||||
isGameFull = (game) => {
|
||||
isGameStartable = (game) => {
|
||||
return game.people.filter(person => person.userType === globals.USER_TYPES.PLAYER
|
||||
|| person.userType === globals.USER_TYPES.TEMPORARY_MODERATOR).length === game.gameSize;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user