< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadingScreenHintsController(...)0%2100%
InitializeHintsAsync()0%42600%
RequestHints()0%56700%
StartHintsCarousel()0%2100%
StopHintsCarousel()0%2100%
CarouselNextHint()0%2100%
CarouselPreviousHint()0%2100%
SetHint(...)0%2100%
Dispose()0%6200%

File(s)

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

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Providers;
 3using System;
 4using System.Collections.Generic;
 5using System.Threading;
 6using UnityEngine;
 7using Object = UnityEngine.Object;
 8
 9namespace DCL.Controllers.LoadingScreenV2
 10{
 11    /// <summary>
 12    /// Controller responsible of managing the hints views and requesting hints from the HintRequestService
 13    /// And also responsible of showing the hints in the LoadingScreen using the HintViewManager carousel
 14    /// </summary>
 15    public class LoadingScreenHintsController
 16    {
 017        private readonly TimeSpan SHOWING_TIME_HINTS = TimeSpan.FromSeconds(5);
 018        private readonly string SOURCE_HINT_ADDRESSABLE = "LoadingScreenV2HintView.prefab";
 19        private const int MAX_HINTS = 15;
 20
 21        private readonly HintRequestService hintRequestService;
 22
 23        internal HintView hintViewPrefab;
 24        internal HintViewManager hintViewManager;
 25        internal readonly List<HintView> hintViewPool;
 26        internal Dictionary<int, Tuple<Hint, Texture2D>> hintsDictionary;
 27        internal CancellationTokenSource cancellationTokenSource;
 28
 29        public event Action OnRequestHintsCompleted;
 30
 031        public LoadingScreenHintsController(HintRequestService hintRequestService)
 32        {
 033            this.hintRequestService = hintRequestService;
 34
 035            hintsDictionary = new Dictionary<int, Tuple<Hint, Texture2D>>();
 036            hintViewPool = new List<HintView>();
 37
 038            InitializeHintsAsync();
 039        }
 40
 41        private async void InitializeHintsAsync()
 42        {
 043            cancellationTokenSource = new CancellationTokenSource();
 44
 045            IAddressableResourceProvider  addressableProvider = new AddressableResourceProvider();
 046            hintViewPrefab = await addressableProvider.GetAddressable<HintView>(SOURCE_HINT_ADDRESSABLE, cancellationTok
 47
 48            // Initializing empty hints views
 049            for (int i = 0; i < MAX_HINTS; i++)
 50            {
 051                HintView newHintView = Object.Instantiate(hintViewPrefab);
 052                newHintView.ToggleHint(false);
 053                hintViewPool.Add(newHintView);
 54            }
 55
 056            await RequestHints(cancellationTokenSource.Token);
 057        }
 58
 59        /// <summary>
 60        /// Requests hints from the HintRequestService and initializes the hints views with the results
 61        /// </summary>
 62        /// <param name="ctx"></param>
 63        public async UniTask RequestHints(CancellationToken ctx)
 64        {
 065            hintsDictionary.Clear();
 66
 067            Dictionary<Hint, Texture2D> hintsResult = await hintRequestService.RequestHintsFromSources(ctx, MAX_HINTS);
 68
 069            int index = 0;
 070            var intializedHints = new List<HintView>();
 071            foreach (var hintResult in hintsResult)
 72            {
 073                var hintTuple = new Tuple<Hint, Texture2D>(hintResult.Key, hintResult.Value);
 074                hintsDictionary.Add(index, hintTuple);
 75
 076                if (index < hintViewPool.Count)
 77                {
 078                    hintViewPool[index].Initialize(hintResult.Key, hintResult.Value, index == 0);
 079                    intializedHints.Add(hintViewPool[index]);
 80                }
 081                index++;
 82            }
 83
 084            hintViewManager = new HintViewManager(intializedHints);
 85
 086            StartHintsCarousel();
 087            OnRequestHintsCompleted?.Invoke();
 088        }
 89
 90        public void StartHintsCarousel()
 91        {
 092            hintViewManager.StartCarousel();
 093        }
 94
 95        public void StopHintsCarousel()
 96        {
 097            hintViewManager.StopCarousel();
 098        }
 99
 100        public void CarouselNextHint()
 101        {
 0102            hintViewManager.CarouselNextHint();
 0103        }
 104
 105        public void CarouselPreviousHint()
 106        {
 0107            hintViewManager.CarouselPreviousHint();
 0108        }
 109
 110        public void SetHint(int index)
 111        {
 0112            hintViewManager.SetSpecificHint(index);
 0113        }
 114
 115        public void Dispose()
 116        {
 0117            cancellationTokenSource?.Cancel();
 0118            hintViewManager.Dispose();
 0119        }
 120    }
 121}