< Summary

Class:DCL.ECSComponents.ECSNFTShapeComponentHandler
Assembly:DCL.ECSComponents.NFTShape
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/NFTShape/Handler/ECSNFTShapeComponentHandler.cs
Covered lines:53
Uncovered lines:3
Coverable lines:56
Total lines:126
Line coverage:94.6% (53 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
ECSNFTShapeComponentHandler(...)0%110100%
OnComponentCreated(...)0%2100%
OnComponentRemoved(...)0%110100%
OnComponentModelUpdated(...)0%330100%
DisposeShapeFrame(...)0%220100%
LoadNFT()0%8.147071.43%
CreateNFTShapeFrame(...)0%22090%
LoadFailed()0%110100%
ApplyModel(...)0%110100%
UpdateBackgroundColor(...)0%3.143075%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/NFTShape/Handler/ECSNFTShapeComponentHandler.cs

#LineLine coverage
 1using DCL.Controllers;
 2using DCL.ECSRuntime;
 3using DCL.Models;
 4using DCL.Helpers;
 5using DCL.Helpers.NFT;
 6using NFTShape_Internal;
 7using UnityEngine;
 8
 9namespace DCL.ECSComponents
 10{
 11    public class ECSNFTShapeComponentHandler : IECSComponentHandler<PBNFTShape>
 12    {
 13        internal INFTShapeFrameFactory factory;
 14
 15        internal INFTInfoRetriever infoRetriever;
 16        internal INFTAssetRetriever assetRetriever;
 17        internal INFTShapeFrame shapeFrame;
 18
 19        private PBNFTShape model;
 20
 21        public DataStore_ECS7 dataStore;
 22
 1223        public ECSNFTShapeComponentHandler(DataStore_ECS7 dataStore, INFTShapeFrameFactory factory, INFTInfoRetriever in
 24        {
 1225            this.dataStore = dataStore;
 1226            this.factory = factory;
 1227            this.infoRetriever = infoRetriever;
 1228            this.assetRetriever = assetRetriever;
 1229        }
 30
 031        public void OnComponentCreated(IParcelScene scene, IDCLEntity entity) { }
 32
 33        public void OnComponentRemoved(IParcelScene scene, IDCLEntity entity)
 34        {
 1235            infoRetriever.Dispose();
 1236            assetRetriever.Dispose();
 1237            DisposeShapeFrame(entity);
 1238        }
 39
 40        public void OnComponentModelUpdated(IParcelScene scene, IDCLEntity entity, PBNFTShape model)
 41        {
 42            // We create the frame gameobject
 343            if(shapeFrame == null || this.model.Style != model.Style)
 344                CreateNFTShapeFrame(entity, model);
 45
 46            // We apply the model to the frame
 347            ApplyModel(model);
 48
 49            // We load the NFT image
 350            LoadNFT(model);
 351        }
 52
 53        private void DisposeShapeFrame(IDCLEntity entity)
 54        {
 1255            if (shapeFrame == null)
 456                return;
 57
 858            dataStore.RemoveShapeReady(entity.entityId);
 859            shapeFrame.Dispose();
 860            ECSComponentsUtils.DisposeMeshInfo(entity.meshesInfo);
 861            GameObject.Destroy(shapeFrame.gameObject);
 862        }
 63
 64        internal async void LoadNFT(PBNFTShape model)
 65        {
 766            NFTInfo info = await infoRetriever.FetchNFTInfo(model.Src);
 67
 768            if (info == null)
 69            {
 470                LoadFailed();
 471                return;
 72            }
 73
 374            INFTAsset nftAsset = await assetRetriever.LoadNFTAsset(info.previewImageUrl);
 75
 376            if (nftAsset == null)
 77            {
 178                LoadFailed();
 179                return;
 80            }
 81
 282            shapeFrame.SetImage(info.name, info.imageUrl, nftAsset);
 783        }
 84
 85        private void CreateNFTShapeFrame(IDCLEntity entity,PBNFTShape model)
 86        {
 387            if (shapeFrame != null)
 088                DisposeShapeFrame(entity);
 89
 390            shapeFrame = factory.InstantiateLoaderController(model.Style);
 91
 392            entity.meshesInfo.meshRootGameObject = shapeFrame.gameObject;
 393            entity.meshesInfo.currentShape = shapeFrame.shape;
 94
 395            entity.meshesInfo.meshRootGameObject.name = "NFT mesh";
 396            entity.meshesInfo.meshRootGameObject.transform.SetParent(entity.gameObject.transform);
 397            entity.meshesInfo.meshRootGameObject.transform.ResetLocalTRS();
 98
 399            dataStore.AddShapeReady(entity.entityId, entity.meshesInfo.meshRootGameObject);
 3100        }
 101
 102        private void LoadFailed()
 103        {
 5104            factory.InstantiateErrorFeedback(shapeFrame.gameObject);
 5105            shapeFrame.FailLoading();
 5106        }
 107
 108        internal void ApplyModel(PBNFTShape model)
 109        {
 4110            shapeFrame.SetVisibility(model.GetVisible());
 4111            shapeFrame.SetHasCollisions(model.GetWithCollisions());
 4112            shapeFrame.SetPointerBlocker(model.GetIsPointerBlocker());
 4113            UpdateBackgroundColor(model);
 114
 4115            this.model = model;
 4116        }
 117
 118        internal void UpdateBackgroundColor(PBNFTShape model)
 119        {
 4120            if (this.model != null && model.Color.Equals(this.model.Color))
 0121                return;
 122
 4123            shapeFrame.UpdateBackgroundColor( new UnityEngine.Color(model.Color.R, model.Color.G,model.Color.B,1));
 4124        }
 125    }
 126}