mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
built out rest of functionality; add placeholder when there are no custom roles
This commit is contained in:
@@ -78,6 +78,7 @@ const EVENT_IDS = {
|
||||
TIMER_EVENT: 'timerEvent',
|
||||
KICK_PERSON: 'kickPerson',
|
||||
UPDATE_GAME_ROLES: 'updateGameRoles',
|
||||
UPDATE_GAME_TIMER: 'updateGameTimer',
|
||||
LEAVE_ROOM: 'leaveRoom',
|
||||
BROADCAST: 'broadcast'
|
||||
};
|
||||
@@ -103,6 +104,7 @@ const SYNCABLE_EVENTS = function () {
|
||||
EVENT_IDS.END_TIMER,
|
||||
EVENT_IDS.KICK_PERSON,
|
||||
EVENT_IDS.UPDATE_GAME_ROLES,
|
||||
EVENT_IDS.UPDATE_GAME_TIMER,
|
||||
EVENT_IDS.LEAVE_ROOM
|
||||
];
|
||||
};
|
||||
|
||||
@@ -56,6 +56,22 @@ class GameCreationRequest {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static timerParamsAreValid = (hasTimer, timerParams) => {
|
||||
if (hasTimer === false) {
|
||||
return timerParams === null;
|
||||
} else {
|
||||
if (timerParams === null || typeof timerParams !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (timerParams.hours === null && timerParams.minutes > 0 && timerParams.minutes < 60)
|
||||
|| (timerParams.minutes === null && timerParams.hours > 0 && timerParams.hours < 6)
|
||||
|| (timerParams.hours === 0 && timerParams.minutes > 0 && timerParams.minutes < 60)
|
||||
|| (timerParams.minutes === 0 && timerParams.hours > 0 && timerParams.hours < 6)
|
||||
|| (timerParams.hours > 0 && timerParams.hours < 6 && timerParams.minutes >= 0 && timerParams.minutes < 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function valid (gameParams) {
|
||||
@@ -65,24 +81,8 @@ function valid (gameParams) {
|
||||
&& typeof gameParams.moderatorName === 'string'
|
||||
&& gameParams.moderatorName.length > 0
|
||||
&& gameParams.moderatorName.length <= 30
|
||||
&& timerParamsAreValid(gameParams.hasTimer, gameParams.timerParams)
|
||||
&& GameCreationRequest.timerParamsAreValid(gameParams.hasTimer, gameParams.timerParams)
|
||||
&& GameCreationRequest.deckIsValid(gameParams.deck);
|
||||
}
|
||||
|
||||
function timerParamsAreValid (hasTimer, timerParams) {
|
||||
if (hasTimer === false) {
|
||||
return timerParams === null;
|
||||
} else {
|
||||
if (timerParams === null || typeof timerParams !== 'object') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (timerParams.hours === null && timerParams.minutes > 0 && timerParams.minutes < 60)
|
||||
|| (timerParams.minutes === null && timerParams.hours > 0 && timerParams.hours < 6)
|
||||
|| (timerParams.hours === 0 && timerParams.minutes > 0 && timerParams.minutes < 60)
|
||||
|| (timerParams.minutes === 0 && timerParams.hours > 0 && timerParams.hours < 6)
|
||||
|| (timerParams.hours > 0 && timerParams.hours < 6 && timerParams.minutes >= 0 && timerParams.minutes < 60);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GameCreationRequest;
|
||||
|
||||
@@ -69,7 +69,7 @@ const Events = [
|
||||
}
|
||||
vars.ackFn({ errorFlag: 1, message: 'This name is taken.' });
|
||||
} else if (socketArgs.newName.length > PRIMITIVES.MAX_PERSON_NAME_LENGTH) {
|
||||
vars.ackFn({ errorFlag: 1, message: 'Your new name is too long - the max is' + PRIMITIVES.MAX_PERSON_NAME_LENGTH + ' characters.' });
|
||||
vars.ackFn({ errorFlag: 1, message: 'Your new name is too long - the max is ' + PRIMITIVES.MAX_PERSON_NAME_LENGTH + ' characters.' });
|
||||
vars.hasNameChanged = false;
|
||||
} else if (socketArgs.newName.length === 0) {
|
||||
vars.ackFn({ errorFlag: 1, message: 'Your new name cannot be empty.' });
|
||||
@@ -381,6 +381,25 @@ const Events = [
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
id: EVENT_IDS.UPDATE_GAME_TIMER,
|
||||
stateChange: async (game, socketArgs, vars) => {
|
||||
if (GameCreationRequest.timerParamsAreValid(socketArgs.hasTimer, socketArgs.timerParams)) {
|
||||
game.hasTimer = socketArgs.hasTimer;
|
||||
game.timerParams = socketArgs.timerParams;
|
||||
}
|
||||
},
|
||||
communicate: async (game, socketArgs, vars) => {
|
||||
if (vars.ackFn) {
|
||||
vars.ackFn();
|
||||
}
|
||||
vars.gameManager.namespace.in(game.accessCode).emit(
|
||||
EVENT_IDS.UPDATE_GAME_TIMER,
|
||||
game.hasTimer,
|
||||
game.timerParams
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
id: EVENT_IDS.END_TIMER,
|
||||
stateChange: async (game, socketArgs, vars) => {
|
||||
|
||||
Reference in New Issue
Block a user