Skip to content

Commit db21d20

Browse files
Merge pull request #256 from CSSLab/codex/material-count-size-tuning
fix: tune chess material display
2 parents 51fc1d4 + c3bcda7 commit db21d20

4 files changed

Lines changed: 75 additions & 44 deletions

File tree

src/components/Board/GameBoard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ export const GameBoard: React.FC<Props> = ({
141141
return {
142142
fen,
143143
lastMove,
144-
check: currentNode.check,
144+
check: currentNode.check
145+
? (currentNode.turn === 'w' ? 'white' : 'black')
146+
: false,
145147
orientation: orientation as 'white' | 'black',
146148
}
147149
}, [currentNode, game, orientation])

src/components/Board/GameClock.tsx

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,24 +60,47 @@ export const GameClock: React.FC<Props> = (
6060

6161
return (
6262
<div
63-
className={`flex items-center justify-between bg-glass-strong md:items-start md:justify-start ${active ? 'opacity-100' : 'opacity-50'} flex-row md:flex-col`}
63+
className="flex flex-row items-center justify-between bg-glass-strong md:flex-col md:items-start md:justify-start"
6464
>
6565
<div className="flex w-full items-center justify-between gap-3 px-4 py-2">
66-
<span>
67-
{props.player === 'black' ? '●' : '○'}{' '}
68-
{player === props.player
69-
? user?.displayName
70-
: getMaiaDisplayName(maiaVersion)}
66+
<span
67+
className={`flex items-center gap-2 transition-colors ${
68+
active ? 'text-white' : 'text-white/55'
69+
}`}
70+
>
71+
<span
72+
className={`inline-block h-3 w-3 rounded-full ${
73+
props.player === 'white'
74+
? 'bg-white ring-1 ring-white/70'
75+
: 'bg-black ring-1 ring-white/35'
76+
} ${active ? 'animate-pulse ring-2 ring-primary/35' : ''}`}
77+
/>
78+
<span>
79+
{player === props.player
80+
? user?.displayName
81+
: getMaiaDisplayName(maiaVersion)}
82+
</span>
7183
</span>
7284
<MaterialBalance
7385
fen={currentNode?.fen}
7486
color={props.player}
75-
className="gap-1.5"
76-
iconClassName="!text-base md:!text-lg text-white/85"
77-
textClassName="text-sm md:text-base text-white/85"
87+
className="gap-2"
88+
iconClassName="!text-xl md:!text-2xl text-white/95"
89+
textClassName="text-base md:text-lg text-white/90"
90+
pieceFilter={
91+
props.player === 'black'
92+
? 'brightness(1.18) contrast(1.08)'
93+
: undefined
94+
}
7895
/>
7996
</div>
80-
<div className="inline-flex self-start px-4 py-2 md:text-3xl">
97+
<div
98+
className={`inline-flex self-start px-4 py-2 transition-all duration-200 md:text-3xl ${
99+
active
100+
? 'font-semibold text-primary'
101+
: 'text-white/55'
102+
}`}
103+
>
81104
{minutes}:{('00' + seconds).slice(-2)}
82105
{showTenths ? '.' + tenths : null}
83106
</div>

src/components/Common/MaterialBalance.tsx

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ const STARTING_MATERIAL: { white: MaterialCount; black: MaterialCount } = {
2121
black: { p: 8, n: 2, b: 2, r: 2, q: 1, k: 1 },
2222
}
2323

24-
const getPieceIcon = (piece: PieceType): string => {
25-
const iconMap: Record<PieceType, string> = {
26-
p: 'chess_pawn',
27-
n: 'chess_knight',
28-
b: 'chess_bishop',
29-
r: 'chess_rook',
30-
q: 'chess',
31-
k: 'chess',
24+
const getPieceLabel = (piece: PieceType): string => {
25+
const labelMap: Record<PieceType, string> = {
26+
p: 'pawn',
27+
n: 'knight',
28+
b: 'bishop',
29+
r: 'rook',
30+
q: 'queen',
31+
k: 'king',
3232
}
3333

34-
return iconMap[piece]
34+
return labelMap[piece]
3535
}
3636

37-
const getPieceLabel = (piece: PieceType): string => {
38-
const labelMap: Record<PieceType, string> = {
37+
const getPieceSpriteClass = (piece: PieceType): string => {
38+
const spriteMap: Record<PieceType, string> = {
3939
p: 'pawn',
4040
n: 'knight',
4141
b: 'bishop',
@@ -44,7 +44,7 @@ const getPieceLabel = (piece: PieceType): string => {
4444
k: 'king',
4545
}
4646

47-
return labelMap[piece]
47+
return spriteMap[piece]
4848
}
4949

5050
const calculateCapturedPieces = (fen: string) => {
@@ -113,12 +113,14 @@ export const MaterialBalance = ({
113113
className = '',
114114
iconClassName = '',
115115
textClassName = '',
116+
pieceFilter,
116117
}: {
117118
fen?: string
118119
color: Color
119120
className?: string
120121
iconClassName?: string
121122
textClassName?: string
123+
pieceFilter?: string
122124
}) => {
123125
const materialData = useMemo(() => {
124126
if (!fen) {
@@ -166,10 +168,12 @@ export const MaterialBalance = ({
166168
return null
167169
}
168170

169-
const capturedPieceToneClass =
170-
color === 'white'
171-
? 'text-zinc-900 [text-shadow:0_0_1px_rgba(255,255,255,0.95)]'
172-
: 'text-white [text-shadow:0_0_1px_rgba(0,0,0,0.9)]'
171+
const capturedPieceColor = color === 'white' ? 'black' : 'white'
172+
const capturedPieceFilter =
173+
pieceFilter ??
174+
capturedPieceColor === 'black'
175+
? 'drop-shadow(0 0 0.8px rgba(255,255,255,0.82)) drop-shadow(0 0 1.5px rgba(255,255,255,0.28))'
176+
: 'drop-shadow(0 0 0.8px rgba(0,0,0,0.82)) drop-shadow(0 0 1.5px rgba(0,0,0,0.22))'
173177

174178
return (
175179
<div className={`flex select-none items-center gap-1 ${className}`.trim()}>
@@ -186,23 +190,25 @@ export const MaterialBalance = ({
186190
{Array.from({ length: count }).map((_, index) => (
187191
<span
188192
key={`${piece}-${index}`}
189-
className={`material-symbols-outlined material-symbols-filled text-sm ${capturedPieceToneClass} ${index > 0 ? '-ml-1.5' : ''} ${iconClassName}`.trim()}
193+
className={`cg-wrap !relative !inline-block !h-[1em] !w-[1em] align-middle ${
194+
index > 0 ? '-ml-1.5' : ''
195+
} ${iconClassName}`.trim()}
190196
title={getPieceLabel(piece)}
191197
>
192-
{getPieceIcon(piece)}
198+
<piece
199+
className={`${getPieceSpriteClass(piece)} ${capturedPieceColor}`}
200+
style={{
201+
width: '100%',
202+
height: '100%',
203+
filter: capturedPieceFilter,
204+
}}
205+
/>
193206
</span>
194207
))}
195208
</div>
196209
)
197210
})}
198211
</div>
199-
{materialData.advantage > 0 && (
200-
<span
201-
className={`text-xxs font-medium text-secondary ${textClassName}`.trim()}
202-
>
203-
+{materialData.advantage}
204-
</span>
205-
)}
206212
</div>
207213
)
208214
}

src/pages/analysis/[...id].tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,8 +1604,8 @@ const Analysis: React.FC<Props> = ({
16041604
fen={controller.currentNode?.fen}
16051605
color="white"
16061606
className="whitespace-nowrap"
1607-
iconClassName="!text-[12px]"
1608-
textClassName="text-[11px] text-white/85"
1607+
iconClassName="!text-[18px]"
1608+
textClassName="text-[14px] text-white/90"
16091609
/>
16101610
</div>
16111611
<AnalysisArrowLegend
@@ -1617,8 +1617,8 @@ const Analysis: React.FC<Props> = ({
16171617
fen={controller.currentNode?.fen}
16181618
color="black"
16191619
className="whitespace-nowrap"
1620-
iconClassName="!text-[12px]"
1621-
textClassName="text-[11px] text-white/85"
1620+
iconClassName="!text-[18px]"
1621+
textClassName="text-[14px] text-white/90"
16221622
/>
16231623
</div>
16241624
</div>
@@ -1893,8 +1893,8 @@ const Analysis: React.FC<Props> = ({
18931893
fen={controller.currentNode?.fen}
18941894
color="white"
18951895
className="whitespace-nowrap"
1896-
iconClassName="!text-[11px]"
1897-
textClassName="text-[10px] text-primary/75"
1896+
iconClassName="!text-[13px]"
1897+
textClassName="text-[11px] text-primary/80"
18981898
/>
18991899
</div>
19001900
<AnalysisArrowLegend
@@ -1906,8 +1906,8 @@ const Analysis: React.FC<Props> = ({
19061906
fen={controller.currentNode?.fen}
19071907
color="black"
19081908
className="whitespace-nowrap"
1909-
iconClassName="!text-[11px]"
1910-
textClassName="text-[10px] text-primary/75"
1909+
iconClassName="!text-[13px]"
1910+
textClassName="text-[11px] text-primary/80"
19111911
/>
19121912
</div>
19131913
</div>

0 commit comments

Comments
 (0)