Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend: Display Player names along with cards #171

Merged
merged 1 commit into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Frontend: Display Player names along with cards
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
kuv2707 authored and asmit27rai committed Jun 28, 2024
commit ad1c831f8cfc57407e1bd664a140183a720d155b
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
@@ -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 {
@@ -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">
@@ -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 */}