< 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:36
Uncovered lines:6
Coverable lines:42
Total lines:97
Line coverage:85.7% (36 of 42)
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.035089.47%
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        {
 3413            public Color color = new Color(0.6404918f, 0.611472f, 0.8584906f); // "light purple" default, same as in exp
 14            public int style = 0;
 15
 1116            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 17        }
 18
 819        public override string componentName => "NFT Shape";
 20
 21        private INFTInfoRetriever infoRetriever;
 22        private INFTAssetRetriever assetRetriever;
 23
 1024        public NFTShape(INFTInfoRetriever infoRetriever, INFTAssetRetriever assetRetriever)
 25        {
 1026            model = new Model();
 1027            this.infoRetriever = infoRetriever;
 1028            this.assetRetriever = assetRetriever;
 1029        }
 30
 531        public override int GetClassId() { return (int) CLASS_ID.NFT_SHAPE; }
 32
 33        protected override void AttachShape(IDCLEntity entity)
 34        {
 835            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
 843            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 844            entity.meshesInfo.currentShape = this;
 45
 846            entity.meshRootGameObject.name = componentName + " mesh";
 847            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 848            entity.meshRootGameObject.transform.ResetLocalTRS();
 49
 850            var loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 51
 852            if (loaderController)
 853                loaderController.Initialize(infoRetriever, assetRetriever);
 54
 855            entity.OnShapeUpdated += UpdateBackgroundColor;
 56
 857            var loadableShape = Environment.i.world.state.GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 58
 859            loadableShape.entity = entity;
 860            loadableShape.initialVisibility = model.visible && entity.isInsideSceneBoundaries;
 61
 862            loadableShape.withCollisions = model.withCollisions && entity.isInsideSceneBoundaries;
 863            loadableShape.backgroundColor = model.color;
 64
 865            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 866        }
 67
 68        protected override void DetachShape(IDCLEntity entity)
 69        {
 670            if (entity == null || entity.meshRootGameObject == null)
 071                return;
 72
 673            entity.OnShapeUpdated -= UpdateBackgroundColor;
 74
 675            base.DetachShape(entity);
 676        }
 77
 1678        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 79
 80        void UpdateBackgroundColor(IDCLEntity entity)
 81        {
 1682            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 1283                return;
 84
 485            var loadableShape = Environment.i.world.state.GetLoaderForEntity(entity) as LoadWrapper_NFT;
 486            loadableShape?.loaderController.UpdateBackgroundColor(model.color);
 487        }
 88
 89        public override string ToString()
 90        {
 091            if (model == null)
 092                return base.ToString();
 93
 094            return $"{componentName} (src = {model.src})";
 95        }
 96    }
 97}