< Summary

Class:DCL.DataStore_WorldObjects_Extensions
Assembly:DataStore_Rendering_Extensions
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DataStore_Rendering_Extensions/DataStore_WorldObjects_Extensions.cs
Covered lines:63
Uncovered lines:12
Coverable lines:75
Total lines:151
Line coverage:84% (63 of 75)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DataStore_WorldObjects_Extensions()0%330100%
AddScene(...)0%220100%
RemoveScene(...)0%220100%
AddExcludedOwner(...)0%2.032080%
RemoveExcludedOwner(...)0%2.062075%
AddTexture(...)0%110100%
RemoveTexture(...)0%110100%
AddMaterial(...)0%110100%
RemoveMaterial(...)0%110100%
AddRendereable(...)0%5.795068.42%
RemoveRendereable(...)0%6.346078.95%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Helpers/DataStore_Rendering_Extensions/DataStore_WorldObjects_Extensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL.Models;
 5using UnityEngine;
 6using UnityEngine.Assertions;
 7
 8namespace DCL
 9{
 10    public static class DataStore_WorldObjects_Extensions
 11    {
 112        private static bool VERBOSE = false;
 113        private static ILogger logger = new Logger(Debug.unityLogger.logHandler) { filterLogType = VERBOSE ? LogType.Log
 14
 15        public static void AddScene( this DataStore_WorldObjects self, string sceneId )
 16        {
 50117            if (!self.sceneData.ContainsKey(sceneId))
 49618                self.sceneData.Add(sceneId, new DataStore_WorldObjects.SceneData());
 50119        }
 20
 21        public static void RemoveScene( this DataStore_WorldObjects self, string sceneId )
 22        {
 22023            if (self.sceneData.ContainsKey(sceneId))
 21824                self.sceneData.Remove(sceneId);
 22025        }
 26
 27        /// <summary>
 28        /// Add owner to the excluded owners list.
 29        /// </summary>
 30        /// <param name="self"></param>
 31        /// <param name="sceneId"></param>
 32        /// <param name="ownerId"></param>
 33        [Obsolete("This feature is only used by the SmartItem component and will have to be deprecated on the future. Pl
 34        public static void AddExcludedOwner(this DataStore_WorldObjects self, string sceneId, string ownerId)
 35        {
 836            if (!self.sceneData.ContainsKey(sceneId))
 037                return;
 38
 839            self.sceneData[sceneId].ignoredOwners.Add(ownerId);
 840            self.sceneData[sceneId].owners.Remove(ownerId);
 841        }
 42
 43        [Obsolete("This feature is only used by the SmartItem component and will have to be deprecated on the future. Pl
 44        public static void RemoveExcludedOwner(this DataStore_WorldObjects self, string sceneId, string ownerId)
 45        {
 446            if (!self.sceneData.ContainsKey(sceneId))
 047                return;
 48
 449            self.sceneData[sceneId].ignoredOwners.Remove(ownerId);
 450        }
 51
 52        public static void AddTexture(this DataStore_WorldObjects self, string sceneId, string ownerId, Texture texture)
 53        {
 6054            var r = new Rendereable();
 6055            r.textures.Add(texture);
 6056            r.ownerId = ownerId;
 6057            AddRendereable(self, sceneId, r);
 6058        }
 59
 60        public static void RemoveTexture(this DataStore_WorldObjects self, string sceneId, string ownerId, Texture textu
 61        {
 3462            var r = new Rendereable();
 3463            r.textures.Add(texture);
 3464            r.ownerId = ownerId;
 3465            RemoveRendereable(self, sceneId, r);
 3466        }
 67
 68        public static void AddMaterial(this DataStore_WorldObjects self, string sceneId, string ownerId, Material materi
 69        {
 6070            var r = new Rendereable();
 6071            r.materials.Add(material);
 6072            r.ownerId = ownerId;
 6073            AddRendereable(self, sceneId, r);
 6074        }
 75
 76        public static void RemoveMaterial(this DataStore_WorldObjects self, string sceneId, string ownerId, Material mat
 77        {
 9078            var r = new Rendereable();
 9079            r.materials.Add(material);
 9080            r.ownerId = ownerId;
 9081            RemoveRendereable(self, sceneId, r);
 9082        }
 83
 84
 85        public static void AddRendereable( this DataStore_WorldObjects self, string sceneId, Rendereable rendereable )
 86        {
 45187            if (rendereable == null)
 88            {
 089                logger.Log( $"Trying to add null rendereable! (id: {sceneId})");
 090                return;
 91            }
 92
 45193            if (string.IsNullOrEmpty(sceneId))
 94            {
 095                logger.LogWarning($"AddRendereable", $"invalid sceneId! (id: {sceneId})");
 096                return;
 97            }
 98
 45199            if (string.IsNullOrEmpty(rendereable.ownerId))
 100            {
 0101                logger.LogError($"AddRendereable", $"invalid ownerId! Make sure to assign ownerId to the given rendereab
 0102                return;
 103            }
 104
 451105            var sceneData = self.sceneData[sceneId];
 106
 451107            if ( sceneData.ignoredOwners.Contains(rendereable.ownerId))
 8108                return;
 109
 443110            sceneData.materials.AddRefCount(rendereable.materials);
 443111            sceneData.meshes.AddRefCount(rendereable.meshes);
 443112            sceneData.textures.AddRefCount(rendereable.textures);
 443113            sceneData.renderers.Add(rendereable.renderers);
 443114            sceneData.owners.Add(rendereable.ownerId);
 443115            sceneData.triangles.Set( sceneData.triangles.Get() + rendereable.totalTriangleCount);
 443116        }
 117
 118        public static void RemoveRendereable( this DataStore_WorldObjects self, string sceneId, Rendereable rendereable 
 119        {
 270120            if ( rendereable == null )
 121            {
 0122                logger.Log( $"Trying to remove null rendereable! (id: {sceneId})");
 0123                return;
 124            }
 125
 270126            if ( string.IsNullOrEmpty(sceneId) || !self.sceneData.ContainsKey(sceneId) )
 127            {
 3128                logger.LogWarning($"RemoveRendereable", $"invalid sceneId! (id: {sceneId})");
 3129                return;
 130            }
 131
 267132            if (string.IsNullOrEmpty(rendereable.ownerId))
 133            {
 0134                logger.LogError($"AddRendereable", $"invalid ownerId! Make sure to assign ownerId to the given rendereab
 0135                return;
 136            }
 137
 267138            var sceneData = self.sceneData[sceneId];
 139
 267140            if ( sceneData.ignoredOwners.Contains(rendereable.ownerId))
 8141                return;
 142
 259143            sceneData.materials.RemoveRefCount(rendereable.materials);
 259144            sceneData.meshes.RemoveRefCount(rendereable.meshes);
 259145            sceneData.textures.RemoveRefCount(rendereable.textures);
 259146            sceneData.renderers.Remove(rendereable.renderers);
 259147            sceneData.owners.Remove(rendereable.ownerId);
 259148            sceneData.triangles.Set( sceneData.triangles.Get() - rendereable.totalTriangleCount);
 259149        }
 150    }
 151}