Wire season flow: map screen, progress save, win recording, next stage

SaveRepository (versioned JSON over prefs) with best-result merging and
unlock walking; ContentRepository loads the bundled pack; SeasonFlow/
Progress notifiers orchestrate stage start -> win record -> advance.
Season map grid with stars/locks, Home -> Map -> Game navigation,
close button, next-stage action on the win overlay.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 17:04:45 +09:00
parent 41c18c8bdd
commit 7bc26447f7
16 changed files with 667 additions and 44 deletions
+28 -38
View File
@@ -2,7 +2,6 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../game/engine/game_engine.dart';
import '../../game/models/stage.dart';
import '../../l10n/gen/app_localizations.dart';
import '../../services/audio_service.dart';
import '../../state/game_session_notifier.dart';
@@ -15,29 +14,8 @@ import '../widgets/hud_widget.dart';
import '../widgets/piece_painter.dart';
import '../widgets/tray_widget.dart';
/// Demo stage until the season map lands in Phase 3.
final _demoStage = StageConfig.fromJson({
'id': 'demo_001',
'seed': 20260611,
'moveLimit': 25,
'preset': [
{'x': 2, 'y': 2, 't': 'gem'},
{'x': 5, 'y': 2, 't': 'gem'},
{'x': 2, 'y': 5, 't': 'gem'},
{'x': 5, 'y': 5, 't': 'gem'},
{'x': 3, 'y': 7, 't': 'filled', 'c': 1},
{'x': 4, 'y': 7, 't': 'filled', 'c': 1},
],
'objectives': [
{'type': 'clearGems', 'count': 4},
],
'stars': {
'two': {'movesLeft': 6},
'three': {'movesLeft': 12},
},
'generatorProfile': 'mid',
});
/// Renders whatever session [gameSessionProvider] holds; callers start the
/// stage (via SeasonFlowNotifier) before navigating here.
class GameScreen extends ConsumerStatefulWidget {
const GameScreen({super.key});
@@ -55,16 +33,6 @@ class _GameScreenState extends ConsumerState<GameScreen> {
/// How far the dragged piece floats above the finger so it stays visible.
static const double _lift = 70;
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (ref.read(gameSessionProvider) == null) {
ref.read(gameSessionProvider.notifier).startStage(_demoStage);
}
});
}
RenderBox? get _boardBox =>
_boardKey.currentContext?.findRenderObject() as RenderBox?;
@@ -125,7 +93,7 @@ class _GameScreenState extends ConsumerState<GameScreen> {
}
}
void _playSfx(GameViewState? prev, GameViewState? next) {
void _onSessionChange(GameViewState? prev, GameViewState? next) {
if (next == null) return;
final audio = ref.read(audioServiceProvider);
if (prev?.fxTick != next.fxTick && next.lastPlacement != null) {
@@ -137,14 +105,20 @@ class _GameScreenState extends ConsumerState<GameScreen> {
}
}
if (prev?.phase != next.phase) {
if (next.phase == GamePhase.won) audio.play(Sfx.win);
if (next.phase == GamePhase.won) {
audio.play(Sfx.win);
// recordResult keeps the best run, so re-entry is harmless.
ref
.read(seasonFlowProvider.notifier)
.recordWin(stars: next.starsEarned, score: next.score);
}
if (next.phase == GamePhase.lost) audio.play(Sfx.lose);
}
}
@override
Widget build(BuildContext context) {
ref.listen<GameViewState?>(gameSessionProvider, _playSfx);
ref.listen<GameViewState?>(gameSessionProvider, _onSessionChange);
final view = ref.watch(gameSessionProvider);
if (view == null) {
return const Scaffold(body: Center(child: CircularProgressIndicator()));
@@ -193,6 +167,15 @@ class _GameScreenState extends ConsumerState<GameScreen> {
_dragIndex! < view.tray.length)
_draggedPieceOverlay(view, draggedTopLeft, boardBox),
if (view.phase != GamePhase.playing) _resultOverlay(view),
if (Navigator.of(context).canPop())
Positioned(
top: 4,
left: 4,
child: IconButton(
icon: const Icon(Icons.close, color: Colors.white54),
onPressed: () => Navigator.of(context).pop(),
),
),
],
),
),
@@ -219,11 +202,18 @@ class _GameScreenState extends ConsumerState<GameScreen> {
final notifier = ref.read(gameSessionProvider.notifier);
final theme = Theme.of(context);
final flow = ref.read(seasonFlowProvider);
final (title, actions) = switch ((view.phase, view.stuckReason)) {
(GamePhase.won, _) => (
l10n.stageClear,
[
FilledButton(
if (flow != null && flow.hasNext)
FilledButton(
onPressed:
ref.read(seasonFlowProvider.notifier).nextStage,
child: Text(l10n.nextStage),
),
TextButton(
onPressed: notifier.restart,
child: Text(l10n.playAgain),
),