< Summary

Class:DCL.LoadingScreen.LoadingScreenPercentageController
Assembly:DCL.LoadingScreen
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreen/Scripts/LoadingScreenPercentageController.cs
Covered lines:0
Uncovered lines:33
Coverable lines:33
Total lines:83
Line coverage:0% (0 of 33)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LoadingScreenPercentageController(...)0%2100%
Dispose()0%6200%
SceneController_OnNewSceneAdded(...)0%12300%
StartedSignUpFlow(...)0%6200%
StatusUpdate(...)0%12300%
StartLoading(...)0%2100%
SetAvatarLoadingMessage()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreen/Scripts/LoadingScreenPercentageController.cs

#LineLine coverage
 1using DCL.Controllers;
 2using System;
 3using UnityEngine;
 4
 5namespace DCL.LoadingScreen
 6{
 7    /// <summary>
 8    /// Loading screen percentage updater. The responsibility of this class is to update the loading bar only
 9    /// listening to the destination scene
 10    /// </summary>
 11    public class LoadingScreenPercentageController : IDisposable
 12    {
 13        private readonly LoadingScreenPercentageView loadingScreenPercentageView;
 14        private readonly ISceneController sceneController;
 15        private readonly DataStore_Common commonDataStore;
 16
 17        private Vector2Int currentDestination;
 18        private IParcelScene currentSceneBeingLoaded;
 19
 020        public LoadingScreenPercentageController(ISceneController sceneController, LoadingScreenPercentageView loadingSc
 21        {
 022            this.loadingScreenPercentageView = loadingScreenPercentageView;
 023            this.sceneController = sceneController;
 024            this.commonDataStore = commonDataStore;
 25
 026            loadingScreenPercentageView.SetSceneLoadingMessage();
 027            loadingScreenPercentageView.SetLoadingPercentage(0);
 28
 029            sceneController.OnNewSceneAdded += SceneController_OnNewSceneAdded;
 030            commonDataStore.isSignUpFlow.OnChange += StartedSignUpFlow;
 031        }
 32
 33        public void Dispose()
 34        {
 035            sceneController.OnNewSceneAdded -= SceneController_OnNewSceneAdded;
 036            commonDataStore.isSignUpFlow.OnChange -= StartedSignUpFlow;
 37
 038            if (currentSceneBeingLoaded != null)
 039                currentSceneBeingLoaded.OnLoadingStateUpdated -= StatusUpdate;
 040        }
 41
 42        private void SceneController_OnNewSceneAdded(IParcelScene scene)
 43        {
 44            //We will only update the percentage of the current destination scene. It may be the only one we care about
 045            if (scene != null &&
 46                Environment.i.world.state.GetSceneNumberByCoords(currentDestination).Equals(scene.sceneData.sceneNumber)
 47            {
 048                currentSceneBeingLoaded = scene;
 049                currentSceneBeingLoaded.OnLoadingStateUpdated += StatusUpdate;
 50            }
 051        }
 52
 53        private void StartedSignUpFlow(bool current, bool previous)
 54        {
 055            if (current)
 056                StatusUpdate(100);
 57            else
 058                StatusUpdate(0);
 059        }
 60
 61        private void StatusUpdate(float percentage)
 62        {
 063            loadingScreenPercentageView.SetLoadingPercentage((int)percentage);
 64
 065            if (currentSceneBeingLoaded != null && percentage >= 100)
 66            {
 067                currentSceneBeingLoaded.OnLoadingStateUpdated -= StatusUpdate;
 068                currentSceneBeingLoaded = null;
 69            }
 070        }
 71
 72        public void StartLoading(Vector2Int newDestination)
 73        {
 074            loadingScreenPercentageView.gameObject.SetActive(true);
 075            currentDestination = newDestination;
 076            loadingScreenPercentageView.SetSceneLoadingMessage();
 077            loadingScreenPercentageView.SetLoadingPercentage(0);
 078        }
 79
 80        public void SetAvatarLoadingMessage() =>
 081            loadingScreenPercentageView.SetPlayerLoadingMessage();
 82    }
 83}