< 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:0
Uncovered lines:53
Coverable lines:53
Total lines:183
Line coverage:0% (0 of 53)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:14
Method coverage:0% (0 of 14)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Equals(...)0%56700%
FromWearableItem(...)0%6200%
FromEmoteItem(...)0%2100%
SetSkin(...)0%2100%
SetModel(...)0%72800%
SetActive(...)0%2100%
SetBackgroundColor(...)0%6200%
SetRarityName(...)0%6200%
SetSellButtonActive(...)0%2100%
SetCategoryInfoActive(...)0%2100%
UpdateItemThumbnail(...)0%2100%
GetThumbnail()0%12300%
OnEnable()0%2100%

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        {
 033            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        {
 044            var iconsIds = wearable.data.representations.SelectMany(x => x.bodyShapes).ToList();
 045            iconsIds.Add(wearable.data.category);
 46
 047            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        {
 062            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    {
 096        this.rarityName.text = rarityName;
 097        this.rarityName.color = skin.rarityNameColor;
 098        backgroundImage.color = skin.backgroundColor;
 99        // gradientImage.color = skin.gradientColor;
 0100    }
 101
 102    public void SetModel(Model newModel)
 103    {
 0104        if (newModel == null)
 0105            return;
 106
 0107        if (currentModel != null && newModel.Equals(currentModel))
 0108            return;
 109
 0110        currentModel = newModel;
 111
 0112        name.text = currentModel.name;
 113
 0114        foreach (var icon in icons)
 115        {
 0116            icon.gameObject.SetActive(currentModel.iconIds.Contains(icon.iconId));
 117        }
 118
 0119        if (!string.IsNullOrEmpty(currentModel.description))
 0120            description.text = currentModel.description;
 121        else
 0122            description.text = "No description.";
 123
 0124        minted.text = $"{currentModel.issuedId} / {currentModel.issuedTotal}";
 125
 0126        Utils.InverseTransformChildTraversal<LayoutGroup>((x) =>
 127        {
 0128            RectTransform rt = x.transform as RectTransform;
 0129            Utils.ForceRebuildLayoutImmediate(rt);
 0130        }, transform);
 131
 132
 0133        ethNetwork.SetActive(!currentModel.isInL2);
 0134        l2Network.SetActive(currentModel.isInL2);
 135
 0136        if (gameObject.activeInHierarchy)
 0137            GetThumbnail();
 0138    }
 139
 0140    public void SetActive(bool active) { gameObject.SetActive(active); }
 141
 142    public void SetBackgroundColor(Color color)
 143    {
 0144        if (backgroundImage == null)
 0145            return;
 146
 0147        backgroundImage.color = color;
 0148    }
 149
 150    public void SetRarityName(string name)
 151    {
 0152        if (rarityName == null)
 0153            return;
 154
 0155        rarityName.text = name;
 0156    }
 157
 0158    public void SetSellButtonActive(bool isActive) => sellButton.gameObject.SetActive(isActive);
 159
 0160    public void SetCategoryInfoActive(bool isActive) => categoryInfoContainer.SetActive(isActive);
 161
 162    private void UpdateItemThumbnail(Asset_Texture texture)
 163    {
 0164        thumbnail.sprite = ThumbnailsManager.GetOrCreateSpriteFromTexture(texture.texture, out _);
 0165        thumbnail.preserveAspect = true;
 0166    }
 167
 168    private void GetThumbnail()
 169    {
 0170        if (currentModel == null)
 0171            return;
 172
 0173        if (currentModel.thumbnailSprite != null)
 174        {
 0175            thumbnail.sprite = currentModel.thumbnailSprite;
 0176            return;
 177        }
 178
 0179        ThumbnailsManager.GetThumbnail(currentModel.thumbnail, UpdateItemThumbnail);
 0180    }
 181
 0182    private void OnEnable() { GetThumbnail(); }
 183}