From 582fa872246af3654ee723da7186d3ace9f2f42f Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 9 Jan 2024 19:07:36 +0100 Subject: [PATCH] Fix the coloring of the last move after an invalid move was played. --- lib/chess/chess_board.dart | 2 +- lib/chess_bloc/chess_bloc.dart | 34 ++++++++++++-------------------- lib/chess_bloc/chess_events.dart | 12 ----------- pubspec.lock | 20 +++++++++---------- 4 files changed, 24 insertions(+), 44 deletions(-) diff --git a/lib/chess/chess_board.dart b/lib/chess/chess_board.dart index 4214b90..e375f6a 100644 --- a/lib/chess/chess_board.dart +++ b/lib/chess/chess_board.dart @@ -25,7 +25,7 @@ class ChessBoard extends StatelessWidget { bool squareWasPartOfLastMove = false; if ((boardState.lastMove.to == ChessCoordinate(column, row) || boardState.lastMove.from == ChessCoordinate(column, row)) && - boardState.positionAckdByServer) { + boardState.colorLastMove) { squareWasPartOfLastMove = true; } diff --git a/lib/chess_bloc/chess_bloc.dart b/lib/chess_bloc/chess_bloc.dart index e66e3d4..8eee842 100644 --- a/lib/chess_bloc/chess_bloc.dart +++ b/lib/chess_bloc/chess_bloc.dart @@ -24,7 +24,6 @@ class ChessBloc extends Bloc { on(ownMoveHandler); on(ownPromotionHandler); on(invalidMoveHandler); - on(boardStatusHandler); } factory ChessBloc.getInstance() { @@ -112,8 +111,14 @@ class ChessBloc extends Bloc { tempPosition[move.from] = const ChessPiece.none(); emit( - ChessBoardState(state.bottomColor, turnColor, tempPosition, move, false, - ChessCoordinate.none()), + ChessBoardState( + state.bottomColor, + turnColor, + tempPosition, + ChessPositionManager.getInstance().lastMove, + true, + ChessCoordinate.none(), + ), ); } @@ -138,31 +143,18 @@ class ChessBloc extends Bloc { void invalidMoveHandler( InvalidMovePlayed event, Emitter emit) { + var move = ChessPositionManager.getInstance().lastMove; emit( ChessBoardState( state.bottomColor, turnColor, ChessPositionManager.getInstance().currentPosition, - ChessMove.none(), - false, + move, + true, event.squareInCheck, ), ); } - - void boardStatusHandler( - BoardStatusReceived event, Emitter emit) { - emit( - ChessBoardState( - event.myColor, - event.whoseTurn, - event.pos, - ChessMove.none(), - false, - ChessCoordinate.none(), - ), - ); - } } class ChessBoardState { @@ -170,7 +162,7 @@ class ChessBoardState { final ChessColor newTurnColor; final ChessPosition position; final ChessMove lastMove; - final bool positionAckdByServer; + final bool colorLastMove; final ChessCoordinate squareInCheck; ChessBoardState._( @@ -178,7 +170,7 @@ class ChessBoardState { this.newTurnColor, this.position, this.lastMove, - this.positionAckdByServer, + this.colorLastMove, this.squareInCheck, ); diff --git a/lib/chess_bloc/chess_events.dart b/lib/chess_bloc/chess_events.dart index 79d99eb..d65d1e8 100644 --- a/lib/chess_bloc/chess_events.dart +++ b/lib/chess_bloc/chess_events.dart @@ -52,15 +52,3 @@ class InvalidMovePlayed extends ChessEvent { required this.squareInCheck, }); } - -class BoardStatusReceived extends ChessEvent { - final ChessPosition pos; - final ChessColor myColor; - final ChessColor whoseTurn; - - BoardStatusReceived({ - required this.pos, - required this.myColor, - required this.whoseTurn, - }); -} diff --git a/pubspec.lock b/pubspec.lock index b3150b7..5ca8b07 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -236,10 +236,10 @@ packages: dependency: transitive description: name: path_provider_platform_interface - sha256: "94b1e0dd80970c1ce43d5d4e050a9918fce4f4a775e6142424c30a29a363265c" + sha256: "88f5779f72ba699763fa3a3b06aa4bf6de76c8e5de842cf6f29e2e06476c2334" url: "https://pub.dev" source: hosted - version: "2.1.1" + version: "2.1.2" path_provider_windows: dependency: transitive description: @@ -324,10 +324,10 @@ packages: dependency: transitive description: name: shared_preferences_platform_interface - sha256: d4ec5fc9ebb2f2e056c617112aa75dcf92fc2e4faaf2ae999caa297473f75d8a + sha256: "22e2ecac9419b4246d7c22bfbbda589e3acf5c0351137d87dd2939d984d37c3b" url: "https://pub.dev" source: hosted - version: "2.3.1" + version: "2.3.2" shared_preferences_web: dependency: transitive description: @@ -433,26 +433,26 @@ packages: dependency: transitive description: name: vector_graphics - sha256: "0f0c746dd2d6254a0057218ff980fc7f5670fd0fcf5e4db38a490d31eed4ad43" + sha256: "18f6690295af52d081f6808f2f7c69f0eed6d7e23a71539d75f4aeb8f0062172" url: "https://pub.dev" source: hosted - version: "1.1.9+1" + version: "1.1.9+2" vector_graphics_codec: dependency: transitive description: name: vector_graphics_codec - sha256: "0edf6d630d1bfd5589114138ed8fada3234deacc37966bec033d3047c29248b7" + sha256: "531d20465c10dfac7f5cd90b60bbe4dd9921f1ec4ca54c83ebb176dbacb7bb2d" url: "https://pub.dev" source: hosted - version: "1.1.9+1" + version: "1.1.9+2" vector_graphics_compiler: dependency: transitive description: name: vector_graphics_compiler - sha256: d24333727332d9bd20990f1483af4e09abdb9b1fc7c3db940b56ab5c42790c26 + sha256: "03012b0a33775c5530576b70240308080e1d5050f0faf000118c20e6463bc0ad" url: "https://pub.dev" source: hosted - version: "1.1.9+1" + version: "1.1.9+2" vector_math: dependency: transitive description: