Skip to content

Commit 6e301a8

Browse files
Copilottom-anders
andcommitted
Add canShowThreat getter to AnalysisState for readability
Co-authored-by: tom-anders <13141438+tom-anders@users.noreply.github.com>
1 parent 74d93f6 commit 6e301a8

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

lib/src/model/analysis/analysis_controller.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,7 @@ class AnalysisController extends AsyncNotifier<AnalysisState>
695695
Future<void> toggleEngineThreatMode() async {
696696
if (state.hasValue) {
697697
final curState = state.requireValue;
698-
// Cannot show threat when the king is in check, checkmate, or stalemate.
699-
if (!curState.engineInThreatMode &&
700-
(curState.currentPosition.isCheck || curState.currentPosition.isStalemate)) {
698+
if (!curState.engineInThreatMode && !curState.canShowThreat) {
701699
return;
702700
}
703701
state = AsyncData(curState.copyWith(engineInThreatMode: !curState.engineInThreatMode));
@@ -1016,6 +1014,13 @@ sealed class AnalysisState
10161014
bool get canGoNext => currentNode.hasChild;
10171015
bool get canGoBack => currentPath.size > UciPath.empty.size;
10181016

1017+
/// Whether the "show threat" feature can be used in the current position.
1018+
///
1019+
/// Threat mode makes the engine analyze from the opponent's perspective, which
1020+
/// is invalid when the king is in check (including checkmate) or in stalemate.
1021+
bool get canShowThreat =>
1022+
!currentPosition.isCheck && !currentPosition.isStalemate;
1023+
10191024
EngineGaugeParams engineGaugeParams(EngineEvaluationPrefState prefs) => (
10201025
isLocalEngineAvailable: isEngineAvailable(prefs),
10211026
orientation: pov,

lib/src/view/analysis/analysis_screen.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -616,9 +616,7 @@ class _BottomBar extends ConsumerWidget {
616616
),
617617
),
618618
],
619-
if (analysisState.isEngineAvailable(evalPrefs) &&
620-
!analysisState.currentPosition.isCheck &&
621-
!analysisState.currentPosition.isStalemate)
619+
if (analysisState.isEngineAvailable(evalPrefs) && analysisState.canShowThreat)
622620
BottomSheetAction(
623621
makeLabel: (context) => Text(
624622
analysisState.engineInThreatMode

0 commit comments

Comments
 (0)