From 226d653455b4cb8baf4d19195ca2ea20cfa0c505 Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Tue, 15 Mar 2022 13:24:21 -0700 Subject: [PATCH] Working on turn timer Signed-off-by: James Ketrenos --- client/src/App.js | 7 +------ server/routes/games.js | 19 +++++++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index 9b274eb..2fbabac 100755 --- a/client/src/App.js +++ b/client/src/App.js @@ -43,7 +43,6 @@ const Table = () => { const [connection, setConnection] = useState(undefined); const [state, setState] = useState(undefined); const [color, setColor] = useState(undefined); - const [setPlayers] = useState(undefined); const [priv, setPriv] = useState(undefined); const [buildActive, setBuildActive] = useState(false); const [cardActive, setCardActive] = useState(undefined); @@ -110,9 +109,6 @@ const Table = () => { setPriv(priv); } - if ('players' in data.update) { - setPlayers(data.update.players); - } if ('name' in data.update && data.update.name !== name) { console.log(`App - setting name: ${data.update.name}`); setName(data.update.name); @@ -298,8 +294,7 @@ const Table = () => { { priv && priv.turnNotice &&
{ priv.turnNotice }
- - +
} { warning &&
diff --git a/server/routes/games.js b/server/routes/games.js index 4855434..a435f1d 100755 --- a/server/routes/games.js +++ b/server/routes/games.js @@ -1915,6 +1915,9 @@ const pass = (game, session) => { game.turns++; addActivity(game, session, `${name} passed their turn.`); addChatMessage(game, null, `It is ${next.name}'s turn.`); + sendUpdateToPlayer(game, next, { + private: next.player + }); sendUpdateToPlayer(game, session, { private: session.player }); @@ -3070,6 +3073,10 @@ const todo = `[ todo ]`; const sendGameToPlayer = (game, session) => { console.log(`${session.id}: -> sendGamePlayer:${getName(session)} - full game`); + if (!session.ws) { + console.log(`${session.id}: -> sendGamePlayer:: Currently no connection`); + return; + } session.ws.send(JSON.stringify({ type: 'game-update', update: getFilteredGameForPlayer(game, session) @@ -3080,14 +3087,7 @@ const sendGameToPlayers = (game) => { console.log(`${all}: -> sendGamePlayers - full game`); for (let key in game.sessions) { - const _session = game.sessions[key]; - if (!_session.ws) { - continue; - } - _session.ws.send(JSON.stringify({ - type: 'game-update', - update: getFilteredGameForPlayer(game, _session) - })); + sendGameToPlayer(game, game.sessions[key]); } }; @@ -3590,6 +3590,8 @@ router.ws("/ws/:id", async (ws, req) => { } processed = true; + const priorSession = session; + switch (data.type) { case 'roll': console.log(`${short}: <- roll:${getName(session)}`); @@ -3741,6 +3743,7 @@ router.ws("/ws/:id", async (ws, req) => { break; } + /* If the current player took an action, reset the session timer */ if (processed && session.color === game.turn.color) { resetTurnTimer(game, session); }