]> git.cworth.org Git - empires-server/commitdiff
Empathy: Delay the updating of total scores until a new round
authorCarl Worth <cworth@cworth.org>
Thu, 11 Jun 2020 02:26:51 +0000 (19:26 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 11 Jun 2020 02:26:51 +0000 (19:26 -0700)
Instead of doing this in the compute_scores function (for the current
round) as we may end up having that function called multiple times.

empathy.js

index f9bf7410d4da8e77f3208b6608005dc770dabbbd..b12c3e75553f596b7cc2108cc9e1c21f0bd97444 100644 (file)
@@ -15,6 +15,20 @@ class Empathy extends Game {
   }
 
   reset() {
+
+    /* Before closing out the current round, we accumulate that score
+     * for each player into their runnning total. */
+    for (let score of this.state.scores.scores) {
+      const player = this.players.find(p => p.name === score.player);
+      if (player.score)
+        player.score += score.score;
+      else
+        player.score = score.score;
+
+      /* And broadcast that new score out. */
+      this.broadcast_event('player-update', player.info_json());
+    }
+
     /* Now that we're done with the active prompt, we remove it from
      * the list of prompts and also remove any prompts that received
      * no votes. This keeps the list of prompts clean.
@@ -125,16 +139,6 @@ class Empathy extends Game {
         player: a.player.name,
         score: score
       });
-      /* Now that we've computed the score for a player for this
-       * round, also accumulate that score into the players runnning
-       * total. */
-      if (a.player.score)
-        a.player.score += score;
-      else
-        a.player.score = score;
-
-      /* And broadcast that new score out. */
-      this.broadcast_event('player-update', a.player.info_json());
     }
 
     scores.sort((a,b) => {