| | 1 | | using System; |
| | 2 | | using UnityEngine; |
| | 3 | |
|
| | 4 | | namespace DCL.SettingsCommon |
| | 5 | | { |
| | 6 | | public class PlayerPrefsGeneralSettingsRepository : ISettingsRepository<GeneralSettings> |
| | 7 | | { |
| | 8 | | public const string AUTO_QUALITY_ON = "autoqualityOn"; |
| | 9 | | public const string PROFANITY_CHAT_FILTERING = "profanityChatFiltering"; |
| | 10 | | public const string MOUSE_SENSITIVITY = "mouseSensitivity"; |
| | 11 | | public const string NAMES_OPACITY = "namesOpacity"; |
| | 12 | | public const string SCENES_LOAD_RADIUS = "scenesLoadRadius"; |
| | 13 | | public const string VOICE_CHAT_VOLUME = "voiceChatVolume"; |
| | 14 | | public const string AVATARS_LOD_DISTANCE = "avatarsLODDistance"; |
| | 15 | | public const string MAX_NON_LOAD_AVATARS = "maxNonLODAvatars"; |
| | 16 | | public const string VOICE_CHAT_ALLOW = "voiceChatAllow"; |
| | 17 | |
|
| | 18 | | private readonly IPlayerPrefsSettingsByKey settingsByKey; |
| | 19 | | private readonly GeneralSettings defaultSettings; |
| | 20 | | private GeneralSettings currentSettings; |
| | 21 | |
|
| | 22 | | public event Action<GeneralSettings> OnChanged; |
| | 23 | |
|
| 1 | 24 | | public PlayerPrefsGeneralSettingsRepository( |
| | 25 | | IPlayerPrefsSettingsByKey settingsByKey, |
| | 26 | | GeneralSettings defaultSettings) |
| | 27 | | { |
| 1 | 28 | | this.settingsByKey = settingsByKey; |
| 1 | 29 | | this.defaultSettings = defaultSettings; |
| 1 | 30 | | currentSettings = Load(); |
| 1 | 31 | | } |
| | 32 | |
|
| 57 | 33 | | public GeneralSettings Data => currentSettings; |
| | 34 | |
|
| | 35 | | public void Apply(GeneralSettings settings) |
| | 36 | | { |
| 44 | 37 | | if (currentSettings.Equals(settings)) return; |
| 0 | 38 | | currentSettings = settings; |
| 0 | 39 | | OnChanged?.Invoke(currentSettings); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | public void Reset() |
| | 43 | | { |
| 22 | 44 | | Apply(defaultSettings); |
| 22 | 45 | | } |
| | 46 | |
|
| | 47 | | public void Save() |
| | 48 | | { |
| 0 | 49 | | settingsByKey.SetBool(AUTO_QUALITY_ON, currentSettings.autoqualityOn); |
| 0 | 50 | | settingsByKey.SetBool(PROFANITY_CHAT_FILTERING, currentSettings.profanityChatFiltering); |
| 0 | 51 | | settingsByKey.SetFloat(MOUSE_SENSITIVITY, currentSettings.mouseSensitivity); |
| 0 | 52 | | settingsByKey.SetFloat(NAMES_OPACITY, currentSettings.namesOpacity); |
| 0 | 53 | | settingsByKey.SetFloat(SCENES_LOAD_RADIUS, currentSettings.scenesLoadRadius); |
| 0 | 54 | | settingsByKey.SetFloat(VOICE_CHAT_VOLUME, currentSettings.voiceChatVolume); |
| 0 | 55 | | settingsByKey.SetFloat(AVATARS_LOD_DISTANCE, currentSettings.avatarsLODDistance); |
| 0 | 56 | | settingsByKey.SetFloat(MAX_NON_LOAD_AVATARS, currentSettings.maxNonLODAvatars); |
| 0 | 57 | | settingsByKey.SetEnum(VOICE_CHAT_ALLOW, currentSettings.voiceChatAllow); |
| 0 | 58 | | } |
| | 59 | |
|
| 57 | 60 | | public bool HasAnyData() => !Data.Equals(defaultSettings); |
| | 61 | |
|
| | 62 | | private GeneralSettings Load() |
| | 63 | | { |
| 1 | 64 | | var settings = defaultSettings; |
| | 65 | |
|
| | 66 | | try |
| | 67 | | { |
| 1 | 68 | | settings.autoqualityOn = settingsByKey.GetBool(AUTO_QUALITY_ON, defaultSettings.autoqualityOn); |
| 1 | 69 | | settings.profanityChatFiltering = settingsByKey.GetBool(PROFANITY_CHAT_FILTERING, |
| | 70 | | defaultSettings.profanityChatFiltering); |
| 1 | 71 | | settings.mouseSensitivity = settingsByKey.GetFloat(MOUSE_SENSITIVITY, defaultSettings.mouseSensitivity); |
| 1 | 72 | | settings.namesOpacity = settingsByKey.GetFloat(NAMES_OPACITY, defaultSettings.namesOpacity); |
| 1 | 73 | | settings.scenesLoadRadius = settingsByKey.GetFloat(SCENES_LOAD_RADIUS, defaultSettings.scenesLoadRadius) |
| 1 | 74 | | settings.voiceChatVolume = settingsByKey.GetFloat(VOICE_CHAT_VOLUME, defaultSettings.voiceChatVolume); |
| 1 | 75 | | settings.avatarsLODDistance = settingsByKey.GetFloat(AVATARS_LOD_DISTANCE, defaultSettings.avatarsLODDis |
| 1 | 76 | | settings.maxNonLODAvatars = settingsByKey.GetFloat(MAX_NON_LOAD_AVATARS, defaultSettings.maxNonLODAvatar |
| 1 | 77 | | settings.voiceChatAllow = settingsByKey.GetEnum(VOICE_CHAT_ALLOW, defaultSettings.voiceChatAllow); |
| 1 | 78 | | } |
| | 79 | | catch (Exception e) |
| | 80 | | { |
| 0 | 81 | | Debug.LogException(e); |
| 0 | 82 | | } |
| | 83 | |
|
| 1 | 84 | | return settings; |
| | 85 | | } |
| | 86 | | } |
| | 87 | | } |