< Summary

Class:DCL.WorldState
Assembly:DCL.Runtime
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/WorldState.cs
Covered lines:35
Uncovered lines:10
Coverable lines:45
Total lines:121
Line coverage:77.7% (35 of 45)
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    {
 117012        public HashSet<string> readyScenes { get; set; } = new HashSet<string>();
 562113        public Dictionary<string, IParcelScene> loadedScenes { get; set; } = new Dictionary<string, IParcelScene>();
 445814        public List<IParcelScene> scenesSortedByDistance { get; set; } = new List<IParcelScene>();
 122915        public List<string> globalSceneIds { get; set; } = new List<string>();
 424416        public string currentSceneId { get; set; } = null;
 17
 18        public IParcelScene GetScene(string id)
 19        {
 1620            if (!Contains(id))
 021                return null;
 22
 1623            return loadedScenes[id];
 24        }
 25
 26        public bool Contains(string id)
 27        {
 45028            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 129                return false;
 30
 44931            return true;
 32        }
 33
 34        public bool TryGetScene(string id, out IParcelScene scene)
 35        {
 2436            scene = null;
 37
 2438            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 1039                return false;
 40
 1441            scene = loadedScenes[id];
 1442            return true;
 43        }
 44
 45        public bool TryGetScene<T>(string id, out T scene)
 46            where T : class, IParcelScene
 47        {
 048            scene = default(T);
 049            bool result = TryGetScene(id, out IParcelScene baseScene);
 50
 051            if (result)
 052                scene = baseScene as T;
 53
 054            if (scene == null)
 055                result = false;
 56
 057            return result;
 58        }
 59
 60        public HashSet<Vector2Int> GetAllLoadedScenesCoords()
 61        {
 78762            HashSet<Vector2Int> allLoadedParcelCoords = new HashSet<Vector2Int>();
 63
 64            // Create fast (hashset) collection of loaded parcels coords
 183665            foreach (var element in loadedScenes)
 66            {
 13167                ParcelScene scene = element.Value as ParcelScene;
 68
 13169                if (!scene.sceneLifecycleHandler.isReady)
 70                    continue;
 71
 572                allLoadedParcelCoords.UnionWith(scene.parcels);
 73            }
 74
 78775            return allLoadedParcelCoords;
 76        }
 77
 76678        private readonly Dictionary<GameObject, LoadWrapper>
 79            attachedLoaders = new Dictionary<GameObject, LoadWrapper>();
 80
 81        public LoadWrapper GetLoaderForEntity(IDCLEntity entity)
 82        {
 23483            if (entity.meshRootGameObject == null)
 84            {
 085                Debug.LogWarning("NULL meshRootGameObject at GetLoaderForEntity()");
 086                return null;
 87            }
 88
 23489            attachedLoaders.TryGetValue(entity.meshRootGameObject, out LoadWrapper result);
 23490            return result;
 91        }
 92
 93        public T GetOrAddLoaderForEntity<T>(IDCLEntity entity)
 94            where T : LoadWrapper, new()
 95        {
 9996            if (!attachedLoaders.TryGetValue(entity.meshRootGameObject, out LoadWrapper result))
 97            {
 9798                result = new T();
 9799                attachedLoaders.Add(entity.meshRootGameObject, result);
 100            }
 101
 99102            return result as T;
 103        }
 104
 105        public void RemoveLoaderForEntity(IDCLEntity entity)
 106        {
 76107            if (entity == null || entity.meshRootGameObject == null)
 7108                return;
 109
 69110            attachedLoaders.Remove(entity.meshRootGameObject);
 69111        }
 112
 113        public void Dispose()
 114        {
 761115        }
 116
 117        public void Initialize()
 118        {
 761119        }
 120    }
 121}