< Summary

Class:DCL.SettingsCommon.PlayerPrefsQualitySettingsRepository
Assembly:Settings
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/PlayerPrefsQualitySettingsRepository.cs
Covered lines:48
Uncovered lines:3
Coverable lines:51
Total lines:105
Line coverage:94.1% (48 of 51)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerPrefsQualitySettingsRepository(...)0%110100%
Apply(...)0%3.073080%
Reset()0%110100%
Save()0%110100%
HasAnyData()0%110100%
Load()0%11090.48%

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.SettingsCommon
 5{
 6    public class PlayerPrefsQualitySettingsRepository : ISettingsRepository<QualitySettings>
 7    {
 8        private const string DISPLAY_NAME = "displayName";
 9        private const string BLOOM = "bloom";
 10        private const string FPS_CAP = "fpsCap";
 11        private const string SOFT_SHADOWS = "softShadows";
 12        private const string ENABLE_DETAIL_OBJECT_CULLING = "enableDetailObjectCulling";
 13        private const string SHADOWS = "shadows";
 14        private const string RENDER_SCALE = "renderScale";
 15        private const string SHADOW_DISTANCE = "shadowDistance";
 16        private const string CAMERA_DRAW_DISTANCE = "cameraDrawDistance";
 17        private const string DETAIL_OBJECT_CULLING_LIMIT = "detailObjectCullingLimit";
 18        private const string ANTI_ALIASING = "antiAliasing";
 19        private const string BASE_RESOLUTION = "baseResolution";
 20        private const string SHADOW_RESOLUTION = "shadowResolution";
 21        private const string SSAO_QUALITY = "ssaoQuality";
 22        private const string MAX_HQ_AVATARS = "maxHQAvatars";
 23        private const string REFLECTION_RESOLUTION = "reflectionResolution";
 24
 25        private readonly IPlayerPrefsSettingsByKey settingsByKey;
 26        private readonly QualitySettings defaultSettings;
 27        private QualitySettings currentSettings;
 28
 29        public event Action<QualitySettings> OnChanged;
 30
 64031        public PlayerPrefsQualitySettingsRepository(
 32            IPlayerPrefsSettingsByKey settingsByKey,
 33            QualitySettings defaultSettings)
 34        {
 64035            this.settingsByKey = settingsByKey;
 64036            this.defaultSettings = defaultSettings;
 64037            currentSettings = Load();
 64038        }
 39
 5940        public QualitySettings Data => currentSettings;
 41
 42        public void Apply(QualitySettings settings)
 43        {
 3744            if (currentSettings.Equals(settings))
 3645                return;
 146            currentSettings = settings;
 147            OnChanged?.Invoke(currentSettings);
 048        }
 49
 5050        public void Reset() { Apply(defaultSettings); }
 51
 52        public void Save()
 53        {
 154            settingsByKey.SetString(DISPLAY_NAME, currentSettings.displayName);
 155            settingsByKey.SetBool(BLOOM, currentSettings.bloom);
 156            settingsByKey.SetBool(FPS_CAP, currentSettings.fpsCap);
 157            settingsByKey.SetBool(SOFT_SHADOWS, currentSettings.softShadows);
 158            settingsByKey.SetBool(ENABLE_DETAIL_OBJECT_CULLING, currentSettings.enableDetailObjectCulling);
 159            settingsByKey.SetBool(SHADOWS, currentSettings.shadows);
 160            settingsByKey.SetFloat(RENDER_SCALE, currentSettings.renderScale);
 161            settingsByKey.SetFloat(SHADOW_DISTANCE, currentSettings.shadowDistance);
 162            settingsByKey.SetFloat(CAMERA_DRAW_DISTANCE, currentSettings.cameraDrawDistance);
 163            settingsByKey.SetFloat(DETAIL_OBJECT_CULLING_LIMIT, currentSettings.detailObjectCullingLimit);
 164            settingsByKey.SetEnum(ANTI_ALIASING, currentSettings.antiAliasing);
 165            settingsByKey.SetEnum(BASE_RESOLUTION, currentSettings.baseResolution);
 166            settingsByKey.SetEnum(SHADOW_RESOLUTION, currentSettings.shadowResolution);
 167            settingsByKey.SetEnum(SSAO_QUALITY, currentSettings.ssaoQuality);
 168            settingsByKey.SetInt(MAX_HQ_AVATARS, currentSettings.maxHQAvatars);
 169            settingsByKey.SetEnum(REFLECTION_RESOLUTION, currentSettings.reflectionResolution);
 170        }
 71
 5972        public bool HasAnyData() => !Data.Equals(defaultSettings);
 73
 74        private QualitySettings Load()
 75        {
 64076            var settings = defaultSettings;
 77
 78            try
 79            {
 64080                settings.displayName = settingsByKey.GetString(DISPLAY_NAME, defaultSettings.displayName);
 64081                settings.bloom = settingsByKey.GetBool(BLOOM, defaultSettings.bloom);
 64082                settings.fpsCap = settingsByKey.GetBool(FPS_CAP, defaultSettings.fpsCap);
 64083                settings.softShadows = settingsByKey.GetBool(SOFT_SHADOWS, defaultSettings.softShadows);
 64084                settings.enableDetailObjectCulling = settingsByKey.GetBool(ENABLE_DETAIL_OBJECT_CULLING, defaultSettings
 64085                settings.shadows = settingsByKey.GetBool(SHADOWS, defaultSettings.shadows);
 64086                settings.renderScale = settingsByKey.GetFloat(RENDER_SCALE, defaultSettings.renderScale);
 64087                settings.shadowDistance = settingsByKey.GetFloat(SHADOW_DISTANCE, defaultSettings.shadowDistance);
 64088                settings.cameraDrawDistance = settingsByKey.GetFloat(CAMERA_DRAW_DISTANCE, defaultSettings.cameraDrawDis
 64089                settings.detailObjectCullingLimit = settingsByKey.GetFloat(DETAIL_OBJECT_CULLING_LIMIT, defaultSettings.
 64090                settings.antiAliasing = settingsByKey.GetEnum(ANTI_ALIASING, defaultSettings.antiAliasing);
 64091                settings.baseResolution = settingsByKey.GetEnum(BASE_RESOLUTION, defaultSettings.baseResolution);
 64092                settings.shadowResolution = settingsByKey.GetEnum(SHADOW_RESOLUTION, defaultSettings.shadowResolution);
 64093                settings.ssaoQuality = settingsByKey.GetEnum(SSAO_QUALITY, defaultSettings.ssaoQuality);
 64094                settings.maxHQAvatars = settingsByKey.GetInt(MAX_HQ_AVATARS, defaultSettings.maxHQAvatars);
 64095                settings.reflectionResolution = settingsByKey.GetEnum(REFLECTION_RESOLUTION, defaultSettings.reflectionR
 64096            }
 97            catch (Exception e)
 98            {
 099                Debug.LogException(e);
 0100            }
 101
 640102            return settings;
 103        }
 104    }
 105}