< Summary

Class:MainScripts.DCL.Controllers.HUD.Preloading.PreloadingController
Assembly:Preloading
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/HUD/Preloading/PreloadingController.cs
Covered lines:0
Uncovered lines:26
Coverable lines:26
Total lines:70
Line coverage:0% (0 of 26)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:7
Method coverage:0% (0 of 7)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PreloadingController(...)0%2100%
>c__DisplayClass6_0/<<-ctor()0%12300%
Dispose()0%6200%
OnDecoupledLoadingScreenVisibilityChange(...)0%6200%
WaitForViewsToFadeOut()0%20400%
SignUpFlowChanged(...)0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Desktop/Scripts/MainScripts/DCL/Controllers/HUD/Preloading/PreloadingController.cs

#LineLine coverage
 1using System;
 2using System.Collections;
 3using Cysharp.Threading.Tasks;
 4using DCL;
 5using DCL.Providers;
 6using System.Threading;
 7using UnityEngine;
 8using Object = UnityEngine.Object;
 9
 10namespace MainScripts.DCL.Controllers.HUD.Preloading
 11{
 12    public class PreloadingController : IDisposable
 13    {
 14        private readonly DataStoreRef<DataStore_LoadingScreen> loadingScreenRef;
 15        private readonly CancellationTokenSource cancellationTokenSource;
 16
 17        private GameObject view;
 18        private bool isDisposed;
 19
 020        private BaseVariable<bool> isSignUpFlow => DataStore.i.common.isSignUpFlow;
 21
 022        public PreloadingController(IAddressableResourceProvider addressableResourceProvider)
 23        {
 024            cancellationTokenSource = new CancellationTokenSource();
 025            GetView(cancellationTokenSource.Token).Forget();
 26
 027            loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange += OnDecoupledLoadingScreenVisibilityChange;
 028            isSignUpFlow.OnChange += SignUpFlowChanged;
 29
 30            async UniTask GetView(CancellationToken cancellationToken) =>
 031                view = (await addressableResourceProvider.Instantiate<Transform>("Preloading", cancellationToken: cancel
 32                   .gameObject;
 033        }
 34
 35        public void Dispose()
 36        {
 037            if (isDisposed) return;
 038            isDisposed = true;
 39
 040            cancellationTokenSource.Cancel();
 041            cancellationTokenSource.Dispose();
 42
 043            WaitForViewsToFadeOut().Forget();
 044        }
 45
 46        private void OnDecoupledLoadingScreenVisibilityChange(bool current, bool _)
 47        {
 048            if (current)
 049                Dispose();
 050        }
 51
 52        private async UniTask WaitForViewsToFadeOut()
 53        {
 54            //This wait will be removed when we merge both loading screen into a single decoupled loading screen
 055            await UniTask.Delay(TimeSpan.FromSeconds(2), ignoreTimeScale: false);
 56
 057            loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange -= OnDecoupledLoadingScreenVisibilityChange;
 058            isSignUpFlow.OnChange -= SignUpFlowChanged;
 59
 060            if(view != null)
 061                Object.Destroy(view.gameObject);
 062        }
 63
 64        private void SignUpFlowChanged(bool current, bool previous)
 65        {
 066            if (current)
 067                Dispose();
 068        }
 69    }
 70}