< 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    {
 137510        public HashSet<string> readyScenes { get; set; } = new HashSet<string>();
 713711        public Dictionary<string, IParcelScene> loadedScenes { get; set; } = new Dictionary<string, IParcelScene>();
 603112        public List<IParcelScene> scenesSortedByDistance { get; set; } = new List<IParcelScene>();
 13
 156114        public List<string> globalSceneIds { get; set; }
 1763015        public string currentSceneId { get; set; }
 16
 17        public void Initialize()
 18        {
 68919            globalSceneIds = new List<string>();
 68920            currentSceneId = null;
 68921            readyScenes = new HashSet<string>();
 68922            loadedScenes = new Dictionary<string, IParcelScene>();
 68923            scenesSortedByDistance = new List<IParcelScene>();
 68924        }
 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        {
 74436            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 037                return false;
 38
 74439            return true;
 40        }
 41
 42        public bool TryGetScene(string id, out IParcelScene scene)
 43        {
 403844            scene = null;
 45
 403846            if (string.IsNullOrEmpty(id) || !loadedScenes.ContainsKey(id))
 201247                return false;
 48
 202649            scene = loadedScenes[id];
 202650            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        {
 131670            HashSet<Vector2Int> allLoadedParcelCoords = new HashSet<Vector2Int>();
 71
 72            // Create fast (hashset) collection of loaded parcels coords
 289873            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
 131683            return allLoadedParcelCoords;
 84        }
 85    }
 86}