Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/src/model/game/game_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,15 @@ class GameController extends _$GameController {
);
}

void toggleAutoQueen() {
final curState = state.requireValue;
state = AsyncValue.data(
curState.copyWith(
autoQueenSettingOverride: !(curState.autoQueenSettingOverride ?? true),
),
);
}

void onToggleChat(bool isChatEnabled) {
if (isChatEnabled) {
// if chat is enabled, we need to resync the game data to get the chat messages
Expand Down Expand Up @@ -920,6 +929,9 @@ class GameState with _$GameState {
/// Game only setting to override the account preference
bool? moveConfirmSettingOverride,

/// Game only setting to override the account preference
bool? autoQueenSettingOverride,

/// Zen mode setting if account preference is set to [Zen.gameAuto]
bool? zenModeGameSetting,

Expand All @@ -941,7 +953,8 @@ class GameState with _$GameState {
bool get canPremove =>
game.meta.speed != Speed.correspondence &&
(game.prefs?.enablePremove ?? true);
bool get canAutoQueen => game.prefs?.autoQueen == AutoQueen.always;
bool get canAutoQueen =>
autoQueenSettingOverride ?? (game.prefs?.autoQueen == AutoQueen.always);
bool get canAutoQueenOnPremove => game.prefs?.autoQueen == AutoQueen.premove;
bool get shouldConfirmResignAndDrawOffer => game.prefs?.confirmResign ?? true;
bool get shouldConfirmMove =>
Expand Down
17 changes: 14 additions & 3 deletions lib/src/view/game/game_screen_providers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,13 @@ Future<bool> shouldPreventGoingBack(

/// User game preferences, defined server-side.
@riverpod
Future<({GamePrefs? prefs, bool shouldConfirmMove, bool isZenModeEnabled})>
userGamePrefs(
Future<
({
GamePrefs? prefs,
bool shouldConfirmMove,
bool isZenModeEnabled,
bool canAutoQueen
})> userGamePrefs(
UserGamePrefsRef ref,
GameFullId gameId,
) async {
Expand All @@ -51,10 +56,16 @@ Future<({GamePrefs? prefs, bool shouldConfirmMove, bool isZenModeEnabled})>
(state) => state.isZenModeEnabled,
),
);
final canAutoQueen = await ref.watch(
gameControllerProvider(gameId).selectAsync(
(state) => state.canAutoQueen,
),
);
return (
prefs: prefs,
shouldConfirmMove: shouldConfirmMove,
isZenModeEnabled: isZenModeEnabled
isZenModeEnabled: isZenModeEnabled,
canAutoQueen: canAutoQueen
);
}

Expand Down
13 changes: 13 additions & 0 deletions lib/src/view/game/game_settings.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:lichess_mobile/src/model/account/account_preferences.dart';
import 'package:lichess_mobile/src/model/common/id.dart';
import 'package:lichess_mobile/src/model/game/game_controller.dart';
import 'package:lichess_mobile/src/model/game/game_preferences.dart';
Expand Down Expand Up @@ -50,6 +51,18 @@ class GameSettings extends ConsumerWidget {
.toggleMoveConfirmation();
},
),
if (data.prefs?.autoQueen == AutoQueen.always)
SwitchSettingTile(
title: Text(
context.l10n.preferencesPromoteToQueenAutomatically,
),
value: data.canAutoQueen,
onChanged: (value) {
ref
.read(gameControllerProvider(id).notifier)
.toggleAutoQueen();
},
),
SwitchSettingTile(
title: Text(
context.l10n.preferencesZenMode,
Expand Down