Skip to content

Commit cf2f894

Browse files
committed
games: Pass lastMove to chess for rendering
1 parent 7e78d8a commit cf2f894

4 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/ps/games/chess/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class Chess extends BaseGame<State> {
179179
showMoves: side === this.turn ? this.showMoves : [],
180180
selected: side === this.turn ? this.selected : null,
181181
isActive: side === this.turn,
182+
lastMove: this.lib.history({ verbose: true }).at(-1) ?? null,
182183
side,
183184
id: this.id,
184185
turn: this.turn!,

src/ps/games/chess/render.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Table } from '@/ps/games/render';
22
import { Button, Form } from '@/utils/components/ps';
33

4-
import type { RenderCtx, Turn } from '@/ps/games/chess/types';
4+
import type { RenderCtx } from '@/ps/games/chess/types';
55
import type { CellRenderer } from '@/ps/games/render';
66
import type { Chess, Square } from 'chess.js';
77
import type { ReactElement } from 'react';
@@ -51,7 +51,7 @@ export function renderBoard(this: This, ctx: RenderCtx) {
5151

5252
let overlay = 'none';
5353
if (action && ctx.theme.hl) overlay = ctx.theme.hl;
54-
// TODO: Last move
54+
else if (ctx.theme.last && (ctx.lastMove?.from === square || ctx.lastMove?.to === square)) overlay = ctx.theme.last;
5555

5656
const label = cell?.type ? `${cell.color}${cell.type}` : null;
5757

@@ -64,9 +64,11 @@ export function renderBoard(this: This, ctx: RenderCtx) {
6464
>
6565
{label ? <img src={PIECE_IMAGES[label]} height={size} width={size} alt={label} /> : null}
6666
</Button>
67-
) : label ? (
68-
<img src={PIECE_IMAGES[label]} height={size} width={size} alt={label} style={{ display: 'block' }} />
69-
) : null}
67+
) : (
68+
<div style={{ background: overlay, height: size, width: size, padding: 0 }}>
69+
{label ? <img src={PIECE_IMAGES[label]} height={size} width={size} alt={label} style={{ display: 'block' }} /> : null}
70+
</div>
71+
)}
7072
</td>
7173
);
7274
};

src/ps/games/chess/themes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const CHESS_THEMES: Record<string, Theme<ThemeColours>> = {
1313
B: '#9c5624',
1414
sel: '#87cefa',
1515
hl: '#adff2fa5',
16-
last: '#ff330019',
16+
last: '#ff3300180',
1717
},
1818
},
1919
snow: {
@@ -25,7 +25,7 @@ export const CHESS_THEMES: Record<string, Theme<ThemeColours>> = {
2525
B: '#ddd',
2626
sel: '#99e6e6',
2727
hl: '#c2ff6666',
28-
last: '#ff330016',
28+
last: '#ff330080',
2929
},
3030
},
3131
ocean: {

src/ps/games/chess/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export type RenderCtx = {
2020
id: string;
2121
side: Turn | null;
2222
turn: Turn;
23+
lastMove: Move | null;
2324
board: ReturnType<Chess['board']>;
2425
selected?: Square | null;
2526
isActive: boolean;

0 commit comments

Comments
 (0)