Add daily streak system and normalize bundle id to com.airkjw.blockseasons

Pure advanceStreak (1-day grace none, milestone flags at 3/7/14/30),
persisted in the save blob; StreakNotifier advances on every finished
attempt; home screen flame chip and milestone snackbar. Fix flutter
create's camelCased iOS bundle id and underscored Android application
id to the agreed lowercase form before any store registration.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-11 17:25:39 +09:00
parent 7bc26447f7
commit 607278928b
14 changed files with 271 additions and 15 deletions
+23
View File
@@ -2,6 +2,8 @@ import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'streak.dart';
class StageProgress {
const StageProgress({required this.stars, required this.bestScore});
@@ -24,6 +26,14 @@ class SaveRepository {
bestScore: value['bestScore'] as int,
);
}
final streak = json['streak'] as Map<String, dynamic>?;
if (streak != null) {
_streak = StreakState(
current: streak['current'] as int,
best: streak['best'] as int,
lastYmd: streak['lastYmd'] as String?,
);
}
}
}
@@ -34,6 +44,14 @@ class SaveRepository {
final SharedPreferences _prefs;
final Map<String, StageProgress> _progress = {};
StreakState _streak = StreakState.initial;
StreakState get streak => _streak;
Future<void> saveStreak(StreakState streak) {
_streak = streak;
return _flush();
}
static String _id(String seasonId, String stageId) => '$seasonId/$stageId';
@@ -88,6 +106,11 @@ class SaveRepository {
'bestScore': entry.value.bestScore,
},
},
'streak': {
'current': _streak.current,
'best': _streak.best,
'lastYmd': _streak.lastYmd,
},
}),
);
}
+49
View File
@@ -0,0 +1,49 @@
/// Daily streak: at least one stage attempt (win or lose) per local
/// calendar day keeps it alive. No clock-cheat defense — single-player,
/// low stakes.
class StreakState {
const StreakState({
required this.current,
required this.best,
required this.lastYmd,
this.hitMilestone,
});
static const initial = StreakState(current: 0, best: 0, lastYmd: null);
static const milestones = [3, 7, 14, 30];
final int current;
final int best;
/// Local date of the last counted play, as `yyyy-MM-dd`.
final String? lastYmd;
/// Set when this advance just reached a milestone (celebrate once).
final int? hitMilestone;
}
String _ymd(DateTime d) =>
'${d.year.toString().padLeft(4, '0')}-'
'${d.month.toString().padLeft(2, '0')}-'
'${d.day.toString().padLeft(2, '0')}';
StreakState advanceStreak(StreakState state, DateTime now) {
final today = _ymd(now);
if (state.lastYmd == today) {
return StreakState(
current: state.current,
best: state.best,
lastYmd: today,
);
}
// Normalized constructor handles month/year boundaries (and DST).
final yesterday = _ymd(DateTime(now.year, now.month, now.day - 1));
final current = state.lastYmd == yesterday ? state.current + 1 : 1;
return StreakState(
current: current,
best: current > state.best ? current : state.best,
lastYmd: today,
hitMilestone: StreakState.milestones.contains(current) ? current : null,
);
}