3d1f3b30c7
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>
41 lines
1.0 KiB
Dart
41 lines
1.0 KiB
Dart
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();
|
|
}
|
|
}
|