< Summary

Class:NFTIconComponentView
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/NFTIcons/NFTIconComponentView.cs
Covered lines:27
Uncovered lines:59
Coverable lines:86
Total lines:190
Line coverage:31.3% (27 of 86)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:17
Method coverage:41.1% (7 of 17)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
NFTIconComponentView()0%110100%
Configure(...)0%6200%
RefreshControl()0%6200%
SetName(...)0%330100%
SetMarketplaceURI(...)0%110100%
SetImageURI(...)0%30500%
SetShowType(...)0%2100%
SetType(...)0%2100%
SetRarity(...)0%42600%
SetShowMarketplaceButton(...)0%110100%
OnFocus()0%3.073080%
OnLoseFocus()0%330100%
ConfigureNFTItemInfo(...)0%2100%
SetNFTItemInfoActive(...)0%20400%
SetNFTIconAsSelected(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/NFTIcons/NFTIconComponentView.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using TMPro;
 3using UnityEngine;
 4using UnityEngine.UI;
 5
 6public class NFTIconComponentView : BaseComponentView, INFTIconComponentView, IComponentModelConfig<NFTIconComponentMode
 7{
 8    private const string NAME_TYPE = "name";
 9    private const string PARCEL_TYPE = "parcel";
 10    private const string ESTATE_TYPE = "estate";
 11
 12    [SerializeField] internal ButtonComponentView marketplaceButton;
 13    [SerializeField] internal Button detailInfoButton;
 14    [SerializeField] internal TMP_Text nftName;
 15    [SerializeField] internal TMP_Text nftNameMarketPlace;
 16    [SerializeField] internal GameObject marketplaceSection;
 17    [SerializeField] internal GameObject outline;
 18    [SerializeField] internal ImageComponentView nftImage;
 19    [SerializeField] internal TMP_Text nftTextInsteadOfImage;
 20    [SerializeField] internal ImageComponentView typeImage;
 21    [SerializeField] internal Image backgroundImage;
 22    [SerializeField] internal Image backgroundImageGradient;
 23    [SerializeField] internal Image rarityBackgroundImage;
 24    [SerializeField] internal NFTTypeIconsAndColors nftTypesIcons;
 25    [SerializeField] internal NFTSkinFactory skinFactory;
 26    [SerializeField] internal SizeOnHover sizeOnHoverComponent;
 27    [SerializeField] internal Transform nftItemInfoPositionRightRef;
 28    [SerializeField] internal Transform nftItemInfoPositionLeftRef;
 29    [SerializeField] internal Sprite normalBackground;
 30    [SerializeField] internal Sprite nameBackground;
 31
 32    [SerializeField] internal NFTIconComponentModel model;
 33
 034    public Button.ButtonClickedEvent onMarketplaceButtonClick => marketplaceButton.onClick;
 035    public Button.ButtonClickedEvent onDetailInfoButtonClick => detailInfoButton.onClick;
 36
 37    private NFTItemInfo nftItemInfo;
 38    private NFTItemInfo.Model nftItemInfoCurrentModel;
 39    private bool showCategoryInfoOnNftItem;
 40    private string nftItemInfoRarity;
 141    private static readonly List<string> landTypes = new () { PARCEL_TYPE, ESTATE_TYPE };
 142    private static string nameType = NAME_TYPE;
 143    private static readonly Vector3 LAND_IMAGE_SCALE = new (5, 5, 5);
 144    private static readonly Vector3 NORMAL_IMAGE_SCALE = new (1, 1, 1);
 45
 46    public void Configure(NFTIconComponentModel newModel)
 47    {
 048        if (model == newModel)
 049            return;
 50
 051        model = newModel;
 052        RefreshControl();
 053    }
 54
 55    public override void RefreshControl()
 56    {
 057        if (model == null)
 058            return;
 59
 060        SetName(model.name);
 061        SetShowMarketplaceButton(model.showMarketplaceButton);
 062        SetMarketplaceURI(model.marketplaceURI);
 063        SetType(model.type);
 064        SetImageURI(model.imageURI);
 065        SetShowType(model.showType);
 066        SetRarity(model.rarity);
 067    }
 68
 69    public void SetName(string name)
 70    {
 171        model.name = name;
 72
 173        if (nftName != null)
 174            nftName.text = name;
 75
 176        if(nftNameMarketPlace != null)
 177            nftNameMarketPlace.text = name;
 178    }
 79
 80    public void SetMarketplaceURI(string marketplaceURI)
 81    {
 182        model.marketplaceURI = marketplaceURI;
 183    }
 84
 85    public void SetImageURI(string imageURI)
 86    {
 087        model.imageURI = imageURI;
 88
 089        if (nftImage != null)
 90        {
 091            nftImage.gameObject.transform.localScale = landTypes.Contains(model.type) ? LAND_IMAGE_SCALE : NORMAL_IMAGE_
 92
 093            nftImage.SetImage(imageURI);
 094            nftImage.gameObject.SetActive(!string.IsNullOrEmpty(imageURI));
 95        }
 96
 097        if (nftTextInsteadOfImage != null)
 98        {
 099            nftTextInsteadOfImage.text = model.name;
 0100            nftTextInsteadOfImage.gameObject.SetActive(string.IsNullOrEmpty(imageURI));
 101        }
 0102    }
 103
 104    public void SetShowType(bool showType)
 105    {
 0106        model.showType = showType;
 107
 0108        typeImage.gameObject.SetActive(showType);
 0109        rarityBackgroundImage.gameObject.SetActive(showType);
 0110    }
 111
 112    public void SetType(string type)
 113    {
 0114        model.type = type;
 0115        typeImage.SetImage(nftTypesIcons.GetTypeImage(type));
 0116    }
 117
 118    public void SetRarity(string rarity)
 119    {
 0120        model.rarity = rarity;
 0121        Color rarityColor = nftTypesIcons.GetColor(rarity);
 122
 0123        backgroundImage.sprite = model.type == nameType ? nameBackground : normalBackground;
 0124        backgroundImageGradient.enabled = model.type != nameType;
 0125        backgroundImage.color = model.type == nameType ? Color.white : new Color(rarityColor.r, rarityColor.g, rarityCol
 0126        rarityBackgroundImage.color = rarityColor;
 0127    }
 128
 129    public void SetShowMarketplaceButton(bool showMarketplaceButton)
 130    {
 2131        model.showMarketplaceButton = showMarketplaceButton;
 2132    }
 133
 134    public override void OnFocus()
 135    {
 1136        if (sizeOnHoverComponent == null || !sizeOnHoverComponent.enabled)
 0137            return;
 138
 1139        base.OnFocus();
 140
 1141        SetNFTIconAsSelected(true);
 1142    }
 143
 144    public override void OnLoseFocus()
 145    {
 5146        base.OnLoseFocus();
 147
 5148        if (nftItemInfo == null || !nftItemInfo.gameObject.activeSelf)
 5149            SetNFTIconAsSelected(false);
 5150    }
 151
 152    public void ConfigureNFTItemInfo(NFTItemInfo nftItemInfoModal, WearableItem wearableItem, bool showCategoryInfo)
 153    {
 0154        nftItemInfo = nftItemInfoModal;
 0155        nftItemInfo.OnCloseButtonClick.RemoveAllListeners();
 0156        nftItemInfo.OnCloseButtonClick.AddListener(() => SetNFTItemInfoActive(false));
 0157        nftItemInfoCurrentModel = NFTItemInfo.Model.FromWearableItem(wearableItem);
 0158        showCategoryInfoOnNftItem = showCategoryInfo;
 0159        nftItemInfoRarity = wearableItem.rarity;
 0160    }
 161
 162    public void SetNFTItemInfoActive(bool isActive, bool showInLeftSide = false)
 163    {
 0164        SetNFTIconAsSelected(isActive);
 0165        sizeOnHoverComponent.enabled = !isActive;
 166
 0167        if (nftItemInfo != null)
 168        {
 0169            nftItemInfo.SetActive(isActive);
 170
 0171            if (isActive)
 172            {
 0173                nftItemInfo.SetModel(nftItemInfoCurrentModel);
 0174                nftItemInfo.SetSkin(nftItemInfoRarity, skinFactory.GetSkinForRarity(nftItemInfoRarity));
 0175                nftItemInfo.SetSellButtonActive(false);
 0176                nftItemInfo.SetCategoryInfoActive(showCategoryInfoOnNftItem);
 0177                nftItemInfo.transform.position = showInLeftSide ? nftItemInfoPositionLeftRef.position : nftItemInfoPosit
 178            }
 179        }
 0180    }
 181
 182    private void SetNFTIconAsSelected(bool isSelected)
 183    {
 6184        if (!model.showMarketplaceButton)
 2185            return;
 186
 4187        marketplaceSection.SetActive(isSelected);
 4188        outline.SetActive(isSelected);
 4189    }
 190}