< Summary

Class:DCL.Controllers.LoadingScreenV2.HintViewManager
Assembly:DCL.LoadingScreenV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreenV2/LoadingScreenScripts/HintViewManager.cs
Covered lines:0
Uncovered lines:50
Coverable lines:50
Total lines:118
Line coverage:0% (0 of 50)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:10
Method coverage:0% (0 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
HintViewManager(...)0%2100%
StartCarousel()0%12300%
StopCarousel()0%6200%
CarouselNextHint()0%6200%
CarouselPreviousHint()0%6200%
SetSpecificHint(...)0%6200%
SetHint(...)0%2100%
ScheduleNextUpdate()0%30500%
UpdateHintView()0%12300%
Dispose()0%20400%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreenV2/LoadingScreenScripts/HintViewManager.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System;
 3using System.Collections.Generic;
 4using System.Threading;
 5using UnityEngine;
 6
 7namespace DCL.Controllers.LoadingScreenV2
 8{
 9    public class HintViewManager : IHintViewManager
 10    {
 011        private readonly TimeSpan SHOWING_TIME_HINTS = TimeSpan.FromSeconds(5);
 12        private readonly List<HintView> hintViewList;
 13
 14        private CancellationTokenSource cancellationTokenSource;
 15
 16        internal bool isIteratingHints = false;
 17        internal int currentHintIndex = 0;
 18
 19        public event Action OnHintChanged;
 20
 021        public HintViewManager(List<HintView> hintViewList)
 22        {
 023            this.hintViewList = hintViewList;
 024        }
 25
 26        public void StartCarousel()
 27        {
 028            if (isIteratingHints || hintViewList.Count == 0)
 029                return;
 30
 031            isIteratingHints = true;
 032            ScheduleNextUpdate(CancellationToken.None).Forget();
 033        }
 34
 35        public void StopCarousel()
 36        {
 037            isIteratingHints = false;
 038            cancellationTokenSource?.Cancel();
 039        }
 40
 41        public void CarouselNextHint()
 42        {
 043            if (hintViewList.Count == 0)
 044                return;
 45
 046            SetHint((currentHintIndex + 1) % hintViewList.Count);
 047        }
 48
 49        public void CarouselPreviousHint()
 50        {
 051            if (hintViewList.Count == 0)
 052                return;
 53
 054            SetHint((currentHintIndex - 1 + hintViewList.Count) % hintViewList.Count);
 055        }
 56
 57        public void SetSpecificHint(int index)
 58        {
 059            if (hintViewList.Count == 0)
 060                return;
 61
 062            SetHint(index);
 063        }
 64
 65        private void SetHint(int index)
 66        {
 067            hintViewList[currentHintIndex].ToggleHint(false);
 068            currentHintIndex = index;
 069            UpdateHintView();
 070        }
 71
 72        private async UniTask ScheduleNextUpdate(CancellationToken token)
 73        {
 074            cancellationTokenSource?.Cancel(); // cancel previous timer
 075            cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
 76
 77            try
 78            {
 079                await UniTask.Delay(SHOWING_TIME_HINTS, cancellationToken: cancellationTokenSource.Token);
 080                CarouselNextHint();
 081            }
 082            catch (OperationCanceledException)
 83            {
 84                // Operation was cancelled
 085            }
 86            catch (Exception ex)
 87            {
 088                Debug.LogException(ex);
 089            }
 090        }
 91
 92        private void UpdateHintView()
 93        {
 094            hintViewList[currentHintIndex].ToggleHint(true);
 95
 096            if (isIteratingHints)
 97            {
 098                ScheduleNextUpdate(cancellationTokenSource.Token).Forget();
 99            }
 100
 0101            OnHintChanged?.Invoke();
 0102        }
 103
 104        public void Dispose()
 105        {
 0106            StopCarousel();
 0107            cancellationTokenSource?.Cancel();
 0108            cancellationTokenSource?.Dispose();
 109
 0110            foreach (var hintView in hintViewList)
 111            {
 0112                DCL.Helpers.Utils.SafeDestroy(hintView.gameObject);
 113            }
 114
 0115            hintViewList.Clear();
 0116        }
 117    }
 118}