| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- import 'package:shared_preferences/shared_preferences.dart';
- import '../game/audio/audio_manager.dart';
- class SettingsManager {
- static const String _keyMusicEnabled = 'music_enabled';
- static const String _keyHapticsEnabled = 'haptics_enabled';
- static const String _keyTutorialShown = 'tutorial_shown';
- static const String _keyBgmVolume = 'bgm_volume';
- static const String _keySfxVolume = 'sfx_volume';
- static SharedPreferences? _prefs;
- static Future<void> init() async {
- _prefs = await SharedPreferences.getInstance();
- }
- // Music Settings
- static bool get isMusicEnabled => _prefs?.getBool(_keyMusicEnabled) ?? true;
-
- static Future<void> setMusicEnabled(bool enabled) async {
- await _prefs?.setBool(_keyMusicEnabled, enabled);
- }
- // Haptics Settings
- static bool get isHapticsEnabled => _prefs?.getBool(_keyHapticsEnabled) ?? true;
-
- static Future<void> setHapticsEnabled(bool enabled) async {
- await _prefs?.setBool(_keyHapticsEnabled, enabled);
- }
- // BGM Volume Settings
- static double get bgmVolume => _prefs?.getDouble(_keyBgmVolume) ?? 0.4;
-
- static Future<void> setBgmVolume(double volume) async {
- await _prefs?.setDouble(_keyBgmVolume, volume);
- }
- // SFX Volume Settings
- static double get sfxVolume => _prefs?.getDouble(_keySfxVolume) ?? 0.6;
-
- static Future<void> setSfxVolume(double volume) async {
- await _prefs?.setDouble(_keySfxVolume, volume);
- }
- // Apply BGM volume to AudioManager
- static void applyBgmVolume() {
- AudioManager().setBgmVolume(bgmVolume);
- }
- // Tutorial Settings
- static bool get isTutorialShown => _prefs?.getBool(_keyTutorialShown) ?? false;
-
- static Future<void> setTutorialShown(bool shown) async {
- await _prefs?.setBool(_keyTutorialShown, shown);
- }
- }
|