< 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:25
Uncovered lines:10
Coverable lines:35
Total lines:84
Line coverage:71.4% (25 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%12300%
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        {
 1913            public Color color = new Color(0.6404918f, 0.611472f, 0.8584906f); // "light purple" default, same as in exp
 14            public int style = 0;
 15
 616            public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<Model>(json); }
 17        }
 18
 319        public override string componentName => "NFT Shape";
 20
 1521        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        {
 327            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
 335            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 336            entity.meshesInfo.currentShape = this;
 37
 338            entity.meshRootGameObject.name = componentName + " mesh";
 339            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 340            entity.meshRootGameObject.transform.ResetLocalTRS();
 41
 342            entity.OnShapeUpdated += UpdateBackgroundColor;
 43
 344            var loadableShape = GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 45
 346            loadableShape.entity = entity;
 347            loadableShape.initialVisibility = model.visible;
 48
 349            loadableShape.withCollisions = model.withCollisions;
 350            loadableShape.backgroundColor = model.color;
 51
 352            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 353        }
 54
 55        protected override void DetachShape(IDCLEntity entity)
 56        {
 057            if (entity == null || entity.meshRootGameObject == null)
 058                return;
 59
 060            entity.OnShapeUpdated -= UpdateBackgroundColor;
 61
 062            base.DetachShape(entity);
 063        }
 64
 665        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 66
 67        void UpdateBackgroundColor(IDCLEntity entity)
 68        {
 469            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 170                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}