Skip to content

Commit

Permalink
Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Sep 2, 2024
1 parent d0f608f commit fdc8280
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
9 changes: 5 additions & 4 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,7 @@ class _HomePageState extends State<HomePage> {
promotionMove: promotionMove,
onMove:
playMode == Mode.botPlay ? _onUserMoveAgainstBot : _playMove,
onPromotionSelect: _onPromotionSelect,
onPromotionCancel: _onPromotionCancel,
onPromotionSelection: _onPromotionSelection,
premovable: (
onSetPremove: _onSetPremove,
premove: premove,
Expand Down Expand Up @@ -421,8 +420,10 @@ class _HomePageState extends State<HomePage> {
});
}

void _onPromotionSelect(Role role) {
if (promotionMove != null) {
void _onPromotionSelection(Role? role) {
if (role == null) {
_onPromotionCancel();
} else if (promotionMove != null) {
if (playMode == Mode.botPlay) {
_onUserMoveAgainstBot(promotionMove!.withPromotion(role));
} else {
Expand Down
12 changes: 5 additions & 7 deletions lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ class GameData {
required this.playerSide,
required this.sideToMove,
required this.validMoves,
required this.onMove,
required this.onPromotionSelect,
required this.onPromotionCancel,
required this.promotionMove,
required this.onMove,
required this.onPromotionSelection,
this.isCheck,
this.premovable,
});
Expand Down Expand Up @@ -60,10 +59,9 @@ class GameData {
final void Function(NormalMove, {bool? isDrop}) onMove;

/// Callback called after a piece has been selected for promotion.
final void Function(Role) onPromotionSelect;

/// Callback called after a promotion has been canceled.
final void Function() onPromotionCancel;
///
/// If the argument is `null`, the promotion should be canceled.
final void Function(Role? role) onPromotionSelection;

/// Optional premovable state of the board.
///
Expand Down
8 changes: 5 additions & 3 deletions lib/src/widgets/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ class _BoardState extends State<Chessboard> {
else
...highlightedBackground,
...objects,
if (widget.game != null && widget.game?.promotionMove != null)
if (widget.game?.promotionMove != null)
PromotionSelector(
pieceAssets: widget.settings.pieceAssets,
move: widget.game!.promotionMove!,
Expand All @@ -380,8 +380,10 @@ class _BoardState extends State<Chessboard> {
orientation: widget.orientation,
piecesUpsideDown: widget.opponentsPiecesUpsideDown &&
widget.game?.sideToMove != widget.orientation,
onSelect: widget.game!.onPromotionSelect,
onCancel: widget.game!.onPromotionCancel,
onSelect: widget.game!.onPromotionSelection,
onCancel: () {
widget.game!.onPromotionSelection(null);
},
),
],
),
Expand Down
11 changes: 4 additions & 7 deletions test/widgets/board_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1316,14 +1316,11 @@ Widget buildBoard({
});
}
},
onPromotionSelect: (Role role) {
setState(() {
playMove(promotionMove!.withPromotion(role));
promotionMove = null;
});
},
onPromotionCancel: () {
onPromotionSelection: (Role? role) {
setState(() {
if (role != null) {
playMove(promotionMove!.withPromotion(role));
}
promotionMove = null;
});
},
Expand Down

0 comments on commit fdc8280

Please sign in to comment.