Fix green flicker of squares on invalid move #1

Merged
marco merged 1 commits from fix-green-square-flicker into master 2023-08-25 10:39:08 +00:00
2 changed files with 13 additions and 11 deletions

View File

@ -22,8 +22,9 @@ class ChessBoard extends StatelessWidget {
final piece = boardState.position[ChessCoordinate(column, row)];
bool squareWasPartOfLastMove = false;
if (boardState.lastMove.to == ChessCoordinate(column, row) ||
boardState.lastMove.from == ChessCoordinate(column, row)) {
if ((boardState.lastMove.to == ChessCoordinate(column, row) ||
boardState.lastMove.from == ChessCoordinate(column, row)) &&
boardState.positionAckd) {
squareWasPartOfLastMove = true;
}

View File

@ -43,6 +43,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
ChessColor.white,
ChessPositionManager.getInstance().currentPosition,
ChessMove.none(),
false,
),
);
}
@ -56,6 +57,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
state.newTurnColor,
state.position,
ChessMove.none(),
false,
),
);
}
@ -76,6 +78,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
turnColor,
event.position,
ChessMove(from: event.startSquare, to: event.endSquare),
true,
),
);
}
@ -101,12 +104,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
tempPosition[move.from] = const ChessPiece.none();
emit(
ChessBoardState(
state.bottomColor,
turnColor,
tempPosition,
move
),
ChessBoardState(state.bottomColor, turnColor, tempPosition, move, false),
);
}
@ -131,7 +129,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
InvalidMovePlayed event, Emitter<ChessBoardState> emit) {
emit(
ChessBoardState(state.bottomColor, turnColor,
ChessPositionManager.getInstance().currentPosition, ChessMove.none()),
ChessPositionManager.getInstance().currentPosition, ChessMove.none(), false),
);
}
}
@ -141,17 +139,19 @@ class ChessBoardState {
final ChessColor newTurnColor;
final ChessPosition position;
final ChessMove lastMove;
final bool positionAckd;
ChessBoardState._(
this.bottomColor, this.newTurnColor, this.position, this.lastMove);
this.bottomColor, this.newTurnColor, this.position, this.lastMove, this.positionAckd);
factory ChessBoardState(
ChessColor bottomColor,
ChessColor turnColor,
ChessPosition position,
ChessMove lastMove,
bool positionAckd,
) {
return ChessBoardState._(bottomColor, turnColor, position, lastMove);
return ChessBoardState._(bottomColor, turnColor, position, lastMove, positionAckd);
}
factory ChessBoardState.init() {
@ -165,6 +165,7 @@ class ChessBoardState {
turnColor,
ChessPositionManager.getInstance().currentPosition,
ChessMove.none(),
false,
);
}