-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from ThePhoenix08/responsive-2
Made App Responsive and Dynamic
- Loading branch information
Showing
14 changed files
with
524 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.game-layout { | ||
display: flex; | ||
flex-direction: column; | ||
padding: 20px; | ||
gap: 10px; | ||
} | ||
|
||
.game-layout > .middle-panel { | ||
display: flex; | ||
gap: 10px; | ||
} | ||
|
||
.game-layout > .panel-area, | ||
.game-layout > .middle-panel > .panel-area { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
|
||
.middle-panels > .player-panel { | ||
writing-mode: vertical-rl; | ||
height: calc(var(--tile-size) * 8); | ||
width: 0.5vw; | ||
padding: 0 12px; | ||
} | ||
|
||
.game-layout > .panel-area > .player-panel { | ||
height: 0.5vw; | ||
width: calc(var(--tile-size) * 8); | ||
padding: 12px 0; | ||
} | ||
|
||
div#left-panel { | ||
transform: rotate(-180deg); | ||
} | ||
|
||
.player-panel { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: calc(var(--tile-size) * 0.1); | ||
} | ||
|
||
.game-display { | ||
display: none; | ||
} | ||
|
||
@media all and (max-width: 700px) { | ||
/* phone styles here */ | ||
.game-layout { | ||
padding: 4vh 4vw; | ||
} | ||
|
||
.player-panel > .player-name { | ||
display: none; | ||
} | ||
|
||
.middle-panels > .player-panel { | ||
padding: 0; | ||
width: 5px; | ||
border-radius: 1px; | ||
} | ||
|
||
.game-layout > .panel-area > .player-panel { | ||
padding: 0; | ||
height: 5px; | ||
border-radius: 1px; | ||
} | ||
|
||
.game-display { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.game-display > .currentPlayerDisplay { | ||
color: var(--secondary-text-color); | ||
padding: 2px 10px; | ||
border-radius: calc(1rem + 2px); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import './ChessWrapper.css' | ||
import { useChessContext } from '../context/ChessContext' | ||
import { TeamType } from '../../Types' | ||
|
||
type PlayerState = 'active' | 'inactive' | 'lost'; | ||
|
||
/** Wrapper component for the chess board, holds player panels surrounding the board */ | ||
export default function ChessWrapper({ | ||
children, | ||
loseOrder: lostTeams, | ||
}: { | ||
children: React.ReactNode; | ||
loseOrder: TeamType[]; | ||
}) { | ||
const { currentPlayer } = useChessContext(); | ||
const players = [ | ||
{ name: "Red Player", color: "red", id: "r" }, | ||
{ name: "Blue Player", color: "blue", id: "b" }, | ||
{ name: "Yellow Player", color: "yellow", id: "y" }, | ||
{ name: "Green Player", color: "green", id: "g" }, | ||
]; | ||
|
||
const getPlayerState = (playerId: TeamType): PlayerState => { | ||
if (lostTeams.includes(playerId)) return 'lost' | ||
return currentPlayer === playerId ? 'active' : 'inactive' | ||
} | ||
|
||
const displayBgColor = players.find((p) => p.id === currentPlayer)?.color || 'grey'; | ||
|
||
return ( | ||
<div className='chess-wrapper'> | ||
<div className='game-display'> | ||
<div | ||
className='currentPlayerDisplay' | ||
style={{ backgroundColor: displayBgColor }} | ||
> | ||
{players.find((p) => p.id === currentPlayer)?.name} | ||
</div> | ||
</div> | ||
<div className='game-layout'> | ||
<div className='panel-area'> | ||
<PlayerPanel | ||
name='Yellow Player' | ||
color='yellow' | ||
playerState={getPlayerState(TeamType.YELLOW)} | ||
/> | ||
</div> | ||
<div className='middle-panel'> | ||
<div className='panel-area middle-panels' id='left-panel'> | ||
<PlayerPanel | ||
name='Blue Player' | ||
color='blue' | ||
playerState={getPlayerState(TeamType.BLUE)} | ||
/> | ||
</div> | ||
<div className='panel-area chessboard-container'>{children}</div> | ||
<div className='panel-area middle-panels'> | ||
<PlayerPanel | ||
name='Green Player' | ||
color='green' | ||
playerState={getPlayerState(TeamType.GREEN)} | ||
/> | ||
</div> | ||
</div> | ||
<div className='panel-area'> | ||
<PlayerPanel | ||
name='Red Player' | ||
color='red' | ||
playerState={getPlayerState(TeamType.RED)} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
interface PlayerPanelProps { | ||
name: string | ||
color: string | ||
playerState: PlayerState | ||
} | ||
|
||
/** Player panel component, holds player name and indicates active player */ | ||
function PlayerPanel({ name, color, playerState }: PlayerPanelProps) { | ||
const stateToColorMap = { | ||
active: color, | ||
inactive: 'grey', | ||
lost: '#444', | ||
} | ||
|
||
return ( | ||
<div | ||
className={`player-panel ${playerState === 'active' ? 'active' : ''}`} | ||
style={{ | ||
backgroundColor: stateToColorMap[playerState], | ||
color: playerState === 'lost' ? "#eee" : "black" | ||
}} | ||
> | ||
<div className='player-name'>{`${name} ${playerState === 'lost' ? 'lost' : ''}`}</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.