feat: add heart beat for timing

This commit is contained in:
2026-06-19 02:28:07 +03:30
parent a4cf2b5f39
commit c4c1453f7e
6 changed files with 476 additions and 246 deletions
+23
View File
@@ -15,6 +15,7 @@ class AppSounds {
static const _win = 'win.mp3'; // برد بازی
static const _button = 'button.mp3'; // فشردنِ دکمه‌ها
static const _selectHokm = 'select_hokm.mp3'; // انتخابِ حکم
static const _heartBeat = 'heart_beat.mp3'; // ثانیه‌های پایانیِ نوبت
static const _all = [
_shuffle,
@@ -24,6 +25,7 @@ class AppSounds {
_win,
_button,
_selectHokm,
_heartBeat,
];
static final Map<String, AudioPool> _pools = {};
@@ -57,5 +59,26 @@ class AppSounds {
static void cut() => _play(_cut, 0.9);
static void win() => _play(_win, 0.9);
static void selectHokm() => _play(_selectHokm, 0.9);
// کنترلِ ضربانِ قلب: همیشه حداکثر یک ضربان هم‌زمان (بدون انباشت/تکرارِ سریع)
// و قابلِ توقف وقتی نوبت تمام می‌شود.
static Function? _hbStop;
static void heartBeat() {
final pool = _pools[_heartBeat];
if (muted || pool == null) return;
_hbStop?.call(); // قطعِ ضربانِ قبلی پیش از پخشِ جدید
_hbStop = null;
pool.start(volume: 0.8).then((stop) {
_hbStop = stop;
}, onError: (_) {});
}
static void stopHeartBeat() {
try {
_hbStop?.call();
} catch (_) {}
_hbStop = null;
}
static void button() => _play(_button, 0.5, cutoffMs: 130); // کلیکِ کوتاه
}