X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=54d6c2660975aac30c9376ba05cff1c4feef3048;hp=2aec434654cf26d7bc5078298ab89f5d3739ce9d;hb=3c2c043c4a6e389a597736c9fd366b716ac7237c;hpb=a3d68ced6e2f65187e4fc076a488715a777b8a62 diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 2aec434..54d6c26 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -55,11 +55,11 @@ 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); + + window.game.set_scores(state.scores); }); events.addEventListener("prompt", event => { @@ -80,6 +80,12 @@ events.addEventListener("answered", event => { window.game.set_players_answered(players_answered); }); +events.addEventListener("scores", event => { + const scores = JSON.parse(event.data); + + window.game.set_scores(scores); +}); + /********************************************************* * Game and supporting classes * *********************************************************/ @@ -428,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); @@ -453,10 +465,54 @@ class Game extends React.PureComponent { }); } + set_scores(scores) { + this.setState({ + scores: scores + }); + } + render() { const state = this.state; const players_total = 1 + state.other_players.length; + if (state.scores) { + return ( +
+

Scores

+ +

Words submitted

+ + +
+ ); + } + if (state.active_prompt) { return