< 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:38
Uncovered lines:7
Coverable lines:45
Total lines:101
Line coverage:84.4% (38 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%2100%
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        {
 3313            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
 719        public override string componentName => "NFT Shape";
 20
 21        private INFTInfoRetriever infoRetriever;
 22        private INFTAssetRetriever assetRetriever;
 23
 924        public NFTShape(INFTInfoRetriever infoRetriever, INFTAssetRetriever assetRetriever)
 25        {
 926            model = new Model();
 927            this.infoRetriever = infoRetriever;
 928            this.assetRetriever = assetRetriever;
 929        }
 30
 031        public override int GetClassId() { return (int) CLASS_ID.NFT_SHAPE; }
 32
 33        protected override void AttachShape(IDCLEntity entity)
 34        {
 735            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
 743            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 744            entity.meshesInfo.currentShape = this;
 45
 746            entity.meshRootGameObject.name = componentName + " mesh";
 747            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 748            entity.meshRootGameObject.transform.ResetLocalTRS();
 49
 750            var loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 51
 752            if (loaderController)
 753                loaderController.Initialize(infoRetriever, assetRetriever);
 54
 755            entity.OnShapeUpdated += UpdateBackgroundColor;
 56
 757            var loadableShape = Environment.i.world.state.GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 58
 759            loadableShape.entity = entity;
 60
 761            bool initialVisibility = model.visible;
 762            if (!DataStore.i.debugConfig.isDebugMode.Get())
 463                initialVisibility &= entity.isInsideSceneBoundaries;
 764            loadableShape.initialVisibility = initialVisibility;
 65
 766            loadableShape.withCollisions = model.withCollisions && entity.isInsideSceneBoundaries;
 767            loadableShape.backgroundColor = model.color;
 68
 769            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 770        }
 71
 72        protected override void DetachShape(IDCLEntity entity)
 73        {
 674            if (entity == null || entity.meshRootGameObject == null)
 075                return;
 76
 677            entity.OnShapeUpdated -= UpdateBackgroundColor;
 78
 679            base.DetachShape(entity);
 680        }
 81
 1482        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 83
 84        void UpdateBackgroundColor(IDCLEntity entity)
 85        {
 1586            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 1487                return;
 88
 189            var loadableShape = Environment.i.world.state.GetLoaderForEntity(entity) as LoadWrapper_NFT;
 190            loadableShape?.loaderController.UpdateBackgroundColor(model.color);
 191        }
 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}