From 4722b4507daf42d6e0799dc6e7ae7a681ee5aebb Mon Sep 17 00:00:00 2001 From: ntr Date: Sat, 8 Jun 2019 16:15:44 +1000 Subject: [PATCH] scoreboard --- WORKLOG.md | 4 +- client/src/components/info.component.jsx | 11 ++-- client/src/components/instance.component.jsx | 55 +++----------------- client/src/components/scoreboard.jsx | 34 ++++++++++++ 4 files changed, 50 insertions(+), 54 deletions(-) create mode 100644 client/src/components/scoreboard.jsx diff --git a/WORKLOG.md b/WORKLOG.md index 3b79c1d5..74d6e680 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -41,8 +41,8 @@ do not allow vbox actions for finished instances *SERVER* -* std game mode - * time control + +* modify time controls to be optional * eth adapter * pay for rerolls diff --git a/client/src/components/info.component.jsx b/client/src/components/info.component.jsx index ba9dadb7..cdc6cb3b 100644 --- a/client/src/components/info.component.jsx +++ b/client/src/components/info.component.jsx @@ -5,13 +5,15 @@ const { INFO } = require('./../constants'); const { convertItem } = require('../utils'); const shapes = require('./shapes'); +const ScoreBoard = require('./scoreboard'); + function InfoComponent(args) { const { info, itemInfo, - combiner, player, + instance, } = args; function Info() { @@ -152,12 +154,13 @@ function InfoComponent(args) { ); } - // const beginningHdr = instance.phase === 'Lobby' - // ?

game beginning...

- // : null; + const scoreboard = instance.phase === 'Lobby' || info + ? null + : ; return (
+ {scoreboard}
diff --git a/client/src/components/instance.component.jsx b/client/src/components/instance.component.jsx index addc837a..859e80ab 100644 --- a/client/src/components/instance.component.jsx +++ b/client/src/components/instance.component.jsx @@ -5,12 +5,13 @@ const Vbox = require('./vbox.component'); const InfoContainer = require('./info.container'); const InstanceConstructsContainer = require('./instance.constructs'); const EquipmentContainer = require('./instance.equip'); +const ScoreBoard = require('./scoreboard'); const actions = require('../actions'); const addState = connect( function receiveState(state) { - const { ws, instance, nav } = state; + const { instance, nav } = state; return { instance, nav }; }, @@ -34,57 +35,15 @@ function Instance(args) { } = args; if (!instance) return false; - - function playerRound(id) { - if (!instance.rounds.length) return null; - return instance.rounds[instance.rounds.length - 1].find(r => r.player_ids.includes(id)); - } - - function playerText(p) { - const round = playerRound(p.id); - if (!round) { - return p.ready - ? 'ready' - : ''; - } - - if (round.finished) return 'finished'; - if (round.game_id) return 'in game'; - - return p.ready - ? 'ready' - : ''; - } - - function ScoreBoard() { - if (instance.phase === 'InProgress') return null; - - const players = instance.players.map((p, i) => { - const pText = playerText(p); - return ( - - {p.name} - {p.wins} / {p.losses} - {pText} - - ); - }); - - return ( - - - {players} - -
- ); - } - const instanceClasses = `instance ${nav === 'constructs' ? 'constructs-visible' : ''}`; + const lobbyInfo = (instance.phase === 'Lobby') + ? + : null; + return (
setInfo(null)} > - + {lobbyInfo} diff --git a/client/src/components/scoreboard.jsx b/client/src/components/scoreboard.jsx new file mode 100644 index 00000000..4fa55c04 --- /dev/null +++ b/client/src/components/scoreboard.jsx @@ -0,0 +1,34 @@ +const preact = require('preact'); +const { connect } = require('preact-redux'); + +const addState = connect( + function receiveState(state) { + const { instance } = state; + return { instance }; + }, +); + +function ScoreBoard(args) { + const { + instance, + } = args; + + const players = instance.players.map((p, i) => + + {p.name} + {p.wins} / {p.losses} + {p.ready ? 'ready' : ''} + + ); + + return ( + + + {players} + +
+ ); +} + +module.exports = addState(ScoreBoard);