< Summary

Class:DCL.SettingsCommon.PlayerPrefsGeneralSettingsRepository
Assembly:Settings
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/PlayerPrefsGeneralSettingsRepository.cs
Covered lines:41
Uncovered lines:2
Coverable lines:43
Total lines:94
Line coverage:95.3% (41 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerPrefsGeneralSettingsRepository(...)0%110100%
Apply(...)0%330100%
Reset()0%110100%
Save()0%110100%
HasAnyData()0%110100%
Load()0%11088.24%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/PlayerPrefsGeneralSettingsRepository.cs

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace 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
 64027        public PlayerPrefsGeneralSettingsRepository(
 28            IPlayerPrefsSettingsByKey settingsByKey,
 29            GeneralSettings defaultSettings)
 30        {
 64031            this.settingsByKey = settingsByKey;
 64032            this.defaultSettings = defaultSettings;
 64033            currentSettings = Load();
 64034        }
 35
 11536        public GeneralSettings Data => currentSettings;
 37
 38        public void Apply(GeneralSettings settings)
 39        {
 3640            if (currentSettings.Equals(settings))
 3041                return;
 642            currentSettings = settings;
 643            OnChanged?.Invoke(currentSettings);
 644        }
 45
 5046        public void Reset() { Apply(defaultSettings); }
 47
 48        public void Save()
 49        {
 150            settingsByKey.SetBool(PROFANITY_CHAT_FILTERING, currentSettings.profanityChatFiltering);
 151            settingsByKey.SetFloat(MOUSE_SENSITIVITY, currentSettings.mouseSensitivity);
 152            settingsByKey.SetFloat(NAMES_OPACITY, currentSettings.namesOpacity);
 153            settingsByKey.SetFloat(SCENES_LOAD_RADIUS, currentSettings.scenesLoadRadius);
 154            settingsByKey.SetFloat(VOICE_CHAT_VOLUME, currentSettings.voiceChatVolume);
 155            settingsByKey.SetFloat(AVATARS_LOD_DISTANCE, currentSettings.avatarsLODDistance);
 156            settingsByKey.SetFloat(MAX_NON_LOAD_AVATARS, currentSettings.maxNonLODAvatars);
 157            settingsByKey.SetEnum(VOICE_CHAT_ALLOW, currentSettings.voiceChatAllow);
 158            settingsByKey.SetBool(PROCEDURAL_SKYBOX_MODE, currentSettings.dynamicProceduralSkybox);
 159            settingsByKey.SetBool(INVERT_Y_AXIS, currentSettings.invertYAxis);
 160            settingsByKey.SetFloat(SKYBOX_TIME, currentSettings.skyboxTime);
 161            settingsByKey.SetFloat(FIRST_PERSON_CAMERA_FOV, currentSettings.firstPersonCameraFOV);
 162        }
 63
 11564        public bool HasAnyData() => !Data.Equals(defaultSettings);
 65
 66        private GeneralSettings Load()
 67        {
 64068            var settings = defaultSettings;
 69
 70            try
 71            {
 64072                settings.profanityChatFiltering = settingsByKey.GetBool(PROFANITY_CHAT_FILTERING,
 73                    defaultSettings.profanityChatFiltering);
 64074                settings.mouseSensitivity = settingsByKey.GetFloat(MOUSE_SENSITIVITY, defaultSettings.mouseSensitivity);
 64075                settings.namesOpacity = settingsByKey.GetFloat(NAMES_OPACITY, defaultSettings.namesOpacity);
 64076                settings.scenesLoadRadius = settingsByKey.GetFloat(SCENES_LOAD_RADIUS, defaultSettings.scenesLoadRadius)
 64077                settings.voiceChatVolume = settingsByKey.GetFloat(VOICE_CHAT_VOLUME, defaultSettings.voiceChatVolume);
 64078                settings.avatarsLODDistance = settingsByKey.GetFloat(AVATARS_LOD_DISTANCE, defaultSettings.avatarsLODDis
 64079                settings.maxNonLODAvatars = settingsByKey.GetFloat(MAX_NON_LOAD_AVATARS, defaultSettings.maxNonLODAvatar
 64080                settings.voiceChatAllow = settingsByKey.GetEnum(VOICE_CHAT_ALLOW, defaultSettings.voiceChatAllow);
 64081                settings.dynamicProceduralSkybox = settingsByKey.GetBool(PROCEDURAL_SKYBOX_MODE, defaultSettings.dynamic
 64082                settings.invertYAxis = settingsByKey.GetBool(INVERT_Y_AXIS, defaultSettings.invertYAxis);
 64083                settings.skyboxTime = settingsByKey.GetFloat(SKYBOX_TIME, defaultSettings.skyboxTime);
 64084                settings.firstPersonCameraFOV = settingsByKey.GetFloat(FIRST_PERSON_CAMERA_FOV, defaultSettings.firstPer
 64085            }
 86            catch (Exception e)
 87            {
 088                Debug.LogException(e);
 089            }
 90
 64091            return settings;
 92        }
 93    }
 94}