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:
@@ -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),
|
||||
),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../l10n/gen/app_localizations.dart';
|
||||
import 'game_screen.dart';
|
||||
import 'season_map_screen.dart';
|
||||
|
||||
class HomeScreen extends StatelessWidget {
|
||||
const HomeScreen({super.key});
|
||||
@@ -33,7 +33,7 @@ class HomeScreen extends StatelessWidget {
|
||||
onPressed: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(
|
||||
builder: (_) => const GameScreen(),
|
||||
builder: (_) => const SeasonMapScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../game/models/season.dart';
|
||||
import '../../state/providers.dart';
|
||||
import '../theme/palette.dart';
|
||||
import 'game_screen.dart';
|
||||
|
||||
/// Stage selection for the active season. Themed map art lands in Phase 6;
|
||||
/// for now a clean node grid with stars and locks.
|
||||
class SeasonMapScreen extends ConsumerWidget {
|
||||
const SeasonMapScreen({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final seasons = ref.watch(seasonsProvider);
|
||||
return seasons.when(
|
||||
loading: () =>
|
||||
const Scaffold(body: Center(child: CircularProgressIndicator())),
|
||||
error: (e, _) => Scaffold(body: Center(child: Text('$e'))),
|
||||
data: (list) => _Map(pack: list.first),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _Map extends ConsumerWidget {
|
||||
const _Map({required this.pack});
|
||||
|
||||
final SeasonPack pack;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
// Watching progress keeps stars/locks fresh after each win.
|
||||
ref.watch(progressProvider);
|
||||
final repo = ref.read(saveRepositoryProvider);
|
||||
final ids = [for (final stage in pack.stages) stage.id];
|
||||
final unlocked = repo.highestUnlockedIndex(pack.seasonId, ids);
|
||||
final totalStars = repo.totalStars(pack.seasonId);
|
||||
final locale = Localizations.localeOf(context).languageCode;
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(pack.titleFor(locale)),
|
||||
actions: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'★ $totalStars/${pack.stages.length * 3}',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleMedium
|
||||
?.copyWith(color: Colors.amber),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
body: GridView.builder(
|
||||
padding: const EdgeInsets.all(16),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
mainAxisSpacing: 12,
|
||||
crossAxisSpacing: 12,
|
||||
),
|
||||
itemCount: pack.stages.length,
|
||||
itemBuilder: (context, i) {
|
||||
final progress = repo.progressFor(pack.seasonId, ids[i]);
|
||||
final isUnlocked = i <= unlocked;
|
||||
return _StageNode(
|
||||
number: i + 1,
|
||||
stars: progress?.stars ?? 0,
|
||||
unlocked: isUnlocked,
|
||||
onTap: !isUnlocked
|
||||
? null
|
||||
: () {
|
||||
ref
|
||||
.read(seasonFlowProvider.notifier)
|
||||
.startSeasonStage(pack, i);
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (_) => const GameScreen()),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _StageNode extends StatelessWidget {
|
||||
const _StageNode({
|
||||
required this.number,
|
||||
required this.stars,
|
||||
required this.unlocked,
|
||||
required this.onTap,
|
||||
});
|
||||
|
||||
final int number;
|
||||
final int stars;
|
||||
final bool unlocked;
|
||||
final VoidCallback? onTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Material(
|
||||
color: unlocked ? GamePalette.emptyCell : GamePalette.boardBackground,
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
onTap: onTap,
|
||||
child: unlocked
|
||||
? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text(
|
||||
'$number',
|
||||
style: Theme.of(context)
|
||||
.textTheme
|
||||
.titleLarge
|
||||
?.copyWith(fontWeight: FontWeight.w800),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
for (var s = 0; s < 3; s++)
|
||||
Icon(
|
||||
Icons.star,
|
||||
size: 14,
|
||||
color: s < stars ? Colors.amber : Colors.white24,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
: const Center(
|
||||
child: Icon(Icons.lock, color: Colors.white24, size: 22),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user