Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate the puzzle with back and forward buttons #631

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 4 additions & 3 deletions lib/src/model/puzzle/puzzle_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ class PuzzleController extends _$PuzzleController {
_onFailOrWin(PuzzleResult.lose);
if (initialStreak == null) {
await Future<void>.delayed(const Duration(milliseconds: 500));
_gameTree.deleteAt(state.currentPath);
_setPath(state.currentPath.penultimate);
}
}
Expand Down Expand Up @@ -582,9 +583,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.play && node.children.isEmpty;
bool get canGoNext => node.children.isNotEmpty;
bool get canGoBack => currentPath.size > 0;

IMap<String, ISet<String>> get validMoves => algebraicLegalMoves(position);
}
28 changes: 18 additions & 10 deletions lib/src/view/puzzle/puzzle_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,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
? puzzleState.pov == Side.white
? cg.InteractableSide.white
: cg.InteractableSide.black
: cg.InteractableSide.none,
fen: puzzleState.fen,
isCheck: puzzleState.position.isCheck,
lastMove: puzzleState.lastMove?.cg,
Expand Down Expand Up @@ -453,9 +455,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(
Expand Down Expand Up @@ -487,8 +491,9 @@ class _BottomBar extends ConsumerWidget {
highlighted: puzzleState.isLocalEvalEnabled,
),
),
if (puzzleState.mode == PuzzleMode.view)
Expanded(
Expanded(
child: Semantics(
label: 'Previous Button',
child: RepeatButton(
triggerDelays: _repeatTriggerDelays,
onLongPress:
Expand All @@ -503,8 +508,10 @@ class _BottomBar extends ConsumerWidget {
),
),
),
if (puzzleState.mode == PuzzleMode.view)
Expanded(
),
Expanded(
child: Semantics(
label: 'Next Button',
child: RepeatButton(
triggerDelays: _repeatTriggerDelays,
onLongPress:
Expand All @@ -519,6 +526,7 @@ class _BottomBar extends ConsumerWidget {
),
),
),
),
if (puzzleState.mode == PuzzleMode.view)
Expanded(
child: BottomBarButton(
Expand Down