< Summary

Class:MainScripts.DCL.Controllers.HUD.Preloading.PreloadingController
Assembly:Preloading
File(s):/tmp/workspace/explorer-desktop/unity-renderer-desktop/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Preloading/PreloadingController.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:66
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PreloadingController()0%2100%
OnDecoupledLoadingScreenVisibilityChange(...)0%6200%
GetView()0%2100%
Dispose()0%6200%
WaitForViewsToFadeOut()0%12300%
OnMessageChange(...)0%6200%
SignUpFlowChanged(...)0%6200%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections;
 3using Cysharp.Threading.Tasks;
 4using DCL;
 5using UnityEngine;
 6using Object = UnityEngine.Object;
 7
 8namespace MainScripts.DCL.Controllers.HUD.Preloading
 9{
 10    public class PreloadingController : IDisposable
 11    {
 12        private GameObject view;
 13        private readonly DataStoreRef<DataStore_LoadingScreen> loadingScreenRef;
 14
 015        private BaseVariable<bool> isSignUpFlow => DataStore.i.common.isSignUpFlow;
 16        private bool isDisposed = false;
 17
 018        public PreloadingController()
 19        {
 020            view = Object.Instantiate(GetView());
 021            loadingScreenRef.Ref.loadingHUD.message.OnChange += OnMessageChange;
 022            loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange += OnDecoupledLoadingScreenVisibilityChange;
 023            isSignUpFlow.OnChange += SignUpFlowChanged;
 024        }
 25
 26        private void OnDecoupledLoadingScreenVisibilityChange(bool current, bool _)
 27        {
 028            if(current)
 029                Dispose();
 030        }
 31
 32        private GameObject GetView()
 33        {
 034            return Resources.Load<GameObject>("Preloading");
 35        }
 36
 37        public void Dispose()
 38        {
 039            if (isDisposed) return;
 040            isDisposed = true;
 041            WaitForViewsToFadeOut();
 042        }
 43
 44        async UniTask WaitForViewsToFadeOut()
 45        {
 46            //This wait will be removed when we merge both loading screen into a single decoupled loading screen
 047            await UniTask.Delay(TimeSpan.FromSeconds(2), ignoreTimeScale: false);
 048            loadingScreenRef.Ref.loadingHUD.message.OnChange -= OnMessageChange;
 049            loadingScreenRef.Ref.decoupledLoadingHUD.visible.OnChange -= OnDecoupledLoadingScreenVisibilityChange;
 050            isSignUpFlow.OnChange -= SignUpFlowChanged;
 051            Object.Destroy(view.gameObject);
 052        }
 53
 54        private void OnMessageChange(string current, string previous)
 55        {
 056            if (current.Contains("%"))
 057                Dispose();
 058        }
 59
 60        private void SignUpFlowChanged(bool current, bool previous)
 61        {
 062            if (current)
 063                Dispose();
 064        }
 65    }
 66}