From 4d70e2a7a65e4def8a2968f5fe0885dd1cce09bb Mon Sep 17 00:00:00 2001 From: tom-anders <13141438+tom-anders@users.noreply.github.com> Date: Thu, 26 Dec 2024 10:40:55 +0100 Subject: [PATCH] refactor: move `finished`, `aborted` and `playable` fields to BaseGame --- .../model/correspondence/offline_correspondence_game.dart | 4 ---- lib/src/model/game/game.dart | 7 +++++++ lib/src/model/game/over_the_board_game.dart | 2 -- lib/src/model/game/playable_game.dart | 6 ------ lib/src/view/game/game_player.dart | 3 +-- 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/lib/src/model/correspondence/offline_correspondence_game.dart b/lib/src/model/correspondence/offline_correspondence_game.dart index de33b3ca5c..189e286e1b 100644 --- a/lib/src/model/correspondence/offline_correspondence_game.dart +++ b/lib/src/model/correspondence/offline_correspondence_game.dart @@ -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; } diff --git a/lib/src/model/game/game.dart b/lib/src/model/game/game.dart index 8bb60cf574..52cca76b76 100644 --- a/lib/src/model/game/game.dart +++ b/lib/src/model/game/game.dart @@ -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; diff --git a/lib/src/model/game/over_the_board_game.dart b/lib/src/model/game/over_the_board_game.dart index 028c9c359a..504a00aab8 100644 --- a/lib/src/model/game/over_the_board_game.dart +++ b/lib/src/model/game/over_the_board_game.dart @@ -49,6 +49,4 @@ abstract class OverTheBoardGame with _$OverTheBoardGame, BaseGame, IndexableStep Side? winner, bool? isThreefoldRepetition, }) = _OverTheBoardGame; - - bool get finished => status.value >= GameStatus.mate.value; } diff --git a/lib/src/model/game/playable_game.dart b/lib/src/model/game/playable_game.dart index 8353a3c43b..fec7d2bff0 100644 --- a/lib/src/model/game/playable_game.dart +++ b/lib/src/model/game/playable_game.dart @@ -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 && diff --git a/lib/src/view/game/game_player.dart b/lib/src/view/game/game_player.dart index 577f648479..6d274fa9c5 100644 --- a/lib/src/view/game/game_player.dart +++ b/lib/src/view/game/game_player.dart @@ -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 ? '?' : ''}',