Skip to content

Commit

Permalink
Merge pull request #3 from GabrielCTroia/preview/fix-flag-insufficient
Browse files Browse the repository at this point in the history
Preview/fix flag insufficient
  • Loading branch information
GabrielCTroia authored Dec 20, 2024
2 parents a817775 + 8a6aa03 commit d5a4dfd
Show file tree
Hide file tree
Showing 55 changed files with 873 additions and 564 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
isBlackColor,
objectKeys,
pieceSanToFenBoardPieceSymbol,
toShortColor,
} from '@xmatter/util-kit';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
Expand Down Expand Up @@ -143,7 +142,7 @@ export const BoardEditor = ({
}>();

const extraPiecesLayout = useMemo(() => {
if (toShortColor(props.boardOrientation || 'w') === 'w') {
if (props.boardOrientation || 'w' === 'w') {
return {
top: blackPieces.map(renderPiece),
bottom: whitePieces.map(renderPiece),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
ShortChessMove,
getNewChessGame,
swapColor,
toShortColor,
} from '@xmatter/util-kit';
import { useEffect, useState } from 'react';
import { Playboard } from './Playboard';
Expand Down Expand Up @@ -61,7 +60,7 @@ export const Main: Story = {
setState((prev) => ({
...prev,
fen: nextFen,
turn: toShortColor(swapColor(state.turn)),
turn: swapColor(state.turn),
}));
}}
/>
Expand Down Expand Up @@ -174,7 +173,7 @@ export const CheckPromotion: Story = {
setState((prev) => ({
...prev,
fen: nextFen,
turn: toShortColor(swapColor(state.turn)),
turn: swapColor(state.turn),
}));
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
ChessFENBoard,
DistributiveOmit,
ShortChessMove,
toShortColor,
} from '@xmatter/util-kit';
import {
ChessboardContainer,
Expand Down Expand Up @@ -34,7 +33,7 @@ export type PlayboardProps = DistributiveOmit<
export const Playboard = ({
fen = ChessFENBoard.STARTING_FEN,
playingColor,
boardOrientation = toShortColor(playingColor),
boardOrientation = playingColor,
onMove,
canPlay = false,
turn,
Expand All @@ -53,15 +52,15 @@ export const Playboard = ({
return false;
}

return validateMove(move, fen, toShortColor(playingColor)).valid;
return validateMove(move, fen, playingColor).valid;
},
[canPlay, turn, fen, playingColor]
);

return (
<ChessboardContainer
strict
turn={toShortColor(turn)}
turn={turn}
fen={fen}
boardOrientation={boardOrientation}
boardTheme={boardTheme}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
ChessFEN,
PieceSan,
ShortChessMove,
ShortChessColor,
toLongColor,
ChessColor,
} from '@xmatter/util-kit';
import { Square } from 'chess.js';
import { useArrowAndCircleColor } from '../hooks/useArrowAndCircleColor';
Expand Down Expand Up @@ -37,7 +36,7 @@ export type ChessboardContainerProps = Omit<
circlesMap?: CirclesMap;
arrowColor?: string;
lastMove?: ShortChessMove;
boardOrientation?: ShortChessColor;
boardOrientation?: ChessColor;
containerClassName?: string;

onPieceDrop?: (from: Square, to: Square, piece: PieceSan) => void;
Expand All @@ -62,11 +61,11 @@ export type ChessboardContainerProps = Omit<
| {
// When this is true the player can only touch the pieces on her side
strict: true;
turn: ShortChessColor;
turn: ChessColor;
}
| {
strict?: false;
turn?: ShortChessColor;
turn?: ChessColor;
}
);

Expand Down Expand Up @@ -155,7 +154,7 @@ export const ChessboardContainer: React.FC<ChessboardContainerProps> = ({
fen={fen}
sizePx={sizePx}
boardTheme={boardTheme}
boardOrientation={toLongColor(boardOrientation)}
boardOrientation={boardOrientation}
// Moves
onPieceDragBegin={moveActions.onPieceDrag}
onSquareClick={moveActions.onSquareClick}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {
ChessColor,
ChessFEN,
ShortChessMove,
promotionalPieceSanToFenBoardPromotionalPieceSymbol,
toLongChessColor,
} from '@xmatter/util-kit';
import { ReactChessBoardProps } from './types';
import { BoardTheme } from '@app/hooks/useTheme/defaultTheme';
import { Chessboard as ReactChessboard } from 'react-chessboard';
import { PromotionDialogLayer } from './PromotionDialogLayer';

export type ChessboardDisplayProps = Omit<ReactChessBoardProps, 'fen'> & {
export type ChessboardDisplayProps = Omit<
ReactChessBoardProps,
'fen' | 'boardOrientation'
> & {
fen: ChessFEN;
sizePx: number;
boardTheme: BoardTheme;
Expand All @@ -20,6 +25,7 @@ export type ChessboardDisplayProps = Omit<ReactChessBoardProps, 'fen'> & {

containerClassName?: string;
overlayComponent?: React.ReactNode;
boardOrientation?: ChessColor;
} & (
| {
rightSideComponent: React.ReactNode;
Expand All @@ -41,7 +47,7 @@ export const ChessboardDisplay = ({
containerClassName,
overlayComponent,
fen,
boardOrientation = 'white',
boardOrientation = 'w',
promoMove,
boardTheme,
onCancelPromoMove,
Expand Down Expand Up @@ -69,7 +75,7 @@ export const ChessboardDisplay = ({
position={fen}
boardWidth={sizePx}
showBoardNotation
boardOrientation={boardOrientation}
boardOrientation={toLongChessColor(boardOrientation)}
snapToCursor={false}
arePiecesDraggable
{...boardProps}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
isBlackColor,
objectKeys,
squareToBoardCoards,
toShortColor,
} from '@xmatter/util-kit';
import { Square } from 'chess.js';
import React, { useMemo } from 'react';
Expand Down Expand Up @@ -51,7 +50,7 @@ export const PromotionDialogLayer: React.FC<PromotionDialogLayerProps> = ({
const promotingColor: ShortChessColor =
Number(promotionSquare[1]) === 1 ? 'b' : 'w';

const isFlipped = promotingColor !== toShortColor(boardOrientation);
const isFlipped = promotingColor !== boardOrientation;

const dialogHorizontalPosition = useMemo(() => {
const rawCoords = squareToBoardCoards(promotionSquare);
Expand All @@ -74,7 +73,7 @@ export const PromotionDialogLayer: React.FC<PromotionDialogLayerProps> = ({
asset: promotablePiecesMapWithDisplayOrder[san],
} as const)
)
.filter((p) => toShortColor(p.color) === promotingColor)
.filter((p) => p.color === promotingColor)
.sort(
(a, b) =>
promotablePiecesMapWithDisplayOrder[a.san] -
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { createContext } from 'react';
import {
ChessColor,
FBHIndex,
FreeBoardHistory,
LongChessColor,
noop,
} from '@xmatter/util-kit';
import { UserId, UsersMap } from '@app/modules/User';
Expand All @@ -12,7 +12,7 @@ import { initialPlayState } from '@app/modules/Match/Play/store';
export type GameContextProps = {
displayState: GameDisplayState;
committedState: {
turn: LongChessColor;
turn: ChessColor;
game: Game;
};
actions: {
Expand All @@ -28,10 +28,10 @@ export const initialGameContextState: GameContextProps = {
fen: '',
history: [],
focusedIndex: FreeBoardHistory.getStartingIndex(),
turn: 'white',
turn: 'w',
},
committedState: {
turn: 'white',
turn: 'w',
game: initialPlayState,
},
actions: {
Expand Down
9 changes: 4 additions & 5 deletions apps/chessroulette-web/modules/Game/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import {
ChessColor,
ChessFEN,
ChessFENBoard,
ChessPGN,
FBHHistory,
FBHIndex,
FreeBoardHistory,
LongChessColor,
pgnToFen,
toLongColor,
} from '@xmatter/util-kit';
import { GameDisplayState } from '../types';

Expand Down Expand Up @@ -56,8 +55,8 @@ export const getGameDisplayState = ({
};
};

export const getTurnFromPgn = (pgn: ChessPGN): LongChessColor =>
export const getTurnFromPgn = (pgn: ChessPGN): ChessColor =>
getTurnFromFen(pgnToFen(pgn));

export const getTurnFromFen = (fen: ChessFEN): LongChessColor =>
toLongColor(new ChessFENBoard(fen).getFenState().turn);
export const getTurnFromFen = (fen: ChessFEN): ChessColor =>
new ChessFENBoard(fen).getFenState().turn;
4 changes: 2 additions & 2 deletions apps/chessroulette-web/modules/Game/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const createPendingGame = ({
timeClass,
timeLeft: {
lastUpdatedAt: null,
white: timeLeft,
black: timeLeft,
w: timeLeft,
b: timeLeft,
},
players,
};
Expand Down
10 changes: 5 additions & 5 deletions apps/chessroulette-web/modules/Game/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export const PENDING_UNTIMED_GAME: PendingGame = {
pgn: '',
timeLeft: {
lastUpdatedAt: null,
white: 0,
black: 0,
w: 0,
b: 0,
},
lastMoveBy: 'black',
lastMoveBy: 'b',
lastMoveAt: null,
timeClass: 'untimed',
gameOverReason: null,
Expand All @@ -19,7 +19,7 @@ export const PENDING_UNTIMED_GAME: PendingGame = {
offers: [],

players: {
white: 'N/A',
black: 'N/A',
w: 'N/A',
b: 'N/A',
},
};
Loading

0 comments on commit d5a4dfd

Please sign in to comment.