< Summary

Class:NFTItemInfo
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/NFTItemInfo.cs
Covered lines:42
Uncovered lines:9
Coverable lines:51
Total lines:176
Line coverage:82.3% (42 of 51)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Equals(...)0%770100%
FromWearableItem(...)0%220100%
FromEmoteItem(...)0%110100%
SetSkin(...)0%110100%
SetModel(...)0%8.068090%
SetActive(...)0%110100%
SetBackgroundColor(...)0%2.062075%
SetRarityName(...)0%2.062075%
UpdateItemThumbnail(...)0%2100%
GetThumbnail()0%3.213071.43%
OnEnable()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/NFTItemInfo.cs

#LineLine coverage
 1using DCL;
 2using DCL.EmotesCustomization;
 3using DCL.Helpers;
 4using System;
 5using System.Collections.Generic;
 6using System.Linq;
 7using TMPro;
 8using UnityEngine;
 9using UnityEngine.UI;
 10
 11public class NFTItemInfo : MonoBehaviour
 12{
 13    [Serializable]
 14    internal class IconToGameObjectMap
 15    {
 16        public string iconId;
 17        public GameObject gameObject;
 18    }
 19
 20    public class Model
 21    {
 22        public string name;
 23        public string thumbnail;
 24        public Sprite thumbnailSprite;
 25        public List<string> iconIds;
 26        public string description;
 27        public int issuedId;
 28        public int issuedTotal;
 29        public bool isInL2;
 30
 31        public bool Equals(Model other)
 32        {
 183533            return name == other.name
 34                   && thumbnail == other.thumbnail
 35                   && thumbnailSprite == other.thumbnailSprite
 36                   && iconIds.SequenceEqual(other.iconIds)
 37                   && description == other.description
 38                   && issuedId == other.issuedId
 39                   && issuedTotal == other.issuedTotal;
 40        }
 41
 42        public static Model FromWearableItem(WearableItem wearable)
 43        {
 614644            var iconsIds = wearable.data.representations.SelectMany(x => x.bodyShapes).ToList();
 281545            iconsIds.Add(wearable.data.category);
 46
 281547            return new Model()
 48            {
 49                name = wearable.GetName(),
 50                thumbnail = wearable.baseUrl + wearable.thumbnail,
 51                thumbnailSprite = wearable.thumbnailSprite,
 52                iconIds = iconsIds,
 53                description = wearable.description,
 54                issuedId = wearable.issuedId,
 55                issuedTotal = wearable.GetIssuedCountFromRarity(wearable.rarity),
 56                isInL2 = wearable.IsInL2()
 57            };
 58        }
 59
 60        public static Model FromEmoteItem(EmoteCardComponentModel emote)
 61        {
 162            return new Model
 63            {
 64                name = emote.name,
 65                thumbnail = emote.pictureUri,
 66                thumbnailSprite = emote.pictureSprite,
 67                iconIds = new List<string>(),
 68                description = emote.description,
 69                issuedId = 1,
 70                issuedTotal = int.MaxValue,
 71                isInL2 = emote.isInL2
 72            };
 73        }
 74    }
 75
 76    [SerializeField] internal TextMeshProUGUI name;
 77    [SerializeField] internal Image thumbnail;
 78    [SerializeField] internal IconToGameObjectMap[] icons;
 79    [SerializeField] internal TextMeshProUGUI description;
 80    [SerializeField] internal TextMeshProUGUI minted;
 81    [SerializeField] internal GameObject ethNetwork;
 82    [SerializeField] internal GameObject l2Network;
 83    [SerializeField] internal Image backgroundImage;
 84    [SerializeField] internal Image gradientImage;
 85    [SerializeField] internal TextMeshProUGUI rarityName;
 86    [SerializeField] internal Button sellButton;
 87    [SerializeField] internal Button closeButton;
 88
 89    private Model currentModel;
 90    public void SetSkin(string rarityName, NFTItemToggleSkin skin)
 91    {
 281592        this.rarityName.text = rarityName;
 281593        this.rarityName.color = skin.rarityNameColor;
 281594        backgroundImage.color = skin.backgroundColor;
 281595        gradientImage.color = skin.gradientColor;
 96
 281597    }
 98
 99    public void SetModel(Model newModel)
 100    {
 2816101        if (newModel == null)
 0102            return;
 103
 2816104        if (currentModel != null && newModel.Equals(currentModel))
 1706105            return;
 106
 1110107        currentModel = newModel;
 108
 1110109        name.text = currentModel.name;
 110
 39960111        foreach (var icon in icons)
 112        {
 18870113            icon.gameObject.SetActive(currentModel.iconIds.Contains(icon.iconId));
 114        }
 115
 1110116        if (!string.IsNullOrEmpty(currentModel.description))
 35117            description.text = currentModel.description;
 118        else
 1075119            description.text = "No description.";
 120
 1110121        minted.text = $"{currentModel.issuedId} / {currentModel.issuedTotal}";
 122
 1110123        Utils.InverseTransformChildTraversal<LayoutGroup>((x) =>
 124        {
 9990125            RectTransform rt = x.transform as RectTransform;
 9990126            Utils.ForceRebuildLayoutImmediate(rt);
 9990127        }, transform);
 128
 129
 1110130        ethNetwork.SetActive(!currentModel.isInL2);
 1110131        l2Network.SetActive(currentModel.isInL2);
 132
 1110133        if (gameObject.activeInHierarchy)
 0134            GetThumbnail();
 1110135    }
 136
 247414137    public void SetActive(bool active) { gameObject.SetActive(active); }
 138
 139    public void SetBackgroundColor(Color color)
 140    {
 1141        if (backgroundImage == null)
 0142            return;
 143
 1144        backgroundImage.color = color;
 1145    }
 146
 147    public void SetRarityName(string name)
 148    {
 1149        if (rarityName == null)
 0150            return;
 151
 1152        rarityName.text = name;
 1153    }
 154
 155    private void UpdateItemThumbnail(Asset_Texture texture)
 156    {
 0157        thumbnail.sprite = ThumbnailsManager.GetOrCreateSpriteFromTexture(texture.texture, out _);
 0158        thumbnail.preserveAspect = true;
 0159    }
 160
 161    private void GetThumbnail()
 162    {
 3163        if (currentModel == null)
 2164            return;
 165
 1166        if (currentModel.thumbnailSprite != null)
 167        {
 1168            thumbnail.sprite = currentModel.thumbnailSprite;
 1169            return;
 170        }
 171
 0172        ThumbnailsManager.GetThumbnail(currentModel.thumbnail, UpdateItemThumbnail);
 0173    }
 174
 6175    private void OnEnable() { GetThumbnail(); }
 176}