Skip to content

Commit

Permalink
Frontend: Display Player names along with cards
Browse files Browse the repository at this point in the history
1. The Player component was refactored to separate JSX for rendering player cards.

2. Highlighting functionality was added to indicate the current player's turn.

3. Player names were styled to appear in a white box with black text.

4. Brightness adjustment was applied to highlight the active player.

Fixes #158
  • Loading branch information
kuv2707 authored and asmit27rai committed Jun 28, 2024
1 parent db09ad5 commit c207aca
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ export function catchError(fn: ControllerFunction): ControllerFunction {
res.status(500).json({ error: (error as Error).message });
}
};
}
}
48 changes: 48 additions & 0 deletions frontend/src/library/Player.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';

interface Player {
name: string;
cards: { length: number };
}

interface PlayerProps {
player: Player;
highlighted: boolean;
positionStyle: React.CSSProperties;
}

const Player: React.FC<PlayerProps> = ({
player,
highlighted,
positionStyle,
}) => {
return (
<div
className="absolute flex flex-col items-center justify-center bg-player-icon-bg"
style={{
...positionStyle,
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
width: '70px',
height: '80px',
zIndex: 2,
filter: highlighted ? 'brightness(1.5)' : 'none',
}}
>
<div
className="player-cards font-[Kavoon] text-gray-900 mt-[96px] text-[12px]"
style={{ marginLeft: '-8px' }}
>
{player.cards.length}
</div>
<div
className="player-name font-[Kavoon] mb-2 text-[14px] text-black bg-gray-400 rounded-lg shadow-md"
style={{ marginLeft: '-8px' }}
>
{player.name}
</div>
</div>
);
};

export default Player;
29 changes: 6 additions & 23 deletions frontend/src/pages/Game.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useNavigate } from 'react-router-dom';
import { triggerEvent } from '../channel';
import { useAuth } from '../contexts/AuthContext';
import { useToast } from '../library/toast/toast-context';
import Player from '../library/Player';

function getCardImageName(card: UNOCard): string {
function getColorAbbreviation(color: CardColor): string {
Expand Down Expand Up @@ -173,10 +174,6 @@ function Game() {
{ top: '75%', left: '85%', transform: 'translate(-50%, -50%)' },
];

const cardStyles = {
filter: 'brightness(1)',
};

if (!gameState) {
return (
<div className="bg-gray-800 h-screen text-white text-5xl font-kavoon text-center">
Expand All @@ -199,26 +196,12 @@ function Game() {
</div>
{/* Players */}
{gameState.players.slice(0, 6).map((player, index) => (
<div
<Player
key={index}
className={`absolute flex flex-col items-center justify-center bg-player-icon-bg`}
style={{
...playerPositions[index],
backgroundSize: 'contain',
backgroundRepeat: 'no-repeat',
width: '70px',
height: '80px',
zIndex: 2,
...(index === gameState.currentPlayerIndex && {
...cardStyles,
filter: 'brightness(1.5)',
}),
}}
>
<div className="player-cards text-black mt-[61px]">
{player.cards.length}
</div>
</div>
player={player}
highlighted={index === gameState.currentPlayerIndex}
positionStyle={playerPositions[index]}
/>
))}

{/* Center Deck and UNO Button */}
Expand Down

0 comments on commit c207aca

Please sign in to comment.