< Summary

Class:DCLServices.EmotesService.EmoteVolumeHandler
Assembly:EmotesService
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/EmotesService/EmoteVolumeHandler.cs
Covered lines:10
Uncovered lines:8
Coverable lines:18
Total lines:50
Line coverage:55.5% (10 of 18)
Covered branches:0
Total branches:0
Covered methods:3
Total methods:6
Method coverage:50% (3 of 6)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmoteVolumeHandler()0%110100%
AddAudioSource(...)0%2100%
RemoveAudioSource(...)0%2100%
SetVolume(...)0%2100%
OnVolumeChanged(...)0%2.152066.67%
GetVolume(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLServices/EmotesService/EmoteVolumeHandler.cs

#LineLine coverage
 1using DCL.Helpers;
 2using DCL.SettingsCommon;
 3using System.Collections.Generic;
 4using UnityEngine;
 5using AudioSettings = DCL.SettingsCommon.AudioSettings;
 6
 7namespace DCLServices.EmotesService
 8{
 9    public class EmoteVolumeHandler
 10    {
 11        private const float BASE_VOLUME = 0.2f;
 12
 42513        private readonly List<AudioSource> audioSources = new ();
 14        private readonly ISettingsRepository<AudioSettings> audioSettings;
 15
 42516        public EmoteVolumeHandler()
 17        {
 42518            audioSettings = Settings.i.audioSettings;
 42519            audioSettings.OnChanged += OnVolumeChanged;
 42520            OnVolumeChanged(audioSettings.Data);
 42521        }
 22
 23        public void AddAudioSource(AudioSource audioSource)
 24        {
 025            audioSources.Add(audioSource);
 026            SetVolume(audioSource, GetVolume(audioSettings.Data));
 027        }
 28
 29        public void RemoveAudioSource(AudioSource audioSource)
 30        {
 031            audioSources.Remove(audioSource);
 032        }
 33
 34        private void SetVolume(AudioSource audioSource, float volume)
 35        {
 036            audioSource.volume = volume;
 037        }
 38
 39        private void OnVolumeChanged(AudioSettings settings)
 40        {
 42741            float targetVolume = GetVolume(settings);
 42
 85443            foreach (AudioSource audioSource in audioSources)
 044                SetVolume(audioSource, targetVolume);
 42745        }
 46
 47        private static float GetVolume(AudioSettings audioSettings) =>
 42748            BASE_VOLUME * Utils.ToVolumeCurve(audioSettings.avatarSFXVolume * audioSettings.masterVolume);
 49    }
 50}