mirror of
https://github.com/AlecM33/Werewolf.git
synced 2025-12-26 15:57:50 +01:00
get timer on connect, patch play/pause functionality
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
const globals = require("../config/globals")
|
||||
|
||||
const GameStateCurator = {
|
||||
getGameStateFromPerspectiveOfPerson: (game, person) => {
|
||||
return getGameStateBasedOnPermissions(game, person);
|
||||
getGameStateFromPerspectiveOfPerson: (game, person, gameRunner, socket, logger) => {
|
||||
if (game.timerParams && game.status === globals.STATUS.IN_PROGRESS) {
|
||||
getTimeRemaining(game.accessCode, gameRunner, socket, logger)
|
||||
}
|
||||
return getGameStateBasedOnPermissions(game, person, gameRunner);
|
||||
}
|
||||
}
|
||||
|
||||
function getGameStateBasedOnPermissions(game, person) {
|
||||
function getGameStateBasedOnPermissions(game, person, gameRunner) {
|
||||
let client = game.status === globals.STATUS.LOBBY // people won't be able to know their role until past the lobby stage.
|
||||
? { name: person.name, id: person.id }
|
||||
: {
|
||||
@@ -89,4 +92,16 @@ function mapPerson(person) {
|
||||
return { name: person.name };
|
||||
}
|
||||
|
||||
function getTimeRemaining(accessCode, gameRunner, socket, logger) {
|
||||
let thread = gameRunner.timerThreads[accessCode];
|
||||
if (thread) {
|
||||
thread.send({
|
||||
command: globals.GAME_PROCESS_COMMANDS.GET_TIME_REMAINING,
|
||||
accessCode: accessCode,
|
||||
socketId: socket.id,
|
||||
logLevel: logger.logLevel
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GameStateCurator;
|
||||
|
||||
Reference in New Issue
Block a user