< Summary

Class:DCL.Components.NFTShape
Assembly:MainScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/LoadableShapes/NFTShape/NFTShape.cs
Covered lines:29
Uncovered lines:6
Coverable lines:35
Total lines:84
Line coverage:82.8% (29 of 35)
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%2.012087.5%
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        {
 4013            public Color color = new Color(0.6404918f, 0.611472f, 0.8584906f); // "light purple" default, same as in exp
 14            public int style = 0;
 15
 1316            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 17        }
 18
 1019        public override string componentName => "NFT Shape";
 20
 3621        public NFTShape() { model = new Model(); }
 22
 923        public override int GetClassId() { return (int) CLASS_ID.NFT_SHAPE; }
 24
 25        protected override void AttachShape(IDCLEntity entity)
 26        {
 1027            if (string.IsNullOrEmpty(model.src))
 28            {
 29#if UNITY_EDITOR
 030                Debug.LogError($"NFT SHAPE with url '{model.src}' couldn't be loaded.");
 31#endif
 032                return;
 33            }
 34
 1035            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 1036            entity.meshesInfo.currentShape = this;
 37
 1038            entity.meshRootGameObject.name = componentName + " mesh";
 1039            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 1040            entity.meshRootGameObject.transform.ResetLocalTRS();
 41
 1042            entity.OnShapeUpdated += UpdateBackgroundColor;
 43
 1044            var loadableShape = GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 45
 1046            loadableShape.entity = entity;
 1047            loadableShape.initialVisibility = model.visible;
 48
 1049            loadableShape.withCollisions = model.withCollisions;
 1050            loadableShape.backgroundColor = model.color;
 51
 1052            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 1053        }
 54
 55        protected override void DetachShape(IDCLEntity entity)
 56        {
 857            if (entity == null || entity.meshRootGameObject == null)
 058                return;
 59
 860            entity.OnShapeUpdated -= UpdateBackgroundColor;
 61
 862            base.DetachShape(entity);
 863        }
 64
 2065        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 66
 67        void UpdateBackgroundColor(IDCLEntity entity)
 68        {
 1869            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 1570                return;
 71
 372            var loadableShape = GetLoaderForEntity(entity) as LoadWrapper_NFT;
 373            loadableShape?.loaderController.UpdateBackgroundColor(model.color);
 374        }
 75
 76        public override string ToString()
 77        {
 078            if (model == null)
 079                return base.ToString();
 80
 081            return $"{componentName} (src = {model.src})";
 82        }
 83    }
 84}