Skip to content

Commit

Permalink
Tweak
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Nov 14, 2024
1 parent 5874914 commit d7161d6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class OfflineCorrespondenceGame
return null;
}

bool get isPlayerTurn => lastPosition.turn == youAre;
bool get playable => status.value < GameStatus.aborted.value;
bool get playing => status.value > GameStatus.started.value;
bool get finished => status.value >= GameStatus.mate.value;
Expand Down
9 changes: 4 additions & 5 deletions lib/src/model/game/game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ class GameController extends _$GameController {

if (data.clock != null) {
final lagCompensation =
newState.game.playable && newState.game.isPlayerTurn
newState.game.playable && newState.game.isMyTurn
// server will send the lag only if it's more than 10ms
? Duration.zero
: data.clock?.lag ?? const Duration(milliseconds: 10);
Expand All @@ -668,12 +668,11 @@ class GameController extends _$GameController {
);

if (newState.game.clock != null) {
// TODO remove that
// we don't rely on these values to display the clock, but let's keep
// the game object in sync
newState = newState.copyWith.game.clock!(
white: data.clock!.white,
black: data.clock!.black,
// lag: lagCompensation,
// at: data.clock!.at,
);
} else if (newState.game.correspondenceClock != null) {
newState = newState.copyWith.game.correspondenceClock!(
Expand Down Expand Up @@ -1131,7 +1130,7 @@ class GameState with _$GameState {
game.drawable && (lastDrawOfferAtPly ?? -99) < game.lastPly - 20;

bool get canShowClaimWinCountdown =>
!game.isPlayerTurn &&
!game.isMyTurn &&
game.resignable &&
(game.meta.rules == null ||
!game.meta.rules!.contains(GameRule.noClaimWin));
Expand Down
5 changes: 3 additions & 2 deletions lib/src/model/game/playable_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class PlayableGame

bool get imported => source == GameSource.import;

bool get isPlayerTurn => lastPosition.turn == youAre;
/// 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;
Expand Down Expand Up @@ -125,7 +126,7 @@ class PlayableGame

bool get canClaimWin =>
opponent?.isGone == true &&
!isPlayerTurn &&
!isMyTurn &&
resignable &&
(meta.rules == null || !meta.rules!.contains(GameRule.noClaimWin));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ class _BodyState extends ConsumerState<_Body> {
data: (games) {
final nextTurn = games
.whereNot((g) => g.$2.id == game.id)
.firstWhereOrNull((g) => g.$2.isPlayerTurn);
.firstWhereOrNull((g) => g.$2.isMyTurn);
return nextTurn != null
? () {
widget.onGameChanged(nextTurn);
Expand Down

0 comments on commit d7161d6

Please sign in to comment.