< Summary

Class:DCL.WorldState
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/WorldState.cs
Covered lines:26
Uncovered lines:9
Coverable lines:35
Total lines:86
Line coverage:74.2% (26 of 35)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WorldState()0%110100%
Initialize()0%110100%
GetScene(...)0%2.152066.67%
Contains(...)0%3.333066.67%
TryGetScene(...)0%330100%
TryGetScene[T](...)0%12300%
GetAllLoadedScenesCoords()0%330100%

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 UnityEngine;
 5
 6namespace DCL
 7{
 8    public class WorldState : IWorldState
 9    {
 140810        public HashSet<string> readyScenes { get; set; } = new HashSet<string>();
 1475611        public Dictionary<string, IParcelScene> loadedScenes { get; set; } = new Dictionary<string, IParcelScene>();
 621012        public List<IParcelScene> scenesSortedByDistance { get; set; } = new List<IParcelScene>();
 13
 158514        public List<string> globalSceneIds { get; set; }
 1936115        public string currentSceneId { get; set; }
 16
 17        public void Initialize()
 18        {
 71919            globalSceneIds = new List<string>();
 71920            currentSceneId = null;
 71921            readyScenes = new HashSet<string>();
 71922            loadedScenes = new Dictionary<string, IParcelScene>();
 71923            scenesSortedByDistance = new List<IParcelScene>();
 71924        }
 25
 26        public IParcelScene GetScene(string id)
 27        {
 1728            if (!Contains(id))
 029                return null;
 30
 1731            return loadedScenes[id];
 32        }
 33
 34        public bool Contains(string id)
 35        {
 75236            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 037                return false;
 38
 75239            return true;
 40        }
 41
 42        public bool TryGetScene(string id, out IParcelScene scene)
 43        {
 585344            scene = null;
 45
 585346            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 292047                return false;
 48
 293349            scene = loadedScenes[id];
 293350            return true;
 51        }
 52
 53        public bool TryGetScene<T>(string id, out T scene)
 54            where T : class, IParcelScene
 55        {
 056            scene = default(T);
 057            bool result = TryGetScene(id, out IParcelScene baseScene);
 58
 059            if (result)
 060                scene = baseScene as T;
 61
 062            if (scene == null)
 063                result = false;
 64
 065            return result;
 66        }
 67
 68        public HashSet<Vector2Int> GetAllLoadedScenesCoords()
 69        {
 133070            HashSet<Vector2Int> allLoadedParcelCoords = new HashSet<Vector2Int>();
 71
 72            // Create fast (hashset) collection of loaded parcels coords
 292673            foreach (var element in loadedScenes)
 74            {
 13375                ParcelScene scene = element.Value as ParcelScene;
 76
 13377                if (!scene.sceneLifecycleHandler.isReady)
 78                    continue;
 79
 380                allLoadedParcelCoords.UnionWith(scene.parcels);
 81            }
 82
 133083            return allLoadedParcelCoords;
 84        }
 85    }
 86}