mchess-client/lib/api/move.dart
2023-07-03 19:41:12 +02:00

42 lines
1.0 KiB
Dart

class ApiMove {
final ApiCoordinate startSquare;
final ApiCoordinate endSquare;
String? promotionToPiece;
ApiMove({
required this.startSquare,
required this.endSquare,
this.promotionToPiece,
});
factory ApiMove.fromJson(Map<String, dynamic> json) {
final startSquare = ApiCoordinate.fromJson(json['startSquare']);
final endSquare = ApiCoordinate.fromJson(json['endSquare']);
final promotionToPiece = json['promotionToPiece'];
return ApiMove(
startSquare: startSquare,
endSquare: endSquare,
promotionToPiece: promotionToPiece);
}
Map<String, dynamic> toJson() => {
'startSquare': startSquare,
'endSquare': endSquare,
'promotionToPiece': promotionToPiece
};
}
class ApiCoordinate {
final int col;
final int row;
const ApiCoordinate({required this.col, required this.row});
factory ApiCoordinate.fromJson(Map<String, dynamic> json) {
return ApiCoordinate(col: json['col'], row: json['row']);
}
Map<String, dynamic> toJson() => {'col': col, 'row': row};
}