< Summary

Class:DCL.SettingsCommon.PlayerPrefsAudioSettingsRepository
Assembly:Settings
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/PlayerPrefsAudioSettingsRepository.cs
Covered lines:31
Uncovered lines:2
Coverable lines:33
Total lines:80
Line coverage:93.9% (31 of 33)
Covered branches:0
Total branches:0

Metrics

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

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3
 4namespace DCL.SettingsCommon
 5{
 6    public class PlayerPrefsAudioSettingsRepository : ISettingsRepository<AudioSettings>
 7    {
 8        private const string CHAT_SFX_ENABLED = "chatSFXEnabled";
 9        private const string MASTER_VOLUME = "masterVolume";
 10        private const string MUSIC_VOLUME = "musicVolume";
 11        private const string VOICE_CHAT_VOLUME = "voiceChatVolume";
 12        private const string AVATAR_SFX_VOLUME = "avatarSFXVolume";
 13        private const string SCENE_SFX_VOLUME = "sceneSFXVolume";
 14        private const string UI_SFX_VOLUME = "uiSFXVolume";
 15
 16        private readonly IPlayerPrefsSettingsByKey settingsByKey;
 17        private readonly AudioSettings defaultSettings;
 18        private AudioSettings currentSettings;
 19
 20        public event Action<AudioSettings> OnChanged;
 21
 64022        public PlayerPrefsAudioSettingsRepository(
 23            IPlayerPrefsSettingsByKey settingsByKey,
 24            AudioSettings defaultSettings)
 25        {
 64026            this.settingsByKey = settingsByKey;
 64027            this.defaultSettings = defaultSettings;
 64028            currentSettings = Load();
 64029        }
 30
 13631        public AudioSettings Data => currentSettings;
 32
 33        public void Apply(AudioSettings settings)
 34        {
 7435            if (currentSettings.Equals(settings)) return;
 236            currentSettings = settings;
 237            OnChanged?.Invoke(currentSettings);
 238        }
 39
 40        public void Reset()
 41        {
 2542            Apply(defaultSettings);
 2543        }
 44
 45        public void Save()
 46        {
 147            settingsByKey.SetBool(CHAT_SFX_ENABLED, currentSettings.chatSFXEnabled);
 148            settingsByKey.SetFloat(MASTER_VOLUME, currentSettings.masterVolume);
 149            settingsByKey.SetFloat(MUSIC_VOLUME, currentSettings.musicVolume);
 150            settingsByKey.SetFloat(VOICE_CHAT_VOLUME, currentSettings.voiceChatVolume);
 151            settingsByKey.SetFloat(AVATAR_SFX_VOLUME, currentSettings.avatarSFXVolume);
 152            settingsByKey.SetFloat(SCENE_SFX_VOLUME, currentSettings.sceneSFXVolume);
 153            settingsByKey.SetFloat(UI_SFX_VOLUME, currentSettings.uiSFXVolume);
 154        }
 55
 13656        public bool HasAnyData() => !Data.Equals(defaultSettings);
 57
 58        private AudioSettings Load()
 59        {
 64060            var settings = defaultSettings;
 61
 62            try
 63            {
 64064                settings.chatSFXEnabled = settingsByKey.GetBool(CHAT_SFX_ENABLED, defaultSettings.chatSFXEnabled);
 64065                settings.masterVolume = settingsByKey.GetFloat(MASTER_VOLUME, defaultSettings.masterVolume);
 64066                settings.musicVolume = settingsByKey.GetFloat(MUSIC_VOLUME, defaultSettings.musicVolume);
 64067                settings.voiceChatVolume = settingsByKey.GetFloat(VOICE_CHAT_VOLUME, defaultSettings.voiceChatVolume);
 64068                settings.avatarSFXVolume = settingsByKey.GetFloat(AVATAR_SFX_VOLUME, defaultSettings.avatarSFXVolume);
 64069                settings.sceneSFXVolume = settingsByKey.GetFloat(SCENE_SFX_VOLUME, defaultSettings.sceneSFXVolume);
 64070                settings.uiSFXVolume = settingsByKey.GetFloat(UI_SFX_VOLUME, defaultSettings.uiSFXVolume);
 64071            }
 72            catch (Exception e)
 73            {
 074                Debug.LogException(e);
 075            }
 76
 64077            return settings;
 78        }
 79    }
 80}