< Summary

Class:MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts.ResolutionSizeControlController
Assembly:SettingsPanelHUDDesktop
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUDDesktop/Scripts/ResolutionSizeControlController.cs
Covered lines:0
Uncovered lines:28
Coverable lines:28
Total lines:76
Line coverage:0% (0 of 28)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ResolutionSizeControlController()0%2100%
Initialize()0%2100%
SetupAvailableResolutions()0%6200%
SetupLabels()0%6200%
GetLabel(...)0%2100%
GetStoredValue()0%6200%
GetAspectRatio(...)0%6200%
UpdateSetting(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/HUD/SettingsPanelHUDDesktop/Scripts/ResolutionSizeControlController.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using MainScripts.DCL.Controllers.SettingsDesktop.SettingsControllers;
 4using UnityEngine;
 5
 6namespace MainScripts.DCL.Controllers.HUD.SettingsPanelHUDDesktop.Scripts
 7{
 8    [CreateAssetMenu(menuName = "Settings/Controllers/Controls/Resolution Size",
 9        fileName = "ResolutionSizeControlController")]
 10    public class ResolutionSizeControlController : SpinBoxSettingsControlControllerDesktop
 11    {
 012        private readonly List<Resolution> possibleResolutions = new ();
 13
 14        public override void Initialize()
 15        {
 016            SetupAvailableResolutions();
 017            base.Initialize();
 018            SetupLabels();
 019        }
 20
 21        // Filter the smallest resolutions as no one will ever use them
 22        private void SetupAvailableResolutions()
 23        {
 024            possibleResolutions.AddRange(ScreenResolutionUtils.Resolutions.SkipWhile(r => r.width <= 1024));
 025        }
 26
 27        private void SetupLabels()
 28        {
 029            var length = possibleResolutions.Count;
 030            var resolutionLabels = new string[length];
 31
 032            for (var i = 0; i < length; i++)
 33            {
 034                var resolution = possibleResolutions[i];
 35
 36                // by design we want the list to be inverted so the biggest resolutions stay on top
 37                // our resolutionSizeIndex is based on this decision
 038                resolutionLabels[length - 1 - i] = GetLabel(resolution);
 39            }
 40
 041            RaiseOnOverrideIndicatorLabel(resolutionLabels);
 042        }
 43
 44        private static string GetLabel(Resolution resolution) =>
 045            $"{resolution.width}x{resolution.height} ({GetAspectRatio(resolution.width, resolution.height)}) {resolution
 46
 47        public override object GetStoredValue()
 48        {
 049            int index = currentDisplaySettings.resolutionSizeIndex;
 050            return index >= 0 ? index : ScreenResolutionUtils.DefaultIndex;
 51        }
 52
 53        private static string GetAspectRatio(int width, int height)
 54        {
 55            int rest;
 056            int tempWidth = width;
 057            int tempHeight = height;
 58
 059            while (height != 0)
 60            {
 061                rest = width % height;
 062                width = height;
 063                height = rest;
 64            }
 65
 066            return $"{tempWidth / width}:{tempHeight / width}";
 67        }
 68
 69        public override void UpdateSetting(object newValue)
 70        {
 071            var value = (int)newValue;
 072            currentDisplaySettings.resolutionSizeIndex = value;
 073            ScreenResolutionUtils.Apply(currentDisplaySettings);
 074        }
 75    }
 76}