From: Carl Worth Date: Wed, 10 Jun 2020 14:57:08 +0000 (-0700) Subject: Empathy: When receiving a game-state event overwrite all prompts X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=commitdiff_plain;h=3c2c043c4a6e389a597736c9fd366b716ac7237c Empathy: When receiving a game-state event overwrite all prompts Originally this cod was written to add each received prompt, but that does the wrong thing when the game-state object is trying to set a subset of the prompts we already have, (for example, to drop the prompt we just finished playing when starting a new game). --- diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index b03d697..54d6c26 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -55,9 +55,7 @@ events.addEventListener("player-update", event => { events.addEventListener("game-state", event => { const state = JSON.parse(event.data); - for (let prompt of state.prompts) { - window.game.add_or_update_prompt(prompt); - } + window.game.set_prompts(state.prompts); window.game.set_active_prompt(state.active_prompt); @@ -436,6 +434,12 @@ class Game extends React.PureComponent { }); } + set_prompts(prompts) { + this.setState({ + prompts: prompts + }); + } + add_or_update_prompt(prompt) { const prompts_copy = [...this.state.prompts]; const idx = prompts_copy.findIndex(p => p.id === prompt.id);