Fix promotions when tapping and fix handling of subsequently tapping two pieces of your color
This commit is contained in:
parent
0b4da28864
commit
68f84507e9
@ -32,10 +32,10 @@ class ChessSquareOuterDragTarget extends StatelessWidget {
|
||||
)) {
|
||||
var move = ChessMove(
|
||||
from: pieceDragged.fromSquare, to: pieceDragged.toSquare);
|
||||
PromotionBloc.getInstance().add(PawnMovedToPromotionField(
|
||||
PromotionBloc().add(PawnMovedToPromotionField(
|
||||
move: move, colorMoved: ChessBloc.myColor!));
|
||||
} else if (coordinate != pieceDragged.fromSquare) {
|
||||
ChessBloc.getInstance().add(OwnPieceMoved(
|
||||
ChessBloc().add(OwnPieceMoved(
|
||||
startSquare: pieceDragged.fromSquare,
|
||||
endSquare: pieceDragged.toSquare));
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import 'dart:developer';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||
import 'package:mchess/chess_bloc/chess_events.dart';
|
||||
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
||||
import 'package:mchess/utils/chess_utils.dart';
|
||||
|
||||
class TapBloc extends Bloc<TapEvent, TapState> {
|
||||
@ -25,6 +26,8 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
||||
ChessPiece? piece;
|
||||
|
||||
if (ChessBloc.myColor != ChessBloc.turnColor) return;
|
||||
if (event.pieceOnSquare != null &&
|
||||
ChessBloc.myColor != event.pieceOnSquare!.color) return;
|
||||
|
||||
if (state.firstSquareTapped == null) {
|
||||
//first tap
|
||||
@ -33,6 +36,13 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
||||
piece = event.pieceOnSquare;
|
||||
} else {
|
||||
//second tap
|
||||
if (event.pieceOnSquare?.color == ChessBloc.myColor) {
|
||||
emit(TapState(
|
||||
firstSquareTapped: event.tapped,
|
||||
pieceOnFirstTappedSquare: event.pieceOnSquare,
|
||||
secondSquareTapped: null));
|
||||
return;
|
||||
}
|
||||
secondTappedSquare = event.tapped;
|
||||
}
|
||||
|
||||
@ -43,9 +53,9 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
||||
ChessBloc.myColor!,
|
||||
event.tapped,
|
||||
)) {
|
||||
ChessBloc().add(OwnPromotionPlayed(
|
||||
pieceClass: state.pieceOnFirstTappedSquare!.pieceClass,
|
||||
move: ChessMove(from: state.firstSquareTapped!, to: event.tapped)));
|
||||
PromotionBloc().add(PawnMovedToPromotionField(
|
||||
move: ChessMove(from: state.firstSquareTapped!, to: event.tapped),
|
||||
colorMoved: ChessBloc.myColor!));
|
||||
emit(TapState.init());
|
||||
return;
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user