window.game.set_other_player_info(info);
});
+events.addEventListener("player-exit", event => {
+ const info = JSON.parse(event.data);
+
+ window.game.remove_player(info);
+});
+
events.addEventListener("player-update", event => {
const info = JSON.parse(event.data);
window.game.set_end_judging(state.end_judging);
window.game.set_scores(state.scores);
+
+ window.game.state_ready();
});
events.addEventListener("prompt", event => {
if (! props.player.id)
return null;
+ const all_players = [props.player, ...props.other_players];
+
+ const sorted_players = all_players.sort((a,b) => {
+ return b.score - a.score;
+ });
+
+ const names_and_scores = sorted_players.map(player => {
+ if (player.score)
+ return `${player.name} (${player.score})`;
+ else
+ return player.name;
+ }).join(', ');
+
return (
<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>
- ))}
+ <span>{names_and_scores}</span>
</div>
);
});
players_judging: {},
judging_idle: false,
end_judging_votes: new Set(),
- scores: null
+ scores: null,
+ ready: false
};
}
});
}
+ remove_player(info) {
+ this.setState({
+ other_players: this.state.other_players.filter(o => o.id !== info.id)
+ });
+ }
+
reset_game_state() {
this.setState({
prompts: [],
players_judging: {},
judging_idle: false,
end_judging_votes: new Set(),
- scores: null
+ scores: null,
+ ready: false
});
}
}
set_judging_idle(value) {
- console.log("Setting judging idle to " + value);
this.setState({
judging_idle: value
});
});
}
+ state_ready() {
+ this.setState({
+ ready: true
+ });
+ }
+
render() {
const state = this.state;
const players_total = 1 + state.other_players.length;
/>;
}
+ if (! state.ready)
+ return null;
+
return [
<GameInfo
key="game-info"