< 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:17
Coverable lines:55
Total lines:119
Line coverage:69% (38 of 55)
Covered branches:0
Total branches:0
Covered methods:8
Total methods:11
Method coverage:72.7% (8 of 11)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Model()0%110100%
GetDataFromJSON(...)0%110100%
GetDataFromPb(...)0%72800%
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.Helpers;
 2using DCL.Models;
 3using UnityEngine;
 4using Decentraland.Sdk.Ecs6;
 5using MainScripts.DCL.Components;
 6
 7namespace DCL.Components
 8{
 9    public class NFTShape : LoadableShape<LoadWrapper_NFT, NFTShape.Model>
 10    {
 11        [System.Serializable]
 12        public new class Model : LoadableShape.Model
 13        {
 3314            public Color color = new (0.6404918f, 0.611472f, 0.8584906f); // "light purple" default, same as in explorer
 15            public int style;
 16
 17            public override BaseModel GetDataFromJSON(string json) =>
 1218                Utils.SafeFromJson<Model>(json);
 19
 20            public override BaseModel GetDataFromPb(ComponentBodyPayload pbModel)
 21            {
 022                if (pbModel.PayloadCase != ComponentBodyPayload.PayloadOneofCase.NftShape)
 023                    return Utils.SafeUnimplemented<NFTShape, Model>(expected: ComponentBodyPayload.PayloadOneofCase.NftS
 24
 025                var pb = new Model();
 026                if (pbModel.NftShape.Color != null) pb.color = pbModel.NftShape.Color.AsUnityColor();
 027                if (pbModel.NftShape.HasStyle) pb.style = (int)pbModel.NftShape.Style;
 028                if (pbModel.NftShape.HasSrc) pb.src = pbModel.NftShape.Src;
 029                if (pbModel.NftShape.HasVisible) pb.visible = pbModel.NftShape.Visible;
 030                if (pbModel.NftShape.HasWithCollisions) pb.withCollisions = pbModel.NftShape.WithCollisions;
 031                if (pbModel.NftShape.HasIsPointerBlocker) pb.isPointerBlocker = pbModel.NftShape.IsPointerBlocker;
 32
 033                return pb;
 34            }
 35        }
 36
 737        public override string componentName => "NFT Shape";
 38
 39        private INFTInfoRetriever infoRetriever;
 40        private INFTAssetRetriever assetRetriever;
 41
 942        public NFTShape(INFTInfoRetriever infoRetriever, INFTAssetRetriever assetRetriever)
 43        {
 944            model = new Model();
 945            this.infoRetriever = infoRetriever;
 946            this.assetRetriever = assetRetriever;
 947        }
 48
 049        public override int GetClassId() { return (int) CLASS_ID.NFT_SHAPE; }
 50
 51        protected override void AttachShape(IDCLEntity entity)
 52        {
 753            if (string.IsNullOrEmpty(model.src))
 54            {
 55#if UNITY_EDITOR
 056                Debug.LogError($"NFT SHAPE with url '{model.src}' couldn't be loaded.");
 57#endif
 058                return;
 59            }
 60
 761            entity.meshesInfo.meshRootGameObject = NFTShapeFactory.InstantiateLoaderController(model.style);
 762            entity.meshesInfo.currentShape = this;
 63
 764            entity.meshRootGameObject.name = componentName + " mesh";
 765            entity.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 766            entity.meshRootGameObject.transform.ResetLocalTRS();
 67
 768            var loaderController = entity.meshRootGameObject.GetComponent<NFTShapeLoaderController>();
 69
 770            if (loaderController)
 771                loaderController.Initialize(infoRetriever, assetRetriever);
 72
 773            entity.OnShapeUpdated += UpdateBackgroundColor;
 74
 775            var loadableShape = Environment.i.world.state.GetOrAddLoaderForEntity<LoadWrapper_NFT>(entity);
 76
 777            loadableShape.entity = entity;
 78
 779            bool initialVisibility = model.visible;
 780            if (!DataStore.i.debugConfig.isDebugMode.Get())
 481                initialVisibility &= entity.isInsideSceneBoundaries;
 782            loadableShape.initialVisibility = initialVisibility;
 83
 784            loadableShape.withCollisions = model.withCollisions && entity.isInsideSceneBoundaries;
 785            loadableShape.backgroundColor = model.color;
 86
 787            loadableShape.Load(model.src, OnLoadCompleted, OnLoadFailed);
 788        }
 89
 90        protected override void DetachShape(IDCLEntity entity)
 91        {
 692            if (entity == null || entity.meshRootGameObject == null)
 093                return;
 94
 695            entity.OnShapeUpdated -= UpdateBackgroundColor;
 96
 697            base.DetachShape(entity);
 698        }
 99
 14100        protected override void ConfigureColliders(IDCLEntity entity) { CollidersManager.i.ConfigureColliders(entity.mes
 101
 102        void UpdateBackgroundColor(IDCLEntity entity)
 103        {
 15104            if (previousModel is NFTShape.Model && model.color == previousModel.color)
 14105                return;
 106
 1107            var loadableShape = Environment.i.world.state.GetLoaderForEntity(entity) as LoadWrapper_NFT;
 1108            loadableShape?.loaderController.UpdateBackgroundColor(model.color);
 1109        }
 110
 111        public override string ToString()
 112        {
 0113            if (model == null)
 0114                return base.ToString();
 115
 0116            return $"{componentName} (src = {model.src})";
 117        }
 118    }
 119}