From 9aa7407eda90493c1004258e705ef0fa4afa6a48 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Wed, 10 Jun 2020 19:26:51 -0700 Subject: [PATCH] Empathy: Delay the updating of total scores until a new round 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 | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/empathy.js b/empathy.js index f9bf741..b12c3e7 100644 --- a/empathy.js +++ b/empathy.js @@ -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) => { -- 2.43.0