feat(ui): modified-piece indicator on board
This commit is contained in:
parent
0bd65e0a73
commit
d555232696
2 changed files with 53 additions and 22 deletions
|
|
@ -13,6 +13,7 @@ import {
|
|||
type SquareOverlayComponent,
|
||||
} from './preset-overlays';
|
||||
import { VisualEffectLayer } from './VisualEffectLayer';
|
||||
import { ModifiedPieceIndicator } from './ModifiedPieceIndicator.js';
|
||||
import '../presets/ui-overlays-index';
|
||||
|
||||
interface BoardProps {
|
||||
|
|
@ -327,28 +328,33 @@ export function Board({ facts, legalMoves, onMove, turn, myColor, lastMove, chec
|
|||
* FLIP clean.
|
||||
*/}
|
||||
{piece && (
|
||||
<div
|
||||
key={piece.id}
|
||||
className="absolute inset-0 z-20"
|
||||
onMouseEnter={() => onPieceHover?.(piece.id)}
|
||||
onMouseLeave={() => onPieceHover?.(null)}
|
||||
onClick={() => onPieceClick?.(piece.id)}
|
||||
>
|
||||
<Piece
|
||||
color={piece.color}
|
||||
type={piece.type}
|
||||
pieceId={piece.id}
|
||||
square={sq}
|
||||
isDraggable={
|
||||
piece.color === turn &&
|
||||
(myColor === null || myColor === undefined || piece.color === myColor)
|
||||
}
|
||||
overlays={overlays}
|
||||
pieceFacts={factsById.get(piece.id) ?? []}
|
||||
onDragStart={handleDragStart}
|
||||
onDragEnd={handleDragEnd}
|
||||
/>
|
||||
</div>
|
||||
<>
|
||||
<div
|
||||
key={piece.id}
|
||||
className="absolute inset-0 z-20"
|
||||
onMouseEnter={() => onPieceHover?.(piece.id)}
|
||||
onMouseLeave={() => onPieceHover?.(null)}
|
||||
onClick={() => onPieceClick?.(piece.id)}
|
||||
>
|
||||
<Piece
|
||||
color={piece.color}
|
||||
type={piece.type}
|
||||
pieceId={piece.id}
|
||||
square={sq}
|
||||
isDraggable={
|
||||
piece.color === turn &&
|
||||
(myColor === null || myColor === undefined || piece.color === myColor)
|
||||
}
|
||||
overlays={overlays}
|
||||
pieceFacts={factsById.get(piece.id) ?? []}
|
||||
onDragStart={handleDragStart}
|
||||
onDragEnd={handleDragEnd}
|
||||
/>
|
||||
</div>
|
||||
{engine !== undefined && (
|
||||
<ModifiedPieceIndicator pieceId={piece.id} engine={engine} />
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Rank/File labels (optional but helpful for debug) */}
|
||||
|
|
|
|||
25
packages/chess/src/ui/ModifiedPieceIndicator.tsx
Normal file
25
packages/chess/src/ui/ModifiedPieceIndicator.tsx
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { MODIFIER_REGISTRY } from '../modifiers/registry';
|
||||
import type { ChessEngine } from '../engine';
|
||||
import type { EntityId } from '@paratype/rete';
|
||||
|
||||
interface Props {
|
||||
pieceId: number;
|
||||
engine: ChessEngine;
|
||||
}
|
||||
|
||||
export function ModifiedPieceIndicator({ pieceId, engine }: Props) {
|
||||
const isModified = MODIFIER_REGISTRY.list().some((descriptor) => {
|
||||
return engine.session.get(pieceId as unknown as EntityId, descriptor.attrName) !== undefined;
|
||||
});
|
||||
|
||||
if (!isModified) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
data-testid={`modifier-indicator-${pieceId}`}
|
||||
className="absolute top-1 right-1 w-2 h-2 bg-fuchsia-500 rounded-full ring-1 ring-white shadow-sm pointer-events-none z-30"
|
||||
/>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue