From 3413582069368fa8e95d2fdf851d8c6cef2dd098 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 11 Apr 2024 23:18:21 +0200 Subject: [PATCH 1/4] WIP on navigation puzzles --- lib/src/model/puzzle/puzzle_controller.dart | 6 +- lib/src/view/puzzle/puzzle_screen.dart | 64 ++++++++++----------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/lib/src/model/puzzle/puzzle_controller.dart b/lib/src/model/puzzle/puzzle_controller.dart index 2bfc96a375..6598f10f15 100644 --- a/lib/src/model/puzzle/puzzle_controller.dart +++ b/lib/src/model/puzzle/puzzle_controller.dart @@ -563,9 +563,9 @@ class PuzzleState with _$PuzzleState { Position get position => node.position; String get fen => node.position.fen; - bool get canGoNext => mode == PuzzleMode.view && node.children.isNotEmpty; - bool get canGoBack => - mode == PuzzleMode.view && currentPath.size > initialPath.size; + bool get canPlayMove => mode == PuzzleMode.view || node.children.isNotEmpty; + bool get canGoNext => node.children.isNotEmpty; + bool get canGoBack => currentPath.size > initialPath.size; IMap> get validMoves => algebraicLegalMoves(position); } diff --git a/lib/src/view/puzzle/puzzle_screen.dart b/lib/src/view/puzzle/puzzle_screen.dart index feb40cee96..fdf9a7acce 100644 --- a/lib/src/view/puzzle/puzzle_screen.dart +++ b/lib/src/view/puzzle/puzzle_screen.dart @@ -324,9 +324,11 @@ class _Body extends ConsumerWidget { ? cg.InteractableSide.none : puzzleState.mode == PuzzleMode.view ? cg.InteractableSide.both - : puzzleState.pov == Side.white - ? cg.InteractableSide.white - : cg.InteractableSide.black, + : puzzleState.canPlayMove + ? cg.InteractableSide.none + : puzzleState.pov == Side.white + ? cg.InteractableSide.white + : cg.InteractableSide.black, fen: puzzleState.fen, isCheck: puzzleState.position.isCheck, lastMove: puzzleState.lastMove?.cg, @@ -446,9 +448,11 @@ class _BottomBar extends ConsumerWidget { if (initialPuzzleContext.userId != null && !isDailyPuzzle && puzzleState.mode != PuzzleMode.view) - _DifficultySelector( - initialPuzzleContext: initialPuzzleContext, - ctrlProvider: ctrlProvider, + Expanded( + child: _DifficultySelector( + initialPuzzleContext: initialPuzzleContext, + ctrlProvider: ctrlProvider, + ), ), if (puzzleState.mode != PuzzleMode.view) BottomBarButton( @@ -486,38 +490,34 @@ class _BottomBar extends ConsumerWidget { highlighted: puzzleState.isLocalEvalEnabled, ), ), - if (puzzleState.mode == PuzzleMode.view) - Expanded( - child: RepeatButton( - triggerDelays: _repeatTriggerDelays, - onLongPress: + Expanded( + child: RepeatButton( + triggerDelays: _repeatTriggerDelays, + onLongPress: + puzzleState.canGoBack ? () => _moveBackward(ref) : null, + child: BottomBarButton( + onTap: puzzleState.canGoBack ? () => _moveBackward(ref) : null, - child: BottomBarButton( - onTap: puzzleState.canGoBack - ? () => _moveBackward(ref) - : null, - label: 'Previous', - icon: CupertinoIcons.chevron_back, - showTooltip: false, - ), + label: 'Previous', + icon: CupertinoIcons.chevron_back, + showTooltip: false, ), ), - if (puzzleState.mode == PuzzleMode.view) - Expanded( - child: RepeatButton( - triggerDelays: _repeatTriggerDelays, - onLongPress: + ), + Expanded( + child: RepeatButton( + triggerDelays: _repeatTriggerDelays, + onLongPress: + puzzleState.canGoNext ? () => _moveForward(ref) : null, + child: BottomBarButton( + onTap: puzzleState.canGoNext ? () => _moveForward(ref) : null, - child: BottomBarButton( - onTap: puzzleState.canGoNext - ? () => _moveForward(ref) - : null, - label: context.l10n.next, - icon: CupertinoIcons.chevron_forward, - showTooltip: false, - ), + label: context.l10n.next, + icon: CupertinoIcons.chevron_forward, + showTooltip: false, ), ), + ), if (puzzleState.mode == PuzzleMode.view) Expanded( child: BottomBarButton( From 61d6e7979d608d1d2549b9d67f27d94e952b1d63 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 12 Apr 2024 23:17:24 +0200 Subject: [PATCH 2/4] delete wrong move from game tree --- lib/src/model/puzzle/puzzle_controller.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/src/model/puzzle/puzzle_controller.dart b/lib/src/model/puzzle/puzzle_controller.dart index d9cb7e5544..d9a8877897 100644 --- a/lib/src/model/puzzle/puzzle_controller.dart +++ b/lib/src/model/puzzle/puzzle_controller.dart @@ -151,6 +151,7 @@ class PuzzleController extends _$PuzzleController { _onFailOrWin(PuzzleResult.lose); if (initialStreak == null) { await Future.delayed(const Duration(milliseconds: 500)); + _gameTree.deleteAt(state.currentPath); _setPath(state.currentPath.penultimate); } } @@ -584,7 +585,7 @@ class PuzzleState with _$PuzzleState { String get fen => node.position.fen; bool get canPlayMove => mode == PuzzleMode.view || node.children.isNotEmpty; bool get canGoNext => node.children.isNotEmpty; - bool get canGoBack => currentPath.size > initialPath.size; + bool get canGoBack => currentPath.size > 0; IMap> get validMoves => algebraicLegalMoves(position); } From 15b41b3be9b048f8936f66479a5c4619b20def2b Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 13 Apr 2024 00:16:08 +0200 Subject: [PATCH 3/4] meet accessibility guidelines --- lib/src/view/puzzle/puzzle_screen.dart | 44 +++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/lib/src/view/puzzle/puzzle_screen.dart b/lib/src/view/puzzle/puzzle_screen.dart index e801559511..36fc19dc78 100644 --- a/lib/src/view/puzzle/puzzle_screen.dart +++ b/lib/src/view/puzzle/puzzle_screen.dart @@ -492,30 +492,38 @@ class _BottomBar extends ConsumerWidget { ), ), Expanded( - child: RepeatButton( - triggerDelays: _repeatTriggerDelays, - onLongPress: - puzzleState.canGoBack ? () => _moveBackward(ref) : null, - child: BottomBarButton( - onTap: + child: Semantics( + label: 'Previous Button', + child: RepeatButton( + triggerDelays: _repeatTriggerDelays, + onLongPress: puzzleState.canGoBack ? () => _moveBackward(ref) : null, - label: 'Previous', - icon: CupertinoIcons.chevron_back, - showTooltip: false, + child: BottomBarButton( + onTap: puzzleState.canGoBack + ? () => _moveBackward(ref) + : null, + label: 'Previous', + icon: CupertinoIcons.chevron_back, + showTooltip: false, + ), ), ), ), Expanded( - child: RepeatButton( - triggerDelays: _repeatTriggerDelays, - onLongPress: - puzzleState.canGoNext ? () => _moveForward(ref) : null, - child: BottomBarButton( - onTap: + child: Semantics( + label: 'Next Button', + child: RepeatButton( + triggerDelays: _repeatTriggerDelays, + onLongPress: puzzleState.canGoNext ? () => _moveForward(ref) : null, - label: context.l10n.next, - icon: CupertinoIcons.chevron_forward, - showTooltip: false, + child: BottomBarButton( + onTap: puzzleState.canGoNext + ? () => _moveForward(ref) + : null, + label: context.l10n.next, + icon: CupertinoIcons.chevron_forward, + showTooltip: false, + ), ), ), ), From 7b992df646cbb1bbcbdde7b104f4fe1a313a6210 Mon Sep 17 00:00:00 2001 From: Noah Date: Sat, 13 Apr 2024 00:39:37 +0200 Subject: [PATCH 4/4] fix confusing variable naming --- lib/src/model/puzzle/puzzle_controller.dart | 2 +- lib/src/view/puzzle/puzzle_screen.dart | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/src/model/puzzle/puzzle_controller.dart b/lib/src/model/puzzle/puzzle_controller.dart index d9a8877897..7a7715f305 100644 --- a/lib/src/model/puzzle/puzzle_controller.dart +++ b/lib/src/model/puzzle/puzzle_controller.dart @@ -583,7 +583,7 @@ class PuzzleState with _$PuzzleState { Position get position => node.position; String get fen => node.position.fen; - bool get canPlayMove => mode == PuzzleMode.view || node.children.isNotEmpty; + bool get canPlayMove => mode == PuzzleMode.play && node.children.isEmpty; bool get canGoNext => node.children.isNotEmpty; bool get canGoBack => currentPath.size > 0; diff --git a/lib/src/view/puzzle/puzzle_screen.dart b/lib/src/view/puzzle/puzzle_screen.dart index 36fc19dc78..aba8b3be68 100644 --- a/lib/src/view/puzzle/puzzle_screen.dart +++ b/lib/src/view/puzzle/puzzle_screen.dart @@ -332,10 +332,10 @@ class _Body extends ConsumerWidget { : puzzleState.mode == PuzzleMode.view ? cg.InteractableSide.both : puzzleState.canPlayMove - ? cg.InteractableSide.none - : puzzleState.pov == Side.white + ? puzzleState.pov == Side.white ? cg.InteractableSide.white - : cg.InteractableSide.black, + : cg.InteractableSide.black + : cg.InteractableSide.none, fen: puzzleState.fen, isCheck: puzzleState.position.isCheck, lastMove: puzzleState.lastMove?.cg,