< Summary

Class:MainScripts.DCL.Controllers.SettingsDesktop.PlayerPrefsDesktopDisplaySettingsRepository
Assembly:SettingsDesktop
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/SettingsDesktop/PlayerPrefsDesktopDisplaySettingsRepository.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:70
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerPrefsDesktopDisplaySettingsRepository(...)0%2100%
Apply(...)0%12300%
Reset()0%2100%
Save()0%2100%
HasAnyData()0%2100%
Load()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/SettingsDesktop/PlayerPrefsDesktopDisplaySettingsRepository.cs

#LineLine coverage
 1using System;
 2using DCL.SettingsCommon;
 3using UnityEngine;
 4
 5namespace MainScripts.DCL.Controllers.SettingsDesktop
 6{
 7    public class PlayerPrefsDesktopDisplaySettingsRepository : ISettingsRepository<DisplaySettings>
 8    {
 9        public const string VSYNC = "vSync";
 10        public const string RESOLUTION_SIZE_INDEX = "resolutionSizeIndexV2";
 11        public const string WINDOW_MODE = "windowMode";
 12        public const string FPS_CAP = "fpsCap";
 13
 14        private readonly IPlayerPrefsSettingsByKey settingsByKey;
 15        private readonly DisplaySettings defaultSettings;
 16        private DisplaySettings currentSettings;
 17
 18        public event Action<DisplaySettings> OnChanged;
 19
 020        public PlayerPrefsDesktopDisplaySettingsRepository(
 21            IPlayerPrefsSettingsByKey settingsByKey,
 22            DisplaySettings defaultSettings)
 23        {
 024            this.settingsByKey = settingsByKey;
 025            this.defaultSettings = defaultSettings;
 026            currentSettings = Load();
 027        }
 28
 029        public DisplaySettings Data => currentSettings;
 30
 31        public void Apply(DisplaySettings settings)
 32        {
 033            if (currentSettings.Equals(settings)) return;
 034            currentSettings = settings;
 035            OnChanged?.Invoke(currentSettings);
 036        }
 37
 38        public void Reset()
 39        {
 040            Apply(defaultSettings);
 041        }
 42
 43        public void Save()
 44        {
 045            settingsByKey.SetBool(VSYNC, currentSettings.vSync);
 046            settingsByKey.SetInt(RESOLUTION_SIZE_INDEX, currentSettings.resolutionSizeIndex);
 047            settingsByKey.SetEnum(WINDOW_MODE, currentSettings.windowMode);
 048            settingsByKey.SetInt(FPS_CAP, currentSettings.fpsCapIndex);
 049        }
 50
 51        public bool HasAnyData() =>
 052            !Data.Equals(defaultSettings);
 53
 54        private DisplaySettings Load()
 55        {
 056            var settings = defaultSettings;
 57
 58            try
 59            {
 060                settings.vSync = settingsByKey.GetBool(VSYNC, defaultSettings.vSync);
 061                settings.resolutionSizeIndex = settingsByKey.GetInt(RESOLUTION_SIZE_INDEX, -1);
 062                settings.windowMode = settingsByKey.GetEnum(WINDOW_MODE, defaultSettings.windowMode);
 063                settings.fpsCapIndex = settingsByKey.GetInt(FPS_CAP, defaultSettings.fpsCapIndex);
 064            }
 065            catch (Exception e) { Debug.LogException(e); }
 66
 067            return settings;
 68        }
 69    }
 70}