< Summary

Class:DCL.WorldRuntime.ResourcesLoadTrackerLegacyECS
Assembly:SceneResourcesLoadTracker
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneResourcesLoadTracker/ResourcesLoadTrackerLegacyECS.cs
Covered lines:26
Uncovered lines:18
Coverable lines:44
Total lines:120
Line coverage:59% (26 of 44)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ResourcesLoadTrackerLegacyECS(...)0%110100%
Dispose()0%110100%
CheckPendingResources()0%3.023087.5%
PrintWaitingResourcesDebugInfo()0%30500%
GetStateString()0%6200%
OnSharedComponentAdded(...)0%110100%
OnDisposableReady(...)0%6.076087.5%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneResourcesLoadTracker/ResourcesLoadTrackerLegacyECS.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.Components;
 5using UnityEngine;
 6
 7namespace DCL.WorldRuntime
 8{
 9    internal class ResourcesLoadTrackerLegacyECS : IResourcesLoadTracker
 10    {
 1011        public int pendingResourcesCount => disposableNotReady?.Count ?? 0;
 12        public float loadingProgress
 13        {
 14            get
 15            {
 35116                int sharedComponentsCount = componentsManager.GetSceneSharedComponentsCount();
 35117                return sharedComponentsCount > 0 ? (sharedComponentsCount - pendingResourcesCount) * 100f / sharedCompon
 18            }
 19        }
 20
 21        public event Action OnResourcesLoaded;
 22        public event Action OnStatusUpdate;
 23
 24        private readonly IECSComponentsManagerLegacy componentsManager;
 25        private readonly IWorldState worldState;
 26
 39327        private List<string> disposableNotReady = new List<string>();
 28
 39329        public ResourcesLoadTrackerLegacyECS(IECSComponentsManagerLegacy componentsManager, IWorldState worldState)
 30        {
 39331            this.componentsManager = componentsManager;
 39332            this.worldState = worldState;
 33
 39334            componentsManager.OnAddSharedComponent += OnSharedComponentAdded;
 39335        }
 36
 37        public void Dispose()
 38        {
 35239            componentsManager.OnAddSharedComponent -= OnSharedComponentAdded;
 35240            disposableNotReady = null;
 35241        }
 42
 43        public bool CheckPendingResources()
 44        {
 345            List<ISharedComponent> disposableComponents = componentsManager.GetSceneSharedComponentsDictionary().Values.
 2046            for (int i = 0; i < disposableComponents.Count; i++)
 47            {
 748                if (!disposableNotReady.Contains(disposableComponents[i].id))
 49                {
 050                    disposableNotReady.Add(disposableComponents[i].id);
 51                }
 752                disposableComponents[i].CallWhenReady(OnDisposableReady);
 53            }
 354            return disposableNotReady.Count > 0;
 55        }
 56
 57        public void PrintWaitingResourcesDebugInfo()
 58        {
 059            foreach (string componentId in disposableNotReady)
 60            {
 061                if (componentsManager.HasSceneSharedComponent(componentId))
 62                {
 063                    var component = componentsManager.GetSceneSharedComponent(componentId);
 64
 065                    Debug.Log($"Waiting for: {component.ToString()}");
 66
 067                    foreach (var entity in component.GetAttachedEntities())
 68                    {
 069                        var loader = worldState.GetLoaderForEntity(entity);
 70
 071                        string loadInfo = "No loader";
 72
 073                        if (loader != null)
 74                        {
 075                            loadInfo = loader.ToString();
 76                        }
 77
 078                        Debug.Log($"This shape is attached to {entity.entityId} entity. Click here for highlight it.\nLo
 79                    }
 80                }
 81                else
 82                {
 083                    Debug.Log($"Waiting for missing component? id: {componentId}");
 84                }
 85            }
 086        }
 87
 88        public string GetStateString()
 89        {
 090            int sharedComponentsCount = componentsManager.GetSceneSharedComponentsCount();
 091            if (sharedComponentsCount > 0)
 092                return $"left to ready:{sharedComponentsCount - pendingResourcesCount}/{sharedComponentsCount} ({loading
 93
 094            return $"no components. waiting...";
 95        }
 96
 97        private void OnSharedComponentAdded(string id, ISharedComponent component)
 98        {
 499            disposableNotReady.Add(id);
 4100        }
 101
 102        private void OnDisposableReady(ISharedComponent component)
 103        {
 7104            if (disposableNotReady == null)
 0105                return;
 106
 7107            if (!disposableNotReady.Remove(component.id))
 3108                return;
 109
 4110            if (disposableNotReady.Count == 0)
 111            {
 2112                OnResourcesLoaded?.Invoke();
 113            }
 114            else
 115            {
 2116                OnStatusUpdate?.Invoke();
 117            }
 2118        }
 119    }
 120}