Send new websocket message type for sending a move.

This commit is contained in:
Marco 2023-06-08 17:14:50 +02:00
parent 6e5d84364d
commit 0627a627d8

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:mchess/api/move.dart'; import 'package:mchess/api/move.dart';
import 'package:mchess/api/websocket_message.dart';
import 'package:mchess/chess_bloc/chess_events.dart'; import 'package:mchess/chess_bloc/chess_events.dart';
import 'package:mchess/chess_bloc/chess_position.dart'; import 'package:mchess/chess_bloc/chess_position.dart';
import 'package:mchess/connection/ws_connection.dart'; import 'package:mchess/connection/ws_connection.dart';
@ -69,8 +70,10 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
var end = var end =
ApiCoordinate(col: event.endSquare.column, row: event.endSquare.row); ApiCoordinate(col: event.endSquare.column, row: event.endSquare.row);
var move = ApiMove(startSquare: start, endSquare: end); var move = ApiMove(startSquare: start, endSquare: end);
var message = ApiWebsocketMessage(
type: MessageType.moveMessage, move: move, color: null);
ServerConnection.getInstance().send(jsonEncode(move)); ServerConnection.getInstance().send(jsonEncode(message));
turnColor = state.newTurnColor == ChessColor.white turnColor = state.newTurnColor == ChessColor.white
? ChessColor.black ? ChessColor.black