From: Carl Worth Date: Mon, 1 Jun 2020 17:52:19 +0000 (-0700) Subject: tictactoe: Adapt to new server event type: game-state X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=0edb467eb1b8922d885ef6a756fca68c9d2d0a08 tictactoe: Adapt to new server event type: game-state Previously, when a client joined a game in progress the server would send all previous moves as "move" events (just the same as if a player were making those moves live). The server was recently changed to instead a single "game-state" event in this case, (which also does contain the entire move history). So when we receive that, we reset the game state, then replay the moves from that history. --- diff --git a/tictactoe/tictactoe.jsx b/tictactoe/tictactoe.jsx index 849a6f2..17c966d 100644 --- a/tictactoe/tictactoe.jsx +++ b/tictactoe/tictactoe.jsx @@ -25,6 +25,16 @@ events.addEventListener("move", event => { window.game.receiveMove(square); }); +events.addEventListener("game-state", event => { + const state = JSON.parse(event.data); + + window.game.resetState(); + + for (let square of state.moves) { + window.game.receiveMove(square); + } +}); + function Square(props) { return (