]> git.cworth.org Git - lmno.games/commitdiff
Empathy: When receiving a game-state event overwrite all prompts
authorCarl Worth <cworth@cworth.org>
Wed, 10 Jun 2020 14:57:08 +0000 (07:57 -0700)
committerCarl Worth <cworth@cworth.org>
Wed, 10 Jun 2020 14:57:08 +0000 (07:57 -0700)
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).

empathy/empathy.jsx

index b03d697ef1cfd2561ffc1b223d4939e3b616fa4a..54d6c2660975aac30c9376ba05cff1c4feef3048 100644 (file)
@@ -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);