< Summary

Class:DCL.SettingsCommon.Settings
Assembly:Settings
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/Settings/Settings.cs
Covered lines:44
Uncovered lines:5
Coverable lines:49
Total lines:112
Line coverage:89.7% (44 of 49)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
CreateSharedInstance(...)0%3.143075%
Settings(...)0%110100%
Dispose()0%110100%
LoadDefaultSettings()0%110100%
ResetAllSettings()0%6200%
SubscribeToVirtualAudioMixerEvents()0%110100%
UnsubscribeFromVirtualAudioMixerEvents()0%110100%
ApplyMasterVolume()0%110100%
ApplyVoiceChatSettings(...)0%110100%
ApplyAvatarSFXVolume(...)0%110100%
ApplyUISFXVolume(...)0%110100%
ApplyMusicVolume(...)0%110100%
SaveSettings()0%110100%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL.Helpers;
 3using DCL.Interface;
 4using UnityEngine.Audio;
 5
 6namespace DCL.SettingsCommon
 7{
 8    public class Settings
 9    {
 191910        public static Settings i { get; private set; }
 11
 12        public event Action OnResetAllSettings;
 13
 014        public QualitySettingsData qualitySettingsPresets => qualitySettingsPreset;
 15
 16        public readonly ISettingsRepository<QualitySettings> qualitySettings;
 17        public readonly ISettingsRepository<GeneralSettings> generalSettings;
 18        public readonly ISettingsRepository<AudioSettings> audioSettings;
 19
 20        private readonly QualitySettingsData qualitySettingsPreset;
 21        private readonly AudioMixer audioMixer;
 22
 23        private bool isDisposed;
 24
 25        public static void CreateSharedInstance(ISettingsFactory settingsFactory)
 26        {
 64027            if (i != null && !i.isDisposed) return;
 64028            i = settingsFactory.Build();
 64029        }
 30
 64031        public Settings(QualitySettingsData qualitySettingsPreset,
 32            AudioMixer audioMixer,
 33            ISettingsRepository<QualitySettings> graphicsQualitySettingsRepository,
 34            ISettingsRepository<GeneralSettings> generalSettingsRepository,
 35            ISettingsRepository<AudioSettings> audioSettingsRepository)
 36        {
 64037            this.qualitySettingsPreset = qualitySettingsPreset;
 64038            this.audioMixer = audioMixer;
 64039            qualitySettings = graphicsQualitySettingsRepository;
 64040            generalSettings = generalSettingsRepository;
 64041            audioSettings = audioSettingsRepository;
 42
 64043            SubscribeToVirtualAudioMixerEvents();
 64044        }
 45
 46        public void Dispose()
 47        {
 64048            UnsubscribeFromVirtualAudioMixerEvents();
 64049            isDisposed = true;
 64050        }
 51
 52        public void LoadDefaultSettings()
 53        {
 2554            qualitySettings.Reset();
 2555            generalSettings.Reset();
 2556            audioSettings.Reset();
 2557        }
 58
 59        public void ResetAllSettings()
 60        {
 061            LoadDefaultSettings();
 062            SaveSettings();
 063            OnResetAllSettings?.Invoke();
 064        }
 65
 66        private void SubscribeToVirtualAudioMixerEvents()
 67        {
 64068            DataStore.i.virtualAudioMixer.voiceChatVolume.OnChange += ApplyVoiceChatSettings;
 64069            DataStore.i.virtualAudioMixer.musicVolume.OnChange += ApplyMusicVolume;
 64070            DataStore.i.virtualAudioMixer.avatarSFXVolume.OnChange += ApplyAvatarSFXVolume;
 64071            DataStore.i.virtualAudioMixer.uiSFXVolume.OnChange += ApplyUISFXVolume;
 64072        }
 73
 74        private void UnsubscribeFromVirtualAudioMixerEvents()
 75        {
 64076            DataStore.i.virtualAudioMixer.voiceChatVolume.OnChange -= ApplyVoiceChatSettings;
 64077            DataStore.i.virtualAudioMixer.musicVolume.OnChange -= ApplyMusicVolume;
 64078            DataStore.i.virtualAudioMixer.avatarSFXVolume.OnChange -= ApplyAvatarSFXVolume;
 64079            DataStore.i.virtualAudioMixer.uiSFXVolume.OnChange -= ApplyUISFXVolume;
 64080        }
 81
 82        public void ApplyMasterVolume()
 83        {
 84            // Update the "All" mixer group
 285            audioMixer.SetFloat("AllBusVolume", Utils.ToAudioMixerGroupVolume(audioSettings.Data.masterVolume));
 86
 87            // Update voice chat volume, as it does not pass through the AudioMixer
 288            ApplyVoiceChatSettings();
 289        }
 90
 91        public void ApplyVoiceChatSettings(float currentDataStoreVolume = 0f, float previousDataStoreVolume = 0f)
 92        {
 693            AudioSettings audioSettingsData = audioSettings.Data;
 694            float calculatedVolume = Utils.ToVolumeCurve(DataStore.i.virtualAudioMixer.voiceChatVolume.Get() * audioSett
 695            WebInterface.ApplySettings(calculatedVolume, (int)generalSettings.Data.voiceChatAllow);
 696        }
 97
 498        public void ApplyAvatarSFXVolume(float currentDataStoreVolume = 0f, float previousDataStoreVolume = 0f) { audioM
 99
 4100        public void ApplyUISFXVolume(float currentDataStoreVolume = 0f, float previousDataStoreVolume = 0f) { audioMixer
 101
 4102        public void ApplyMusicVolume(float currentDataStoreVolume = 0f, float previousDataStoreVolume = 0f) { audioMixer
 103
 104        public void SaveSettings()
 105        {
 1106            generalSettings.Save();
 1107            qualitySettings.Save();
 1108            audioSettings.Save();
 1109            PlayerPrefsUtils.Save();
 1110        }
 111    }
 112}