Skip to content

Commit 68601f7

Browse files
authored
Merge pull request #39 from solbound-dev/change-player-list
Change player list
2 parents d85d49e + 1030de7 commit 68601f7

File tree

5 files changed

+107
-23
lines changed

5 files changed

+107
-23
lines changed

apps/web/src/components/Game/GameStatus.tsx

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,16 @@ import Button from '../Button';
44
import { useGame } from '../../providers/GameProvider';
55
import { useLocation } from 'wouter';
66
import DarkContainer from '../DarkContainer';
7-
import type { Player } from '../../utils/Player';
8-
import { useWallet } from '@solana/wallet-adapter-react';
7+
import PlayerTagContainer from '../PlayerTag';
98

109
const getColor = (time: number) => {
1110
if (time > 5000) return 'lightgreen';
1211
if (time > 2000) return 'orange';
1312
return 'red';
1413
};
1514

16-
const getTextDecoration = (p: Player, walletId: string | undefined) => {
17-
if (p.isDead) return 'line-through';
18-
if (p.walletId === walletId) return 'underline';
19-
return 'none';
20-
};
21-
2215
export const GameStatus = () => {
2316
const queryClient = useQueryClient();
24-
const { publicKey: walletId } = useWallet();
2517

2618
const {
2719
gameState,
@@ -93,20 +85,7 @@ export const GameStatus = () => {
9385
</Button>
9486
}
9587
</DarkContainer>
96-
<DarkContainer className={c.rightFixed}>
97-
{gameState?.players.map((p) => (
98-
<div
99-
key={p.walletId}
100-
style={{
101-
textDecoration: getTextDecoration(p, walletId?.toString()),
102-
fontSize: p.won ? '20px' : '16px',
103-
}}>
104-
{p.playerType} {p.walletId === walletId ? ' (you)' : ''} | {p.cards}{' '}
105-
/ 3{p.won && ' WON!'}
106-
</div>
107-
))}
108-
</DarkContainer>
109-
{/* </div> */}
88+
<PlayerTagContainer gameState={gameState} />
11089
</div>
11190
);
11291
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { Player, PlayerType } from '../../utils/Player';
2+
import astronautImg from '../../assets/astronaut2.png';
3+
import alienImg from '../../assets/alien2.png';
4+
import robotImg from '../../assets/robot2.png';
5+
import wizardImg from '../../assets/wizard2.png';
6+
import c from './style.module.css';
7+
import clsx from 'clsx';
8+
9+
type PlayerTagProps = {
10+
player: Player;
11+
};
12+
13+
const PlayerTag: React.FC<PlayerTagProps> = ({ player }) => {
14+
let image = astronautImg;
15+
if (player.playerType === PlayerType.Alien) {
16+
image = alienImg;
17+
}
18+
if (player.playerType === PlayerType.Robot) {
19+
image = robotImg;
20+
}
21+
if (player.playerType === PlayerType.Wizard) {
22+
image = wizardImg;
23+
}
24+
return (
25+
<div className={clsx(c.tagWrapper, { [c.grayscale]: player.isDead })}>
26+
<p className={c.text}>
27+
{player.playerType} {player.cards}/3
28+
</p>
29+
<div className={c.imageContainer}>
30+
<img className={c.image} src={image} alt='' />
31+
</div>
32+
</div>
33+
);
34+
};
35+
36+
export default PlayerTag;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import PlayerTag from './PlayerTag';
2+
import type { GameData } from '../../utils/GameData';
3+
import c from './style.module.css';
4+
5+
type PlayerTagContainerProps = {
6+
gameState: GameData | null | undefined;
7+
};
8+
9+
const PlayerTagContainer: React.FC<PlayerTagContainerProps> = ({
10+
gameState,
11+
}) => {
12+
return (
13+
<div className={c.container}>
14+
{gameState?.players.map((p) => (
15+
<PlayerTag key={p.walletId} player={p} />
16+
))}
17+
</div>
18+
);
19+
};
20+
21+
export default PlayerTagContainer;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import PlayerTagContainer from './PlayerTagContainer';
2+
3+
export default PlayerTagContainer;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.container {
2+
position: fixed;
3+
right: 12px;
4+
top: 20%;
5+
}
6+
7+
.tagWrapper {
8+
display: flex;
9+
right: 0;
10+
align-items: center;
11+
justify-content: flex-end;
12+
gap: 4px;
13+
margin-bottom: 4px;
14+
}
15+
16+
.text {
17+
color: #f2e2b7;
18+
font-family: 'Trebuchet MS', sans-serif;
19+
font-size: 20px;
20+
font-style: italic;
21+
font-weight: 200;
22+
line-height: 100%;
23+
text-align: right;
24+
margin: 0;
25+
}
26+
27+
.imageContainer {
28+
height: 50px;
29+
width: 50px;
30+
display: flex;
31+
justify-content: center;
32+
align-items: center;
33+
border-radius: 50%;
34+
border: 4px solid #f2e2b7;
35+
overflow: hidden;
36+
}
37+
38+
.image {
39+
max-width: 100%;
40+
max-height: 100%;
41+
}
42+
43+
.grayscale {
44+
filter: grayscale(100%);
45+
}

0 commit comments

Comments
 (0)