fix: hide spent rescue to prevent StateError crash; log per-attempt starts
Expose engine.rescueUsed getter and surface it through GameViewState so the result overlay can omit the watch-ad FilledButton after a rescue has been consumed, preventing a second tap from calling useContinue / addExtraMoves and hitting their StateError guard. Give-up is promoted to FilledButton when rescue is unavailable for clear affordance. Also emit stageStart / endlessStart analytics in restart() so every attempt (not just the first) is bracketed by a matching start event. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import '../game/models/grid.dart';
|
||||
import '../game/models/objective.dart';
|
||||
import '../game/models/piece.dart';
|
||||
import '../game/models/stage.dart';
|
||||
import 'providers.dart';
|
||||
|
||||
/// Immutable snapshot of one engine moment; the only game state the UI sees.
|
||||
class GameViewState {
|
||||
@@ -24,6 +25,7 @@ class GameViewState {
|
||||
required this.lastPlacement,
|
||||
required this.fxTick,
|
||||
required this.endless,
|
||||
required this.rescueUsed,
|
||||
});
|
||||
|
||||
final GridState grid;
|
||||
@@ -43,6 +45,7 @@ class GameViewState {
|
||||
final int fxTick;
|
||||
|
||||
final bool endless;
|
||||
final bool rescueUsed;
|
||||
}
|
||||
|
||||
/// Bridges the pure-Dart [GameEngine] to the widget tree. The engine object
|
||||
@@ -72,6 +75,17 @@ class GameSessionNotifier extends Notifier<GameViewState?> {
|
||||
final stage = _stage;
|
||||
if (stage == null) throw StateError('no stage to restart');
|
||||
startStage(stage, attempt: _attempt + 1, generator: _generatorOverride);
|
||||
if (stage.endless) {
|
||||
ref.read(analyticsProvider).endlessStart();
|
||||
} else {
|
||||
final flow = ref.read(seasonFlowProvider);
|
||||
if (flow != null) {
|
||||
ref.read(analyticsProvider).stageStart(
|
||||
seasonId: flow.pack.seasonId,
|
||||
stageId: flow.stage.id,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool tryPlace(int trayIndex, int x, int y) {
|
||||
@@ -119,6 +133,7 @@ class GameSessionNotifier extends Notifier<GameViewState?> {
|
||||
objectiveProgress: engine.objectiveProgress,
|
||||
lastPlacement: lastPlacement,
|
||||
fxTick: _fxTick,
|
||||
rescueUsed: engine.rescueUsed,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user