< 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:21
Uncovered lines:20
Coverable lines:41
Total lines:138
Line coverage:51.2% (21 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Equals(...)0%42600%
FromWearableItem(...)0%220100%
SetModel(...)0%8.518080%
SetActive(...)0%110100%
UpdateItemThumbnail(...)0%6200%
GetThumbnail()0%6200%
ForgetThumbnail()0%2100%
OnEnable()0%2100%
OnDisable()0%2100%

File(s)

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

#LineLine coverage
 1using DCL.Helpers;
 2using System;
 3using System.Collections.Generic;
 4using System.Linq;
 5using DCL;
 6using TMPro;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10public class NFTItemInfo : MonoBehaviour
 11{
 12    [Serializable]
 13    internal class IconToGameObjectMap
 14    {
 15        public string iconId;
 16        public GameObject gameObject;
 17    }
 18
 19    public class Model
 20    {
 21        public string name;
 22        public string thumbnail;
 23        public List<string> iconIds;
 24        public string description;
 25        public int issuedId;
 26        public int issuedTotal;
 27        public bool isInL2;
 28
 29        public bool Equals(Model other)
 30        {
 031            return name == other.name
 32                   && thumbnail == other.thumbnail
 33                   && iconIds.SequenceEqual(other.iconIds)
 34                   && description == other.description
 35                   && issuedId == other.issuedId
 36                   && issuedTotal == other.issuedTotal;
 37        }
 38
 39        public static Model FromWearableItem(WearableItem wearable)
 40        {
 7241            var iconsIds = wearable.data.representations.SelectMany(x => x.bodyShapes).ToList();
 3642            iconsIds.Add(wearable.data.category);
 43
 3644            return new Model()
 45            {
 46                name = wearable.GetName(),
 47                thumbnail = wearable.baseUrl + wearable.thumbnail,
 48                iconIds = iconsIds,
 49                description = wearable.description,
 50                issuedId = wearable.issuedId,
 51                issuedTotal = wearable.GetIssuedCountFromRarity(wearable.rarity),
 52                isInL2 = wearable.IsInL2()
 53            };
 54        }
 55    }
 56
 57    [SerializeField] internal TextMeshProUGUI name;
 58    [SerializeField] internal Image thumbnail;
 59    [SerializeField] internal IconToGameObjectMap[] icons;
 60    [SerializeField] internal TextMeshProUGUI description;
 61    [SerializeField] internal TextMeshProUGUI minted;
 62    [SerializeField] internal GameObject ethNetwork;
 63    [SerializeField] internal GameObject l2Network;
 64
 65    private Model currentModel;
 66    private AssetPromise_Texture thumbnailPromise;
 67
 68    public void SetModel(Model newModel)
 69    {
 3670        if (newModel == null)
 071            return;
 72
 3673        if (currentModel != null && newModel.Equals(currentModel))
 074            return;
 75
 3676        currentModel = newModel;
 77
 3678        name.text = currentModel.name;
 79
 129680        foreach (var icon in icons)
 81        {
 61282            icon.gameObject.SetActive(currentModel.iconIds.Contains(icon.iconId));
 83        }
 84
 3685        if (!string.IsNullOrEmpty(currentModel.description))
 3686            description.text = currentModel.description;
 87        else
 088            description.text = "No description.";
 89
 3690        minted.text = $"{currentModel.issuedId} / {currentModel.issuedTotal}";
 91
 3692        Utils.InverseTransformChildTraversal<LayoutGroup>((x) =>
 93        {
 32494            RectTransform rt = x.transform as RectTransform;
 32495            Utils.ForceRebuildLayoutImmediate(rt);
 32496        }, transform);
 97
 98
 3699        ethNetwork.SetActive(!currentModel.isInL2);
 36100        l2Network.SetActive(currentModel.isInL2);
 101
 36102        if (gameObject.activeInHierarchy)
 0103            GetThumbnail();
 36104    }
 105
 112106    public void SetActive(bool active) { gameObject.SetActive(active); }
 107
 108    private void UpdateItemThumbnail(Asset_Texture texture)
 109    {
 0110        if (thumbnail.sprite != null)
 111        {
 0112            Destroy(thumbnail.sprite);
 113        }
 114
 0115        thumbnail.sprite = ThumbnailsManager.CreateSpriteFromTexture(texture.texture);
 0116    }
 117
 118    private void GetThumbnail()
 119    {
 0120        if (currentModel == null)
 0121            return;
 122
 123        //NOTE(Brian): Get before forget to prevent referenceCount == 0 and asset unload
 0124        var newThumbnailPromise = ThumbnailsManager.GetThumbnail(currentModel.thumbnail, UpdateItemThumbnail);
 0125        ThumbnailsManager.ForgetThumbnail(thumbnailPromise);
 0126        thumbnailPromise = newThumbnailPromise;
 0127    }
 128
 129    private void ForgetThumbnail()
 130    {
 0131        ThumbnailsManager.ForgetThumbnail(thumbnailPromise);
 0132        thumbnailPromise = null;
 0133    }
 134
 0135    private void OnEnable() { GetThumbnail(); }
 136
 0137    private void OnDisable() { ForgetThumbnail(); }
 138}