mchess-client/lib/api/move.dart

42 lines
1.0 KiB
Dart
Raw Permalink Normal View History

2023-06-02 21:28:40 +00:00
class ApiMove {
final ApiCoordinate startSquare;
final ApiCoordinate endSquare;
2023-07-03 17:41:12 +00:00
String? promotionToPiece;
2023-06-02 21:28:40 +00:00
2023-07-03 17:41:12 +00:00
ApiMove({
2023-06-02 21:28:40 +00:00
required this.startSquare,
required this.endSquare,
2023-07-03 17:41:12 +00:00
this.promotionToPiece,
2023-06-02 21:28:40 +00:00
});
factory ApiMove.fromJson(Map<String, dynamic> json) {
final startSquare = ApiCoordinate.fromJson(json['startSquare']);
final endSquare = ApiCoordinate.fromJson(json['endSquare']);
2023-07-03 17:41:12 +00:00
final promotionToPiece = json['promotionToPiece'];
2023-06-02 21:28:40 +00:00
2023-07-03 17:41:12 +00:00
return ApiMove(
startSquare: startSquare,
endSquare: endSquare,
promotionToPiece: promotionToPiece);
2023-06-02 21:28:40 +00:00
}
2023-07-03 17:41:12 +00:00
Map<String, dynamic> toJson() => {
'startSquare': startSquare,
'endSquare': endSquare,
'promotionToPiece': promotionToPiece
};
2023-06-02 21:28:40 +00:00
}
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};
}