Fix turnColor handling

This commit is contained in:
Marco 2023-12-25 18:08:21 +01:00
parent ba947ae5e4
commit 289ec6db26
4 changed files with 13 additions and 8 deletions

View File

@ -27,7 +27,7 @@ class ChessApp extends StatelessWidget {
useMaterial3: true,
),
routerConfig: ChessAppRouter.getInstance().router,
title: 'mChess 0.1339',
title: 'mChess 0.1.1340',
),
);
}

View File

@ -75,6 +75,8 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
.recordMove(event.startSquare, event.endSquare, event.position);
}
turnColor = event.turnColor;
emit(
ChessBoardState(
state.bottomColor,

View File

@ -8,12 +8,14 @@ class ReceivedBoardState extends ChessEvent {
final ChessCoordinate? endSquare;
final ChessPosition position;
final ChessCoordinate squareInCheck;
final ChessColor turnColor;
ReceivedBoardState({
required this.startSquare,
required this.endSquare,
required this.position,
required this.squareInCheck,
required this.turnColor,
});
}

View File

@ -99,13 +99,14 @@ class ServerConnection {
if (apiMessage.position != null) {
ChessBloc.getInstance().add(
ReceivedBoardState(
startSquare: move?.from,
endSquare: move?.to,
position: ChessPositionManager.getInstance()
.fromPGNString(apiMessage.position!),
squareInCheck: ChessCoordinate.fromApiCoordinate(
apiMessage.squareInCheck ?? const ApiCoordinate(col: 0, row: 0)),
),
startSquare: move?.from,
endSquare: move?.to,
position: ChessPositionManager.getInstance()
.fromPGNString(apiMessage.position!),
squareInCheck: ChessCoordinate.fromApiCoordinate(
apiMessage.squareInCheck ??
const ApiCoordinate(col: 0, row: 0)),
turnColor: ChessColor.fromApiColor(apiMessage.turnColor!)),
);
} else {
log('Error: no position received');