diff --git a/.DS_Store b/.DS_Store index 3087572..1772090 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/assets/.DS_Store b/assets/.DS_Store index cfbf861..e9fe782 100644 Binary files a/assets/.DS_Store and b/assets/.DS_Store differ diff --git a/assets/audio/.DS_Store b/assets/audio/.DS_Store new file mode 100644 index 0000000..9afef4d Binary files /dev/null and b/assets/audio/.DS_Store differ diff --git a/assets/audio/bgm/8-bit_Prowler.mp3 b/assets/audio/bgm/8-bit_Prowler.mp3 new file mode 100644 index 0000000..d39ba82 Binary files /dev/null and b/assets/audio/bgm/8-bit_Prowler.mp3 differ diff --git a/assets/audio/bgm/Cyber_Dystopia.mp3 b/assets/audio/bgm/Cyber_Dystopia.mp3 new file mode 100644 index 0000000..2959500 Binary files /dev/null and b/assets/audio/bgm/Cyber_Dystopia.mp3 differ diff --git a/assets/audio/bgm/Grimorio_Astral.mp3 b/assets/audio/bgm/Grimorio_Astral.mp3 new file mode 100644 index 0000000..c7232a9 Binary files /dev/null and b/assets/audio/bgm/Grimorio_Astral.mp3 differ diff --git a/assets/audio/bgm/Legno_Canopy.mp3 b/assets/audio/bgm/Legno_Canopy.mp3 new file mode 100644 index 0000000..39d31d8 Binary files /dev/null and b/assets/audio/bgm/Legno_Canopy.mp3 differ diff --git a/assets/audio/bgm/Quad_Dreams.mp3 b/assets/audio/bgm/Quad_Dreams.mp3 new file mode 100644 index 0000000..5b7b553 Binary files /dev/null and b/assets/audio/bgm/Quad_Dreams.mp3 differ diff --git a/lib/core/theme_manager.dart b/lib/core/theme_manager.dart index 40a6665..3a2b092 100644 --- a/lib/core/theme_manager.dart +++ b/lib/core/theme_manager.dart @@ -1,6 +1,11 @@ +// =========================================================================== +// FILE: lib/core/theme_manager.dart +// =========================================================================== + import 'package:flutter/material.dart'; import 'app_colors.dart'; import '../services/storage_service.dart'; +import '../services/audio_service.dart'; // <-- NUOVO IMPORT PER LA MUSICA class ThemeManager extends ChangeNotifier { late AppThemeType _currentThemeType; @@ -8,6 +13,9 @@ class ThemeManager extends ChangeNotifier { ThemeManager() { // Quando l'app parte, legge il tema dalla memoria! _currentThemeType = AppThemeType.values[StorageService.instance.savedThemeIndex]; + + // Fai partire subito la colonna sonora del tema salvato! + AudioService.instance.playBgm(_currentThemeType); } AppThemeType get currentThemeType => _currentThemeType; @@ -16,6 +24,10 @@ class ThemeManager extends ChangeNotifier { void setTheme(AppThemeType type) { _currentThemeType = type; StorageService.instance.saveTheme(type); // Salva la scelta nel "disco fisso" + + // Cambia magicamente la canzone in sottofondo! + AudioService.instance.playBgm(type); + notifyListeners(); } } \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index ba3f0b5..838e30a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,3 +1,7 @@ +// =========================================================================== +// FILE: lib/main.dart +// =========================================================================== + import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; // <-- AGGIUNTO PER kDebugMode import 'package:provider/provider.dart'; @@ -5,6 +9,7 @@ import 'core/theme_manager.dart'; import 'logic/game_controller.dart'; import 'ui/home/home_screen.dart'; import 'services/storage_service.dart'; +import 'services/audio_service.dart'; // <-- NUOVO IMPORT PER L'AUDIO import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_auth/firebase_auth.dart'; import 'firebase_options.dart'; @@ -36,6 +41,9 @@ void main() async { // 3. Accendiamo la Memoria Locale! await StorageService.instance.init(); + // 4. Accendiamo la Radio! (Lettore Musicale) + await AudioService.instance.init(); + runApp( MultiProvider( providers: [ diff --git a/lib/services/audio_service.dart b/lib/services/audio_service.dart index 982e2bf..aafcdbb 100644 --- a/lib/services/audio_service.dart +++ b/lib/services/audio_service.dart @@ -5,6 +5,7 @@ import 'package:flutter/material.dart'; import 'package:audioplayers/audioplayers.dart'; import '../core/app_colors.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class AudioService extends ChangeNotifier { static final AudioService instance = AudioService._internal(); @@ -12,27 +13,99 @@ class AudioService extends ChangeNotifier { bool isMuted = false; final AudioPlayer _sfxPlayer = AudioPlayer(); + final AudioPlayer _bgmPlayer = AudioPlayer(); - void toggleMute() { + Future init() async { + // 1. Carica la preferenza salvata + final prefs = await SharedPreferences.getInstance(); + isMuted = prefs.getBool('isMuted') ?? false; + + // 2. Imposta la musica in loop infinito + await _bgmPlayer.setReleaseMode(ReleaseMode.loop); + } + + void toggleMute() async { isMuted = !isMuted; + + // Salva la scelta per il prossimo riavvio + final prefs = await SharedPreferences.getInstance(); + await prefs.setBool('isMuted', isMuted); + + if (isMuted) { + _bgmPlayer.pause(); + } else { + _bgmPlayer.resume(); + } notifyListeners(); } + // --- BGM (Musica di sottofondo) --- + Future playBgm(AppThemeType theme) async { + await _bgmPlayer.stop(); // Ferma la canzone precedente + + if (isMuted) return; + + String audioPath = ''; + + // Assegna a ogni tema la sua colonna sonora + switch (theme) { + case AppThemeType.cyberpunk: + audioPath = 'audio/bgm/Cyber_Dystopia.mp3'; + break; + case AppThemeType.doodle: + audioPath = 'audio/bgm/Quad_Dreams.mp3'; + break; + case AppThemeType.wood: + audioPath = 'audio/bgm/Legno_Canopy.mp3'; + break; + case AppThemeType.arcade: + audioPath = 'audio/bgm/8-bit_Prowler.mp3'; + break; + case AppThemeType.grimorio: + audioPath = 'audio/bgm/Grimorio_Astral.mp3'; + break; + case AppThemeType.minimal: + // Il tema minimal non ha musica (silenzio/focus) + audioPath = ''; + break; + } + + if (audioPath.isNotEmpty) { + try { + await _bgmPlayer.play(AssetSource(audioPath), volume: 0.4); + } catch (e) { + debugPrint("Errore riproduzione BGM: $e"); + } + } + } + + Future stopBgm() async { + await _bgmPlayer.stop(); + } + + // --- SFX (Effetti sonori) --- void playLineSfx(AppThemeType theme) async { if (isMuted) return; String file = ''; switch (theme) { case AppThemeType.minimal: - case AppThemeType.arcade: // Suono secco per l'arcade + case AppThemeType.arcade: file = 'minimal_line.wav'; break; case AppThemeType.doodle: case AppThemeType.wood: file = 'doodle_line.wav'; break; case AppThemeType.cyberpunk: - case AppThemeType.grimorio: // Suono etereo per la magia + case AppThemeType.grimorio: file = 'cyber_line.wav'; break; } - await _sfxPlayer.play(AssetSource('audio/sfx/$file')); + + if (file.isNotEmpty) { + try { + await _sfxPlayer.play(AssetSource('audio/sfx/$file')); + } catch (e) { + debugPrint("Errore SFX Linea non trovato: $file"); + } + } } void playBoxSfx(AppThemeType theme) async { @@ -49,16 +122,27 @@ class AudioService extends ChangeNotifier { case AppThemeType.grimorio: file = 'cyber_box.wav'; break; } - await _sfxPlayer.play(AssetSource('audio/sfx/$file')); + + if (file.isNotEmpty) { + try { + await _sfxPlayer.play(AssetSource('audio/sfx/$file')); + } catch (e) { + debugPrint("Errore SFX Box non trovato: $file"); + } + } } void playBonusSfx() async { if (isMuted) return; - await _sfxPlayer.play(AssetSource('audio/sfx/bonus.wav')); + try { + await _sfxPlayer.play(AssetSource('audio/sfx/bonus.wav')); + } catch(e) {} } void playBombSfx() async { if (isMuted) return; - await _sfxPlayer.play(AssetSource('audio/sfx/bomb.wav')); + try { + await _sfxPlayer.play(AssetSource('audio/sfx/bomb.wav')); + } catch(e) {} } } \ No newline at end of file diff --git a/pubspec.yaml b/pubspec.yaml index 7e1640b..2fa4fa4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,6 +43,7 @@ flutter: - assets/images/ - assets/audio/bgm/ - assets/audio/sfx/ + - assets/audio/ flutter_icons: