settings_manager.dart 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import 'package:shared_preferences/shared_preferences.dart';
  2. import '../game/audio/audio_manager.dart';
  3. class SettingsManager {
  4. static const String _keyMusicEnabled = 'music_enabled';
  5. static const String _keyHapticsEnabled = 'haptics_enabled';
  6. static const String _keyTutorialShown = 'tutorial_shown';
  7. static const String _keyBgmVolume = 'bgm_volume';
  8. static const String _keySfxVolume = 'sfx_volume';
  9. static SharedPreferences? _prefs;
  10. static Future<void> init() async {
  11. _prefs = await SharedPreferences.getInstance();
  12. }
  13. // Music Settings
  14. static bool get isMusicEnabled => _prefs?.getBool(_keyMusicEnabled) ?? true;
  15. static Future<void> setMusicEnabled(bool enabled) async {
  16. await _prefs?.setBool(_keyMusicEnabled, enabled);
  17. }
  18. // Haptics Settings
  19. static bool get isHapticsEnabled => _prefs?.getBool(_keyHapticsEnabled) ?? true;
  20. static Future<void> setHapticsEnabled(bool enabled) async {
  21. await _prefs?.setBool(_keyHapticsEnabled, enabled);
  22. }
  23. // BGM Volume Settings
  24. static double get bgmVolume => _prefs?.getDouble(_keyBgmVolume) ?? 0.4;
  25. static Future<void> setBgmVolume(double volume) async {
  26. await _prefs?.setDouble(_keyBgmVolume, volume);
  27. }
  28. // SFX Volume Settings
  29. static double get sfxVolume => _prefs?.getDouble(_keySfxVolume) ?? 0.6;
  30. static Future<void> setSfxVolume(double volume) async {
  31. await _prefs?.setDouble(_keySfxVolume, volume);
  32. }
  33. // Apply BGM volume to AudioManager
  34. static void applyBgmVolume() {
  35. AudioManager().setBgmVolume(bgmVolume);
  36. }
  37. // Tutorial Settings
  38. static bool get isTutorialShown => _prefs?.getBool(_keyTutorialShown) ?? false;
  39. static Future<void> setTutorialShown(bool shown) async {
  40. await _prefs?.setBool(_keyTutorialShown, shown);
  41. }
  42. }