< 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:12
Coverable lines:54
Total lines:184
Line coverage:77.7% (42 of 54)
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%
SetSellButtonActive(...)0%2100%
SetCategoryInfoActive(...)0%2100%
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        {
 229633            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        {
 781844            var iconsIds = wearable.data.representations.SelectMany(x => x.bodyShapes).ToList();
 365445            iconsIds.Add(wearable.data.category);
 46
 365447            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    [SerializeField] internal GameObject categoryInfoContainer;
 89
 90    private Model currentModel;
 91
 092    public Button.ButtonClickedEvent OnCloseButtonClick => closeButton?.onClick;
 93
 94    public void SetSkin(string rarityName, NFTItemToggleSkin skin)
 95    {
 365496        this.rarityName.text = rarityName;
 365497        this.rarityName.color = skin.rarityNameColor;
 365498        backgroundImage.color = skin.backgroundColor;
 365499        gradientImage.color = skin.gradientColor;
 100
 3654101    }
 102
 103    public void SetModel(Model newModel)
 104    {
 3655105        if (newModel == null)
 0106            return;
 107
 3655108        if (currentModel != null && newModel.Equals(currentModel))
 2296109            return;
 110
 1359111        currentModel = newModel;
 112
 1359113        name.text = currentModel.name;
 114
 48924115        foreach (var icon in icons)
 116        {
 23103117            icon.gameObject.SetActive(currentModel.iconIds.Contains(icon.iconId));
 118        }
 119
 1359120        if (!string.IsNullOrEmpty(currentModel.description))
 37121            description.text = currentModel.description;
 122        else
 1322123            description.text = "No description.";
 124
 1359125        minted.text = $"{currentModel.issuedId} / {currentModel.issuedTotal}";
 126
 1359127        Utils.InverseTransformChildTraversal<LayoutGroup>((x) =>
 128        {
 12231129            RectTransform rt = x.transform as RectTransform;
 12231130            Utils.ForceRebuildLayoutImmediate(rt);
 12231131        }, transform);
 132
 133
 1359134        ethNetwork.SetActive(!currentModel.isInL2);
 1359135        l2Network.SetActive(currentModel.isInL2);
 136
 1359137        if (gameObject.activeInHierarchy)
 0138            GetThumbnail();
 1359139    }
 140
 236528141    public void SetActive(bool active) { gameObject.SetActive(active); }
 142
 143    public void SetBackgroundColor(Color color)
 144    {
 1145        if (backgroundImage == null)
 0146            return;
 147
 1148        backgroundImage.color = color;
 1149    }
 150
 151    public void SetRarityName(string name)
 152    {
 1153        if (rarityName == null)
 0154            return;
 155
 1156        rarityName.text = name;
 1157    }
 158
 0159    public void SetSellButtonActive(bool isActive) => sellButton.gameObject.SetActive(isActive);
 160
 0161    public void SetCategoryInfoActive(bool isActive) => categoryInfoContainer.SetActive(isActive);
 162
 163    private void UpdateItemThumbnail(Asset_Texture texture)
 164    {
 0165        thumbnail.sprite = ThumbnailsManager.GetOrCreateSpriteFromTexture(texture.texture, out _);
 0166        thumbnail.preserveAspect = true;
 0167    }
 168
 169    private void GetThumbnail()
 170    {
 3171        if (currentModel == null)
 2172            return;
 173
 1174        if (currentModel.thumbnailSprite != null)
 175        {
 1176            thumbnail.sprite = currentModel.thumbnailSprite;
 1177            return;
 178        }
 179
 0180        ThumbnailsManager.GetThumbnail(currentModel.thumbnail, UpdateItemThumbnail);
 0181    }
 182
 6183    private void OnEnable() { GetThumbnail(); }
 184}