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