From 8ebc010e63e5eebe5210108237bed097b29aa96c Mon Sep 17 00:00:00 2001 From: Marco Date: Sun, 13 Nov 2022 03:42:30 +0100 Subject: [PATCH] Fix shit. --- lib/chess_bloc/chess_bloc.dart | 35 +++++----------------------------- lib/chessapp/chess_board.dart | 5 ++--- lib/chessapp/chess_square.dart | 4 +++- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/lib/chess_bloc/chess_bloc.dart b/lib/chess_bloc/chess_bloc.dart index 1354a35..fbca3fa 100644 --- a/lib/chess_bloc/chess_bloc.dart +++ b/lib/chess_bloc/chess_bloc.dart @@ -1,11 +1,7 @@ import 'dart:async'; - -import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:mchess/chessapp/chess_board.dart'; - +import 'chess_events.dart'; import 'package:mchess/chessapp/chess_utils.dart'; -import 'package:mchess/chessapp/chess_square.dart'; class ChessBloc extends Bloc { static final ChessBloc _instance = ChessBloc._internal(); @@ -40,27 +36,14 @@ class ChessBloc extends Bloc { )); } - FutureOr preCheckHandler( + void preCheckHandler( PreCheckMove event, Emitter emit, ) { - return false; + print('Pretending to check a move before you drop a piece'); } } -abstract class ChessEvent {} - -class PieceMoved extends ChessEvent { - final ChessCoordinate startSquare; - final ChessCoordinate endSquare; - - PieceMoved({required this.startSquare, required this.endSquare}); -} - -class PreCheckMove extends ChessEvent {} - -class BoardFlippedEvent extends ChessEvent {} - class ChessBoardState { final bool flipped; final ChessColor turnColor; @@ -81,16 +64,8 @@ class ChessBoardState { ChessColor turnColor = ChessColor.white; Map position = {}; - for (int row = 1; row <= 8; row++) { - for (int col = 1; col <= 8; col++) { - position[ChessCoordinate(row, col)] = - ChessPiece(ChessPieceName.none, ChessColor.white); - if (col == 1 && row == 4) { - position[ChessCoordinate(col, row)] = - ChessPiece(ChessPieceName.blackKing, ChessColor.black); - } - } - } + position[ChessCoordinate(1, 1)] = + ChessPiece(ChessPieceName.blackKing, ChessColor.black); return ChessBoardState._(flipped, turnColor, position); } diff --git a/lib/chessapp/chess_board.dart b/lib/chessapp/chess_board.dart index 8ffb47b..f938aff 100644 --- a/lib/chessapp/chess_board.dart +++ b/lib/chessapp/chess_board.dart @@ -31,9 +31,8 @@ class ChessBoard extends StatelessWidget { @override Widget build(BuildContext context) { - return Column( - children: _buildBoard(bState.flipped), - ); + print("ChessBoard's build()"); + return Column(children: _buildBoard(bState.flipped)); } Row _buildChessRow(int rowNo, bool flipped) { diff --git a/lib/chessapp/chess_square.dart b/lib/chessapp/chess_square.dart index 7882627..cab703e 100644 --- a/lib/chessapp/chess_square.dart +++ b/lib/chessapp/chess_square.dart @@ -1,4 +1,6 @@ import 'package:flutter/material.dart'; + +import 'package:mchess/chess_bloc/chess_events.dart'; import 'package:mchess/chess_bloc/chess_bloc.dart'; import 'chess_utils.dart'; @@ -52,7 +54,7 @@ class ChessSquare extends StatelessWidget { ); }, onWillAccept: (move) { - print('onWillAccept'); + ChessBloc().add(PreCheckMove(move: move!)); return true; }, onAccept: (move) {