summaryrefslogtreecommitdiff
path: root/frontend/src
diff options
context:
space:
mode:
authorJoffrey BION <joffrey.bion@gmail.com>2018-06-12 00:36:08 +0200
committerJoffrey BION <joffrey.bion@gmail.com>2018-06-12 00:36:08 +0200
commit510c4cfeb666ab385e7200e1ac243fc6ed31043b (patch)
treecff1f46d81481df614f17adbd1121cf0fa09ef53 /frontend/src
parentUse radial list for lobby (diff)
downloadseven-wonders-510c4cfeb666ab385e7200e1ac243fc6ed31043b.tar.gz
seven-wonders-510c4cfeb666ab385e7200e1ac243fc6ed31043b.tar.bz2
seven-wonders-510c4cfeb666ab385e7200e1ac243fc6ed31043b.zip
Place current player always at the bottom
Diffstat (limited to 'frontend/src')
-rw-r--r--frontend/src/components/lobby/RadialPlayerList.jsx20
1 files changed, 14 insertions, 6 deletions
diff --git a/frontend/src/components/lobby/RadialPlayerList.jsx b/frontend/src/components/lobby/RadialPlayerList.jsx
index c3dd988e..0a148c78 100644
--- a/frontend/src/components/lobby/RadialPlayerList.jsx
+++ b/frontend/src/components/lobby/RadialPlayerList.jsx
@@ -21,7 +21,7 @@ const PlayerItem = ({player, isOwner, isUser}) => (
);
const PlayerPlaceholder = () => (
- <Flex column align='center' style={{opacity: 0.4}}>
+ <Flex column align='center' style={{opacity: 0.3}}>
<UserIcon isOwner={false} isUser={false}/>
<h5 style={{margin: 0}}>?</h5>
</Flex>
@@ -35,12 +35,13 @@ const UserIcon = ({isUser, isOwner}) => {
};
export const RadialPlayerList = ({players, owner, currentPlayer}: RadialPlayerListProps) => {
- const playerItems = players.map(player => <PlayerItem key={player.username}
- player={player}
- isOwner={player.username === owner}
- isUser={player.username === currentPlayer.username}/>);
+ const orderedPlayers = placeFirst(players.toArray(), currentPlayer.username);
+ const playerItems = orderedPlayers.map(player => <PlayerItem key={player.username}
+ player={player}
+ isOwner={player.username === owner}
+ isUser={player.username === currentPlayer.username}/>);
const tableImg = <img src={roundTable} alt='Round table' style={{width: 200, height: 200}}/>;
- return <RadialList items={completeWithPlaceholders(playerItems.toArray())}
+ return <RadialList items={completeWithPlaceholders(playerItems)}
centerElement={tableImg}
diameter={350}
offsetDegrees={180}
@@ -48,6 +49,13 @@ export const RadialPlayerList = ({players, owner, currentPlayer}: RadialPlayerLi
itemHeight={100}/>;
};
+function placeFirst(players: Array<Player>, targetFirstUsername: string): Array<Player> {
+ while (players[0].username !== targetFirstUsername) {
+ players.push(players.shift());
+ }
+ return players;
+}
+
function completeWithPlaceholders(playerItems: Array<React.Node>): Array<React.Node> {
while (playerItems.length < 3) {
playerItems.push(<PlayerPlaceholder/>);
bgstack15