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:
@@ -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