Skip to content

Commit

Permalink
refactor: move finished, aborted and playable fields to BaseGame
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-anders committed Dec 26, 2024
1 parent 6cb849f commit 4d70e2a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 14 deletions.
4 changes: 0 additions & 4 deletions lib/src/model/correspondence/offline_correspondence_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,4 @@ class OfflineCorrespondenceGame
}
return null;
}

bool get playable => status.value < GameStatus.aborted.value;
bool get playing => status.value > GameStatus.started.value;
bool get finished => status.value >= GameStatus.mate.value;
}
7 changes: 7 additions & 0 deletions lib/src/model/game/game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ abstract mixin class BaseGame {

GameStatus get status;

/// Whether the game is properly finished (not aborted).
bool get finished => status.value >= GameStatus.mate.value;
bool get aborted => status == GameStatus.aborted;

/// Whether the game is still playable (not finished or aborted and not imported).
bool get playable => status.value < GameStatus.aborted.value;

/// This field is null if the game is being watched as a spectator, and
/// represents the side that the current player is playing as otherwise.
Side? get youAre;
Expand Down
2 changes: 0 additions & 2 deletions lib/src/model/game/over_the_board_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,4 @@ abstract class OverTheBoardGame with _$OverTheBoardGame, BaseGame, IndexableStep
Side? winner,
bool? isThreefoldRepetition,
}) = _OverTheBoardGame;

bool get finished => status.value >= GameStatus.mate.value;
}
6 changes: 0 additions & 6 deletions lib/src/model/game/playable_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ class PlayableGame with _$PlayableGame, BaseGame, IndexableSteps implements Base
/// Whether it is the current player's turn.
bool get isMyTurn => lastPosition.turn == youAre;

/// Whether the game is properly finished (not aborted).
bool get finished => status.value >= GameStatus.mate.value;
bool get aborted => status == GameStatus.aborted;

/// Whether the game is still playable (not finished or aborted and not imported).
bool get playable => status.value < GameStatus.aborted.value && !imported;
bool get abortable =>
playable &&
lastPosition.fullmoves <= 1 &&
Expand Down
3 changes: 1 addition & 2 deletions lib/src/view/game/game_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ class GamePlayer extends StatelessWidget {
],
if (player.rating != null)
RatingPrefAware(
isActiveGameOfCurrentUser:
game.status.value < GameStatus.aborted.value && game.me != null,
isActiveGameOfCurrentUser: game.me != null && !game.finished && !game.aborted,
child: Text.rich(
TextSpan(
text: ' ${player.rating}${player.provisional == true ? '?' : ''}',
Expand Down

0 comments on commit 4d70e2a

Please sign in to comment.