mchess-client/lib/chess_bloc/promotion_bloc.dart

50 lines
1.3 KiB
Dart

import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/utils/chess_utils.dart';
class PromotionUiBloc extends Bloc<PromotionEvent, PromotionUiState> {
static final PromotionUiBloc _instance = PromotionUiBloc._internal();
PromotionUiBloc._internal() : super(PromotionUiState.init()) {
on<PawnMovedToPromotionField>(promotionMoveHandler);
}
void promotionMoveHandler(
PawnMovedToPromotionField event,
Emitter<PromotionUiState> emit,
) {
emit(PromotionUiState(
showPromotionDialog: true, colorMoved: event.colorMoved));
}
factory PromotionUiBloc.getInstance() {
return PromotionUiBloc();
}
factory PromotionUiBloc() {
return _instance;
}
}
abstract class PromotionEvent {}
class PawnMovedToPromotionField extends PromotionEvent {
final ChessCoordinate endSquare;
final ChessColor colorMoved;
PawnMovedToPromotionField(
{required this.endSquare, required this.colorMoved});
}
class PromotionUiState {
final bool showPromotionDialog;
final ChessColor colorMoved;
PromotionUiState(
{required this.showPromotionDialog, required this.colorMoved});
factory PromotionUiState.init() {
return PromotionUiState(
showPromotionDialog: false, colorMoved: ChessColor.white);
}
}