]> git.cworth.org Git - lmno.games/blobdiff - empathy/empathy.jsx
Empathy: Display player scores at the main screen of the game
[lmno.games] / empathy / empathy.jsx
index b03d697ef1cfd2561ffc1b223d4939e3b616fa4a..21b766ab689c3c8c652275f16d495387e40faaaa 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);
 
@@ -129,10 +127,12 @@ const PlayerInfo = React.memo(props => {
     <div className="player-info">
       <span className="players-header">Players: </span>
       {props.player.name}
+      {props.player.score > 0 ? ` (${props.player.score})` : ""}
       {props.other_players.map(other => (
         <span key={other.id}>
           {", "}
           {other.name}
+          {other.score > 0 ? ` (${other.score})` : ""}
         </span>
       ))}
     </div>
@@ -436,6 +436,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);