< 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:30
Uncovered lines:6
Coverable lines:36
Total lines:85
Line coverage:83.3% (30 of 36)
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.012088.24%
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
 3321        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        {
 927            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
 935            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 936            entity.meshesInfo.currentShape = this;
 37
 938            entity.meshRootGameObject.name = componentName + " mesh";
 939            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 940            entity.meshRootGameObject.transform.ResetLocalTRS();
 41
 942            entity.OnShapeUpdated += UpdateBackgroundColor;
 43
 944            var loadableShape = GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 45
 946            loadableShape.entity = entity;
 947            loadableShape.component = this;
 948            loadableShape.initialVisibility = model.visible;
 49
 950            loadableShape.withCollisions = model.withCollisions;
 951            loadableShape.backgroundColor = model.color;
 52
 953            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 954        }
 55
 56        protected override void DetachShape(IDCLEntity entity)
 57        {
 858            if (entity == null || entity.meshRootGameObject == null)
 059                return;
 60
 861            entity.OnShapeUpdated -= UpdateBackgroundColor;
 62
 863            base.DetachShape(entity);
 864        }
 65
 1866        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 67
 68        void UpdateBackgroundColor(IDCLEntity entity)
 69        {
 2270            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 1971                return;
 72
 373            var loadableShape = GetLoaderForEntity(entity) as LoadWrapper_NFT;
 374            loadableShape?.loaderController.UpdateBackgroundColor(model.color);
 375        }
 76
 77        public override string ToString()
 78        {
 079            if (model == null)
 080                return base.ToString();
 81
 082            return $"{componentName} (src = {model.src})";
 83        }
 84    }
 85}