diff --git a/client/src/config/globals.js b/client/src/config/globals.js
index 3d502bd..53e9894 100644
--- a/client/src/config/globals.js
+++ b/client/src/config/globals.js
@@ -54,7 +54,8 @@ export const globals = {
UPDATE_SPECTATORS: 'updateSpectators',
RESTART_GAME: 'restartGame',
ASSIGN_DEDICATED_MOD: 'assignDedicatedMod',
- KICK_PERSON: 'kickPerson'
+ KICK_PERSON: 'kickPerson',
+ UPDATE_GAME_ROLES: 'updateGameRoles'
},
TIMER_EVENTS: function () {
return [
@@ -68,7 +69,8 @@ export const globals = {
return [
this.EVENT_IDS.PLAYER_JOINED,
this.EVENT_IDS.ADD_SPECTATOR,
- this.EVENT_IDS.KICK_PERSON
+ this.EVENT_IDS.KICK_PERSON,
+ this.EVENT_IDS.UPDATE_GAME_ROLES
];
},
IN_PROGRESS_EVENTS: function () {
diff --git a/client/src/images/save-svgrepo-com.svg b/client/src/images/save-svgrepo-com.svg
new file mode 100644
index 0000000..964878e
--- /dev/null
+++ b/client/src/images/save-svgrepo-com.svg
@@ -0,0 +1,4 @@
+
+
diff --git a/client/src/modules/front_end_components/HTMLFragments.js b/client/src/modules/front_end_components/HTMLFragments.js
index 83d89aa..812e08a 100644
--- a/client/src/modules/front_end_components/HTMLFragments.js
+++ b/client/src/modules/front_end_components/HTMLFragments.js
@@ -45,10 +45,8 @@ export const HTMLFragments = {
`,
START_GAME_PROMPT:
- `
@@ -69,5 +72,3 @@ const template =
`;
-
-export default template;
diff --git a/client/src/views/game.html b/client/src/views/game.html
index be5a021..3a1470d 100644
--- a/client/src/views/game.html
+++ b/client/src/views/game.html
@@ -14,6 +14,7 @@
+
diff --git a/server/config/globals.js b/server/config/globals.js
index af4bced..26fac56 100644
--- a/server/config/globals.js
+++ b/server/config/globals.js
@@ -56,7 +56,8 @@ const globals = {
UPDATE_SOCKET: 'updateSocket',
ASSIGN_DEDICATED_MOD: 'assignDedicatedMod',
TIMER_EVENT: 'timerEvent',
- KICK_PERSON: 'kickPerson'
+ KICK_PERSON: 'kickPerson',
+ UPDATE_GAME_ROLES: 'updateGameRoles'
},
SYNCABLE_EVENTS: function () {
return [
@@ -76,7 +77,8 @@ const globals = {
this.EVENT_IDS.RESUME_TIMER,
this.EVENT_IDS.PAUSE_TIMER,
this.EVENT_IDS.END_TIMER,
- this.EVENT_IDS.KICK_PERSON
+ this.EVENT_IDS.KICK_PERSON,
+ this.EVENT_IDS.UPDATE_GAME_ROLES
];
},
TIMER_EVENTS: function () {
diff --git a/server/model/GameCreationRequest.js b/server/model/GameCreationRequest.js
index 29e20a7..e2ab638 100644
--- a/server/model/GameCreationRequest.js
+++ b/server/model/GameCreationRequest.js
@@ -29,6 +29,33 @@ class GameCreationRequest {
return Promise.resolve();
}
};
+
+ static deckIsValid = (deck) => {
+ if (Array.isArray(deck) && deck.length > 0) {
+ for (const entry of deck) {
+ if (entry !== null
+ && typeof entry === 'object'
+ && typeof entry.role === 'string'
+ && entry.role.length > 0
+ && entry.role.length <= globals.MAX_CUSTOM_ROLE_NAME_LENGTH
+ && typeof entry.team === 'string'
+ && (entry.team === globals.ALIGNMENT.GOOD || entry.team === globals.ALIGNMENT.EVIL)
+ && typeof entry.description === 'string'
+ && entry.description.length > 0
+ && entry.description.length <= globals.MAX_CUSTOM_ROLE_DESCRIPTION_LENGTH
+ && (!entry.custom || typeof entry.custom === 'boolean')
+ && typeof entry.quantity === 'number'
+ && entry.quantity >= 1
+ && entry.quantity <= 50
+ ) {
+ continue;
+ }
+ return false;
+ }
+ return true;
+ }
+ return false;
+ }
}
function valid (gameParams) {
@@ -39,7 +66,7 @@ function valid (gameParams) {
&& gameParams.moderatorName.length > 0
&& gameParams.moderatorName.length <= 30
&& timerParamsAreValid(gameParams.hasTimer, gameParams.timerParams)
- && deckIsValid(gameParams.deck);
+ && GameCreationRequest.deckIsValid(gameParams.deck);
}
function timerParamsAreValid (hasTimer, timerParams) {
@@ -58,31 +85,4 @@ function timerParamsAreValid (hasTimer, timerParams) {
}
}
-function deckIsValid (deck) {
- if (Array.isArray(deck) && deck.length > 0) {
- for (const entry of deck) {
- if (entry !== null
- && typeof entry === 'object'
- && typeof entry.role === 'string'
- && entry.role.length > 0
- && entry.role.length <= globals.MAX_CUSTOM_ROLE_NAME_LENGTH
- && typeof entry.team === 'string'
- && (entry.team === globals.ALIGNMENT.GOOD || entry.team === globals.ALIGNMENT.EVIL)
- && typeof entry.description === 'string'
- && entry.description.length > 0
- && entry.description.length <= globals.MAX_CUSTOM_ROLE_DESCRIPTION_LENGTH
- && (!entry.custom || typeof entry.custom === 'boolean')
- && typeof entry.quantity === 'number'
- && entry.quantity >= 1
- && entry.quantity <= 50
- ) {
- continue;
- }
- return false;
- }
- return true;
- }
- return false;
-}
-
module.exports = GameCreationRequest;
diff --git a/server/modules/Events.js b/server/modules/Events.js
index eb1cd8f..fc02fd0 100644
--- a/server/modules/Events.js
+++ b/server/modules/Events.js
@@ -1,6 +1,7 @@
const globals = require('../config/globals');
const GameStateCurator = require('./GameStateCurator');
const UsernameGenerator = require('./UsernameGenerator');
+const GameCreationRequest = require('../model/GameCreationRequest');
const EVENT_IDS = globals.EVENT_IDS;
const Events = [
@@ -57,6 +58,28 @@ const Events = [
);
}
},
+ {
+ id: EVENT_IDS.UPDATE_GAME_ROLES,
+ stateChange: async (game, socketArgs, vars) => {
+ if (GameCreationRequest.deckIsValid(socketArgs.deck)) {
+ game.deck = socketArgs.deck;
+ game.gameSize = socketArgs.deck.reduce(
+ (accumulator, currentValue) => accumulator + currentValue.quantity,
+ 0
+ );
+ }
+ },
+ communicate: async (game, socketArgs, vars) => {
+ if (vars.ackFn) {
+ vars.ackFn();
+ }
+ vars.gameManager.namespace.in(game.accessCode).emit(
+ EVENT_IDS.UPDATE_GAME_ROLES,
+ game.deck,
+ game.gameSize
+ );
+ }
+ },
{
id: EVENT_IDS.ADD_SPECTATOR,
stateChange: async (game, socketArgs, vars) => {
diff --git a/server/modules/singletons/GameManager.js b/server/modules/singletons/GameManager.js
index 3149ae7..5443f14 100644
--- a/server/modules/singletons/GameManager.js
+++ b/server/modules/singletons/GameManager.js
@@ -302,6 +302,10 @@ class GameManager {
return array;
};
+ deal = () => {
+
+ }
+
isGameFull = (game) => {
return !game.people.find((person) => person.userType === globals.USER_TYPES.PLAYER && person.assigned === false);
}
diff --git a/spec/e2e/game_spec.js b/spec/e2e/game_spec.js
index 05d73f5..a3295de 100644
--- a/spec/e2e/game_spec.js
+++ b/spec/e2e/game_spec.js
@@ -332,7 +332,7 @@ describe('game page', () => {
}
]);
expect(document.getElementById('end-of-game-header')).not.toBeNull();
- expect(document.getElementById('restart-game-button')).not.toBeNull();
+ expect(document.getElementById('return-to-lobby-button')).not.toBeNull();
});
afterAll(() => {