< Summary

Class:DCL.WorldState
Assembly:DCL.Runtime
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/WorldState.cs
Covered lines:36
Uncovered lines:10
Coverable lines:46
Total lines:122
Line coverage:78.2% (36 of 46)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WorldState()0%110100%
GetScene(...)0%2.152066.67%
Contains(...)0%330100%
TryGetScene(...)0%330100%
TryGetScene[T](...)0%12300%
GetAllLoadedScenesCoords()0%330100%
GetLoaderForEntity(...)0%2.262060%
GetOrAddLoaderForEntity[T](...)0%220100%
RemoveLoaderForEntity(...)0%330100%
Dispose()0%110100%
Initialize()0%110100%

File(s)

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

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using System.Collections.Generic;
 4using DCL.Components;
 5using DCL.Models;
 6using UnityEngine;
 7
 8namespace DCL
 9{
 10    public class WorldState : IWorldState
 11    {
 118512        public HashSet<string> readyScenes { get; set; } = new HashSet<string>();
 566513        public Dictionary<string, IParcelScene> loadedScenes { get; set; } = new Dictionary<string, IParcelScene>();
 125014        public Dictionary<Vector2Int, string> loadedScenesByCoordinate { get; set; } = new Dictionary<Vector2Int, string
 450415        public List<IParcelScene> scenesSortedByDistance { get; set; } = new List<IParcelScene>();
 124616        public List<string> globalSceneIds { get; set; } = new List<string>();
 426617        public string currentSceneId { get; set; } = null;
 18
 19        public IParcelScene GetScene(string id)
 20        {
 1621            if (!Contains(id))
 022                return null;
 23
 1624            return loadedScenes[id];
 25        }
 26
 27        public bool Contains(string id)
 28        {
 45729            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 130                return false;
 31
 45632            return true;
 33        }
 34
 35        public bool TryGetScene(string id, out IParcelScene scene)
 36        {
 2837            scene = null;
 38
 2839            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 1040                return false;
 41
 1842            scene = loadedScenes[id];
 1843            return true;
 44        }
 45
 46        public bool TryGetScene<T>(string id, out T scene)
 47            where T : class, IParcelScene
 48        {
 049            scene = default(T);
 050            bool result = TryGetScene(id, out IParcelScene baseScene);
 51
 052            if (result)
 053                scene = baseScene as T;
 54
 055            if (scene == null)
 056                result = false;
 57
 058            return result;
 59        }
 60
 61        public HashSet<Vector2Int> GetAllLoadedScenesCoords()
 62        {
 80163            HashSet<Vector2Int> allLoadedParcelCoords = new HashSet<Vector2Int>();
 64
 65            // Create fast (hashset) collection of loaded parcels coords
 186466            foreach (var element in loadedScenes)
 67            {
 13168                ParcelScene scene = element.Value as ParcelScene;
 69
 13170                if (!scene.sceneLifecycleHandler.isReady)
 71                    continue;
 72
 573                allLoadedParcelCoords.UnionWith(scene.parcels);
 74            }
 75
 80176            return allLoadedParcelCoords;
 77        }
 78
 77479        private readonly Dictionary<GameObject, LoadWrapper>
 80            attachedLoaders = new Dictionary<GameObject, LoadWrapper>();
 81
 82        public LoadWrapper GetLoaderForEntity(IDCLEntity entity)
 83        {
 57784            if (entity.meshRootGameObject == null)
 85            {
 086                Debug.LogWarning("NULL meshRootGameObject at GetLoaderForEntity()");
 087                return null;
 88            }
 89
 57790            attachedLoaders.TryGetValue(entity.meshRootGameObject, out LoadWrapper result);
 57791            return result;
 92        }
 93
 94        public T GetOrAddLoaderForEntity<T>(IDCLEntity entity)
 95            where T : LoadWrapper, new()
 96        {
 10497            if (!attachedLoaders.TryGetValue(entity.meshRootGameObject, out LoadWrapper result))
 98            {
 10299                result = new T();
 102100                attachedLoaders.Add(entity.meshRootGameObject, result);
 101            }
 102
 104103            return result as T;
 104        }
 105
 106        public void RemoveLoaderForEntity(IDCLEntity entity)
 107        {
 81108            if (entity == null || entity.meshRootGameObject == null)
 7109                return;
 110
 74111            attachedLoaders.Remove(entity.meshRootGameObject);
 74112        }
 113
 114        public void Dispose()
 115        {
 767116        }
 117
 118        public void Initialize()
 119        {
 767120        }
 121    }
 122}