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(
|
var move = ChessMove(
|
||||||
from: pieceDragged.fromSquare, to: pieceDragged.toSquare);
|
from: pieceDragged.fromSquare, to: pieceDragged.toSquare);
|
||||||
PromotionBloc.getInstance().add(PawnMovedToPromotionField(
|
PromotionBloc().add(PawnMovedToPromotionField(
|
||||||
move: move, colorMoved: ChessBloc.myColor!));
|
move: move, colorMoved: ChessBloc.myColor!));
|
||||||
} else if (coordinate != pieceDragged.fromSquare) {
|
} else if (coordinate != pieceDragged.fromSquare) {
|
||||||
ChessBloc.getInstance().add(OwnPieceMoved(
|
ChessBloc().add(OwnPieceMoved(
|
||||||
startSquare: pieceDragged.fromSquare,
|
startSquare: pieceDragged.fromSquare,
|
||||||
endSquare: pieceDragged.toSquare));
|
endSquare: pieceDragged.toSquare));
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import 'dart:developer';
|
|||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||||
import 'package:mchess/chess_bloc/chess_events.dart';
|
import 'package:mchess/chess_bloc/chess_events.dart';
|
||||||
|
import 'package:mchess/chess_bloc/promotion_bloc.dart';
|
||||||
import 'package:mchess/utils/chess_utils.dart';
|
import 'package:mchess/utils/chess_utils.dart';
|
||||||
|
|
||||||
class TapBloc extends Bloc<TapEvent, TapState> {
|
class TapBloc extends Bloc<TapEvent, TapState> {
|
||||||
@ -25,6 +26,8 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
|||||||
ChessPiece? piece;
|
ChessPiece? piece;
|
||||||
|
|
||||||
if (ChessBloc.myColor != ChessBloc.turnColor) return;
|
if (ChessBloc.myColor != ChessBloc.turnColor) return;
|
||||||
|
if (event.pieceOnSquare != null &&
|
||||||
|
ChessBloc.myColor != event.pieceOnSquare!.color) return;
|
||||||
|
|
||||||
if (state.firstSquareTapped == null) {
|
if (state.firstSquareTapped == null) {
|
||||||
//first tap
|
//first tap
|
||||||
@ -33,6 +36,13 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
|||||||
piece = event.pieceOnSquare;
|
piece = event.pieceOnSquare;
|
||||||
} else {
|
} else {
|
||||||
//second tap
|
//second tap
|
||||||
|
if (event.pieceOnSquare?.color == ChessBloc.myColor) {
|
||||||
|
emit(TapState(
|
||||||
|
firstSquareTapped: event.tapped,
|
||||||
|
pieceOnFirstTappedSquare: event.pieceOnSquare,
|
||||||
|
secondSquareTapped: null));
|
||||||
|
return;
|
||||||
|
}
|
||||||
secondTappedSquare = event.tapped;
|
secondTappedSquare = event.tapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,9 +53,9 @@ class TapBloc extends Bloc<TapEvent, TapState> {
|
|||||||
ChessBloc.myColor!,
|
ChessBloc.myColor!,
|
||||||
event.tapped,
|
event.tapped,
|
||||||
)) {
|
)) {
|
||||||
ChessBloc().add(OwnPromotionPlayed(
|
PromotionBloc().add(PawnMovedToPromotionField(
|
||||||
pieceClass: state.pieceOnFirstTappedSquare!.pieceClass,
|
move: ChessMove(from: state.firstSquareTapped!, to: event.tapped),
|
||||||
move: ChessMove(from: state.firstSquareTapped!, to: event.tapped)));
|
colorMoved: ChessBloc.myColor!));
|
||||||
emit(TapState.init());
|
emit(TapState.init());
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user