Auto-sync: 20260304_210000
This commit is contained in:
parent
37d638816a
commit
c83cc6b9ae
12 changed files with 112 additions and 7 deletions
BIN
.DS_Store
vendored
BIN
.DS_Store
vendored
Binary file not shown.
BIN
assets/.DS_Store
vendored
BIN
assets/.DS_Store
vendored
Binary file not shown.
BIN
assets/audio/.DS_Store
vendored
Normal file
BIN
assets/audio/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
assets/audio/bgm/8-bit_Prowler.mp3
Normal file
BIN
assets/audio/bgm/8-bit_Prowler.mp3
Normal file
Binary file not shown.
BIN
assets/audio/bgm/Cyber_Dystopia.mp3
Normal file
BIN
assets/audio/bgm/Cyber_Dystopia.mp3
Normal file
Binary file not shown.
BIN
assets/audio/bgm/Grimorio_Astral.mp3
Normal file
BIN
assets/audio/bgm/Grimorio_Astral.mp3
Normal file
Binary file not shown.
BIN
assets/audio/bgm/Legno_Canopy.mp3
Normal file
BIN
assets/audio/bgm/Legno_Canopy.mp3
Normal file
Binary file not shown.
BIN
assets/audio/bgm/Quad_Dreams.mp3
Normal file
BIN
assets/audio/bgm/Quad_Dreams.mp3
Normal file
Binary file not shown.
|
|
@ -1,6 +1,11 @@
|
||||||
|
// ===========================================================================
|
||||||
|
// FILE: lib/core/theme_manager.dart
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'app_colors.dart';
|
import 'app_colors.dart';
|
||||||
import '../services/storage_service.dart';
|
import '../services/storage_service.dart';
|
||||||
|
import '../services/audio_service.dart'; // <-- NUOVO IMPORT PER LA MUSICA
|
||||||
|
|
||||||
class ThemeManager extends ChangeNotifier {
|
class ThemeManager extends ChangeNotifier {
|
||||||
late AppThemeType _currentThemeType;
|
late AppThemeType _currentThemeType;
|
||||||
|
|
@ -8,6 +13,9 @@ class ThemeManager extends ChangeNotifier {
|
||||||
ThemeManager() {
|
ThemeManager() {
|
||||||
// Quando l'app parte, legge il tema dalla memoria!
|
// Quando l'app parte, legge il tema dalla memoria!
|
||||||
_currentThemeType = AppThemeType.values[StorageService.instance.savedThemeIndex];
|
_currentThemeType = AppThemeType.values[StorageService.instance.savedThemeIndex];
|
||||||
|
|
||||||
|
// Fai partire subito la colonna sonora del tema salvato!
|
||||||
|
AudioService.instance.playBgm(_currentThemeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
AppThemeType get currentThemeType => _currentThemeType;
|
AppThemeType get currentThemeType => _currentThemeType;
|
||||||
|
|
@ -16,6 +24,10 @@ class ThemeManager extends ChangeNotifier {
|
||||||
void setTheme(AppThemeType type) {
|
void setTheme(AppThemeType type) {
|
||||||
_currentThemeType = type;
|
_currentThemeType = type;
|
||||||
StorageService.instance.saveTheme(type); // Salva la scelta nel "disco fisso"
|
StorageService.instance.saveTheme(type); // Salva la scelta nel "disco fisso"
|
||||||
|
|
||||||
|
// Cambia magicamente la canzone in sottofondo!
|
||||||
|
AudioService.instance.playBgm(type);
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
|
// ===========================================================================
|
||||||
|
// FILE: lib/main.dart
|
||||||
|
// ===========================================================================
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/foundation.dart'; // <-- AGGIUNTO PER kDebugMode
|
import 'package:flutter/foundation.dart'; // <-- AGGIUNTO PER kDebugMode
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
@ -5,6 +9,7 @@ import 'core/theme_manager.dart';
|
||||||
import 'logic/game_controller.dart';
|
import 'logic/game_controller.dart';
|
||||||
import 'ui/home/home_screen.dart';
|
import 'ui/home/home_screen.dart';
|
||||||
import 'services/storage_service.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_core/firebase_core.dart';
|
||||||
import 'package:firebase_auth/firebase_auth.dart';
|
import 'package:firebase_auth/firebase_auth.dart';
|
||||||
import 'firebase_options.dart';
|
import 'firebase_options.dart';
|
||||||
|
|
@ -36,6 +41,9 @@ void main() async {
|
||||||
// 3. Accendiamo la Memoria Locale!
|
// 3. Accendiamo la Memoria Locale!
|
||||||
await StorageService.instance.init();
|
await StorageService.instance.init();
|
||||||
|
|
||||||
|
// 4. Accendiamo la Radio! (Lettore Musicale)
|
||||||
|
await AudioService.instance.init();
|
||||||
|
|
||||||
runApp(
|
runApp(
|
||||||
MultiProvider(
|
MultiProvider(
|
||||||
providers: [
|
providers: [
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:audioplayers/audioplayers.dart';
|
import 'package:audioplayers/audioplayers.dart';
|
||||||
import '../core/app_colors.dart';
|
import '../core/app_colors.dart';
|
||||||
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
class AudioService extends ChangeNotifier {
|
class AudioService extends ChangeNotifier {
|
||||||
static final AudioService instance = AudioService._internal();
|
static final AudioService instance = AudioService._internal();
|
||||||
|
|
@ -12,27 +13,99 @@ class AudioService extends ChangeNotifier {
|
||||||
|
|
||||||
bool isMuted = false;
|
bool isMuted = false;
|
||||||
final AudioPlayer _sfxPlayer = AudioPlayer();
|
final AudioPlayer _sfxPlayer = AudioPlayer();
|
||||||
|
final AudioPlayer _bgmPlayer = AudioPlayer();
|
||||||
|
|
||||||
void toggleMute() {
|
Future<void> 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;
|
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();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- BGM (Musica di sottofondo) ---
|
||||||
|
Future<void> 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<void> stopBgm() async {
|
||||||
|
await _bgmPlayer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- SFX (Effetti sonori) ---
|
||||||
void playLineSfx(AppThemeType theme) async {
|
void playLineSfx(AppThemeType theme) async {
|
||||||
if (isMuted) return;
|
if (isMuted) return;
|
||||||
String file = '';
|
String file = '';
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
case AppThemeType.minimal:
|
case AppThemeType.minimal:
|
||||||
case AppThemeType.arcade: // Suono secco per l'arcade
|
case AppThemeType.arcade:
|
||||||
file = 'minimal_line.wav'; break;
|
file = 'minimal_line.wav'; break;
|
||||||
case AppThemeType.doodle:
|
case AppThemeType.doodle:
|
||||||
case AppThemeType.wood:
|
case AppThemeType.wood:
|
||||||
file = 'doodle_line.wav'; break;
|
file = 'doodle_line.wav'; break;
|
||||||
case AppThemeType.cyberpunk:
|
case AppThemeType.cyberpunk:
|
||||||
case AppThemeType.grimorio: // Suono etereo per la magia
|
case AppThemeType.grimorio:
|
||||||
file = 'cyber_line.wav'; break;
|
file = 'cyber_line.wav'; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file.isNotEmpty) {
|
||||||
|
try {
|
||||||
await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
|
await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Errore SFX Linea non trovato: $file");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void playBoxSfx(AppThemeType theme) async {
|
void playBoxSfx(AppThemeType theme) async {
|
||||||
|
|
@ -49,16 +122,27 @@ class AudioService extends ChangeNotifier {
|
||||||
case AppThemeType.grimorio:
|
case AppThemeType.grimorio:
|
||||||
file = 'cyber_box.wav'; break;
|
file = 'cyber_box.wav'; break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (file.isNotEmpty) {
|
||||||
|
try {
|
||||||
await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
|
await _sfxPlayer.play(AssetSource('audio/sfx/$file'));
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Errore SFX Box non trovato: $file");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void playBonusSfx() async {
|
void playBonusSfx() async {
|
||||||
if (isMuted) return;
|
if (isMuted) return;
|
||||||
|
try {
|
||||||
await _sfxPlayer.play(AssetSource('audio/sfx/bonus.wav'));
|
await _sfxPlayer.play(AssetSource('audio/sfx/bonus.wav'));
|
||||||
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
void playBombSfx() async {
|
void playBombSfx() async {
|
||||||
if (isMuted) return;
|
if (isMuted) return;
|
||||||
|
try {
|
||||||
await _sfxPlayer.play(AssetSource('audio/sfx/bomb.wav'));
|
await _sfxPlayer.play(AssetSource('audio/sfx/bomb.wav'));
|
||||||
|
} catch(e) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -43,6 +43,7 @@ flutter:
|
||||||
- assets/images/
|
- assets/images/
|
||||||
- assets/audio/bgm/
|
- assets/audio/bgm/
|
||||||
- assets/audio/sfx/
|
- assets/audio/sfx/
|
||||||
|
- assets/audio/
|
||||||
|
|
||||||
|
|
||||||
flutter_icons:
|
flutter_icons:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue