X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=empathy%2Fempathy.jsx;h=cd5f3423d845f731e309e5521287a58e68f93c77;hb=bbbb65e60e043c8a60d362a6baa84e71dd4d2254;hp=b69ce6f15c3d090e178b27e78e89686a2e7051a1;hpb=dee335da95357a8993a22aab01809d5bbd3e9b57;p=lmno.games
diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx
index b69ce6f..cd5f342 100644
--- a/empathy/empathy.jsx
+++ b/empathy/empathy.jsx
@@ -55,9 +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 => {
@@ -66,6 +68,24 @@ events.addEventListener("prompt", event => {
window.game.add_or_update_prompt(prompt);
});
+events.addEventListener("start", event => {
+ const prompt = JSON.parse(event.data);
+
+ window.game.set_active_prompt(prompt);
+});
+
+events.addEventListener("answered", event => {
+ const players_answered = JSON.parse(event.data);
+
+ 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 *
*********************************************************/
@@ -80,7 +100,7 @@ function copy_to_clipboard(id)
document.body.removeChild(tmp);
}
-function GameInfo(props) {
+const GameInfo = React.memo(props => {
if (! props.id)
return null;
@@ -97,9 +117,9 @@ function GameInfo(props) {
>Copy Link
);
-}
+});
-function PlayerInfo(props) {
+const PlayerInfo = React.memo(props => {
if (! props.player.id)
return null;
@@ -107,15 +127,17 @@ function PlayerInfo(props) {
Players:
{props.player.name}
+ {props.player.score > 0 ? ` (${props.player.score})` : ""}
{props.other_players.map(other => (
{", "}
{other.name}
+ {other.score > 0 ? ` (${other.score})` : ""}
))}
);
-}
+});
function fetch_method_json(method, api = '', data = {}) {
const response = fetch(api, {
@@ -136,7 +158,7 @@ async function fetch_put_json(api = '', data = {}) {
return fetch_method_json('PUT', api, data);
}
-class CategoryRequest extends React.Component {
+class CategoryRequest extends React.PureComponent {
constructor(props) {
super(props);
this.category = React.createRef();
@@ -210,11 +232,7 @@ class CategoryRequest extends React.Component {
}
}
-function PromptOptions(props) {
-
- function handle_click(id) {
- fetch_post_json(`vote/${id}`);
- }
+const PromptOptions = React.memo(props => {
if (props.prompts.length === 0)
return null;
@@ -231,7 +249,7 @@ function PromptOptions(props) {