feat: add sounds

This commit is contained in:
2026-06-18 21:57:28 +03:30
parent 519752b478
commit f4d99043c4
18 changed files with 312 additions and 55 deletions
@@ -6,6 +6,7 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
import '../../../../core/network/ws_client.dart';
import '../../../../core/service/app_sounds.dart';
import '../../../../core/theme/app_theme.dart';
import '../../../wallet/presentation/bloc/wallet_bloc.dart';
import '../../../wallet/presentation/bloc/wallet_event.dart';
@@ -51,19 +52,32 @@ class _GameScreenState extends State<GameScreen> {
},
child: Scaffold(
body: BlocConsumer<GameBloc, GameUiState>(
listenWhen: (a, b) => a.notice != b.notice && b.notice != null,
listenWhen: (a, b) =>
(a.notice != b.notice && b.notice != null) ||
(a.gameOver == null && b.gameOver != null),
listener: (context, state) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.notice!),
duration: const Duration(seconds: 2)),
);
context.read<GameBloc>().clearNotice();
if (state.gameOver != null) {
final won = state.gameOver!.winnerTeam ==
(state.state?.yourSeat ?? 0) % 2;
if (won) AppSounds.win();
}
if (state.notice != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(state.notice!),
duration: const Duration(seconds: 2)),
);
context.read<GameBloc>().clearNotice();
}
},
builder: (context, state) {
if (state.state != null && _introTimer == null) {
_introTimer = Timer(const Duration(milliseconds: 1600), () {
if (mounted) setState(() => _introHidden = true);
// کمی «حریفان پیدا شد» نشان بده، بعد اوورلی را کنار بزن و همان
// لحظه انیمیشنِ بُر زدن (با صدا) را اجرا کن.
_introTimer = Timer(const Duration(milliseconds: 700), () {
if (!mounted) return;
setState(() => _introHidden = true);
_game.endIntro();
});
}
return Stack(
@@ -130,6 +144,7 @@ class _GameScreenState extends State<GameScreen> {
}
void _exitToLobby(BuildContext context) {
_game.silence(); // پس از خروج، صدای کارت‌های بات پخش نشود
context.read<WalletBloc>().add(LoadWalletEvent());
context.go('/lobby');
}