feat: tutorial step state machine with persistence
Adds TutorialNotifier (dragPiece → clearLine → explainHud → null) backed by SaveRepository.markTutorialDone(); out-of-order events are silently ignored. Registers tutorialProvider in providers.dart. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,7 @@ import 'game_session_notifier.dart';
|
||||
import 'progress_notifier.dart';
|
||||
import 'season_flow_notifier.dart';
|
||||
import 'streak_notifier.dart';
|
||||
import 'tutorial_notifier.dart';
|
||||
|
||||
final gameSessionProvider =
|
||||
NotifierProvider<GameSessionNotifier, GameViewState?>(
|
||||
@@ -46,6 +47,10 @@ final streakProvider = NotifierProvider<StreakNotifier, StreakState>(
|
||||
StreakNotifier.new,
|
||||
);
|
||||
|
||||
final tutorialProvider = NotifierProvider<TutorialNotifier, TutorialStep?>(
|
||||
TutorialNotifier.new,
|
||||
);
|
||||
|
||||
/// The visual theme of whatever season is in play; fallback outside seasons
|
||||
/// (home, endless). Pure model — UI converts via ThemeColors.
|
||||
final activeThemeProvider = Provider<SeasonTheme>((ref) {
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import 'providers.dart';
|
||||
|
||||
enum TutorialStep { dragPiece, clearLine, explainHud }
|
||||
|
||||
/// First-play guided tutorial. State null = inactive. Events arriving in the
|
||||
/// wrong step are ignored, so engine wiring can fire them unconditionally.
|
||||
class TutorialNotifier extends Notifier<TutorialStep?> {
|
||||
@override
|
||||
TutorialStep? build() => null;
|
||||
|
||||
void start() {
|
||||
if (ref.read(saveRepositoryProvider).tutorialDone) return;
|
||||
state = TutorialStep.dragPiece;
|
||||
}
|
||||
|
||||
void onPlaced() {
|
||||
if (state == TutorialStep.dragPiece) state = TutorialStep.clearLine;
|
||||
}
|
||||
|
||||
void onLineCleared() {
|
||||
if (state == TutorialStep.clearLine) state = TutorialStep.explainHud;
|
||||
}
|
||||
|
||||
Future<void> dismissHud() async {
|
||||
if (state != TutorialStep.explainHud) return;
|
||||
await _finish();
|
||||
}
|
||||
|
||||
Future<void> skip() async {
|
||||
if (state == null) return;
|
||||
await _finish();
|
||||
}
|
||||
|
||||
Future<void> _finish() async {
|
||||
state = null;
|
||||
await ref.read(saveRepositoryProvider).markTutorialDone();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user