From 83597d1ecb3e79e79f4c21346f711cc623efc232 Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Tue, 10 Oct 2023 18:15:33 +0200 Subject: [PATCH] Go to analysis from game position --- lib/src/model/analysis/analysis_controller.dart | 12 ++++++++++-- lib/src/model/game/game_controller.dart | 1 + lib/src/view/game/archived_game_screen.dart | 6 +++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/src/model/analysis/analysis_controller.dart b/lib/src/model/analysis/analysis_controller.dart index 9819c80952..e5adef2f62 100644 --- a/lib/src/model/analysis/analysis_controller.dart +++ b/lib/src/model/analysis/analysis_controller.dart @@ -29,6 +29,7 @@ class AnalysisOptions with _$AnalysisOptions { required String initialFen, required int initialPly, required IList moves, + int? initialMoveCursor, LightOpening? opening, }) = _AnalysisOptions; } @@ -61,6 +62,7 @@ class AnalysisController extends _$AnalysisController { int ply = options.initialPly; Position position = initialPosition; Node current = _root; + UciPath path = UciPath.empty; for (final move in options.moves) { final (newPos, san) = position.playToSan(move); position = newPos; @@ -73,9 +75,15 @@ class AnalysisController extends _$AnalysisController { ); current.addChild(nextNode); current = nextNode; + if (options.initialMoveCursor != null && + ply <= options.initialMoveCursor!) { + path = path + nextNode.id; + } } - final currentPath = _root.mainlinePath; + final currentPath = + options.initialMoveCursor == null ? _root.mainlinePath : path; + final currentNode = _root.nodeAt(currentPath); // don't use ref.watch here: we don't want to invalidate state when the // analysis preferences change @@ -100,7 +108,7 @@ class AnalysisController extends _$AnalysisController { initialPath: UciPath.empty, currentPath: currentPath, root: _root.view, - currentNode: current.view, + currentNode: currentNode.view, pov: options.orientation, evaluationContext: evalContext, contextOpening: options.opening, diff --git a/lib/src/model/game/game_controller.dart b/lib/src/model/game/game_controller.dart index da187110a4..8d4805cacf 100644 --- a/lib/src/model/game/game_controller.dart +++ b/lib/src/model/game/game_controller.dart @@ -843,6 +843,7 @@ class GameState with _$GameState { .where((e) => e.sanMove != null) .map((e) => e.sanMove!.move), ), + initialMoveCursor: stepCursor, orientation: game.youAre ?? Side.white, id: game.meta.id, ); diff --git a/lib/src/view/game/archived_game_screen.dart b/lib/src/view/game/archived_game_screen.dart index c0b415f67c..6bcfb2022b 100644 --- a/lib/src/view/game/archived_game_screen.dart +++ b/lib/src/view/game/archived_game_screen.dart @@ -242,10 +242,9 @@ class _BottomBar extends ConsumerWidget { semanticsLabel: context.l10n.gameAnalysis, onPressed: ref.read(gameCursorProvider(gameData.id)).hasValue ? () { - final game = ref + final (game, cursor) = ref .read(gameCursorProvider(gameData.id)) - .requireValue - .$1; + .requireValue; pushPlatformRoute( context, @@ -261,6 +260,7 @@ class _BottomBar extends ConsumerWidget { .where((e) => e.sanMove != null) .map((e) => e.sanMove!.move), ), + initialMoveCursor: cursor, orientation: orientation, id: gameData.id, opening: gameData.opening,