< Summary

Class:DCL.Components.NFTShape
Assembly:DCL.Components.LoadableShapes
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/NFTShape.cs
Covered lines:39
Uncovered lines:6
Coverable lines:45
Total lines:101
Line coverage:86.6% (39 of 45)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
NFTShape(...)0%110100%
GetClassId()0%110100%
AttachShape(...)0%5.025090.91%
DetachShape(...)0%3.073080%
ConfigureColliders(...)0%110100%
UpdateBackgroundColor(...)0%440100%
ToString()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/NFTShape.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.Helpers;
 3using DCL.Models;
 4using UnityEngine;
 5
 6namespace DCL.Components
 7{
 8    public class NFTShape : LoadableShape<LoadWrapper_NFT, NFTShape.Model>
 9    {
 10        [System.Serializable]
 11        public new class Model : LoadableShape.Model
 12        {
 3713            public Color color = new Color(0.6404918f, 0.611472f, 0.8584906f); // "light purple" default, same as in exp
 14            public int style = 0;
 15
 1216            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 17        }
 18
 919        public override string componentName => "NFT Shape";
 20
 21        private INFTInfoRetriever infoRetriever;
 22        private INFTAssetRetriever assetRetriever;
 23
 1124        public NFTShape(INFTInfoRetriever infoRetriever, INFTAssetRetriever assetRetriever)
 25        {
 1126            model = new Model();
 1127            this.infoRetriever = infoRetriever;
 1128            this.assetRetriever = assetRetriever;
 1129        }
 30
 531        public override int GetClassId() { return (int) CLASS_ID.NFT_SHAPE; }
 32
 33        protected override void AttachShape(IDCLEntity entity)
 34        {
 935            if (string.IsNullOrEmpty(model.src))
 36            {
 37#if UNITY_EDITOR
 038                Debug.LogError($"NFT SHAPE with url '{model.src}' couldn't be loaded.");
 39#endif
 040                return;
 41            }
 42
 943            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 944            entity.meshesInfo.currentShape = this;
 45
 946            entity.meshRootGameObject.name = componentName + " mesh";
 947            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 948            entity.meshRootGameObject.transform.ResetLocalTRS();
 49
 950            var loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 51
 952            if (loaderController)
 953                loaderController.Initialize(infoRetriever, assetRetriever);
 54
 955            entity.OnShapeUpdated += UpdateBackgroundColor;
 56
 957            var loadableShape = Environment.i.world.state.GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 58
 959            loadableShape.entity = entity;
 60
 961            bool initialVisibility = model.visible;
 962            if (!DataStore.i.debugConfig.isDebugMode.Get())
 663                initialVisibility &= entity.isInsideSceneBoundaries;
 964            loadableShape.initialVisibility = initialVisibility;
 65
 966            loadableShape.withCollisions = model.withCollisions && entity.isInsideSceneBoundaries;
 967            loadableShape.backgroundColor = model.color;
 68
 969            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 970        }
 71
 72        protected override void DetachShape(IDCLEntity entity)
 73        {
 774            if (entity == null || entity.meshRootGameObject == null)
 075                return;
 76
 777            entity.OnShapeUpdated -= UpdateBackgroundColor;
 78
 779            base.DetachShape(entity);
 780        }
 81
 1882        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 83
 84        void UpdateBackgroundColor(IDCLEntity entity)
 85        {
 1886            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 1487                return;
 88
 489            var loadableShape = Environment.i.world.state.GetLoaderForEntity(entity) as LoadWrapper_NFT;
 490            loadableShape?.loaderController.UpdateBackgroundColor(model.color);
 491        }
 92
 93        public override string ToString()
 94        {
 095            if (model == null)
 096                return base.ToString();
 97
 098            return $"{componentName} (src = {model.src})";
 99        }
 100    }
 101}