< Summary

Class:DCL.Backpack.WearableGridComponentView
Assembly:BackpackEditorHUDV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/WearableGridComponentView.cs
Covered lines:74
Uncovered lines:10
Coverable lines:84
Total lines:199
Line coverage:88% (74 of 84)
Covered branches:0
Total branches:0
Covered methods:15
Total methods:20
Method coverage:75% (15 of 20)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
WearableGridComponentView()0%110100%
Awake()0%110100%
OnEnable()0%110100%
Dispose()0%330100%
SetWearablePages(...)0%220100%
ShowWearables(...)0%330100%
ClearWearables()0%220100%
SetWearable(...)0%330100%
ClearWearableSelection()0%220100%
SelectWearable(...)0%110100%
FillInfoCard(...)0%110100%
SetInfoCardVisible(...)0%110100%
SetLoadingActive(...)0%110100%
SetWearableBreadcrumb(...)0%110100%
RefreshWearable(...)0%6200%
RefreshAllWearables()0%6200%
HandleWearableSelected(...)0%6200%
HandleWearableEquipped(...)0%6200%
HandleWearableUnequipped(...)0%6200%
UpdateEmptyState()0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BackpackEditorHUDV2/WearableGridComponentView.cs

#LineLine coverage
 1using DCLServices.WearablesCatalogService;
 2using System;
 3using System.Collections.Generic;
 4using UIComponents.Scripts.Components;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.Backpack
 9{
 10    public class WearableGridComponentView : MonoBehaviour, IWearableGridView
 11    {
 12        [SerializeField] internal NftBreadcrumbComponentView wearablesBreadcrumbComponentView;
 13        [SerializeField] internal GridContainerComponentView wearablesGridContainer;
 14        [SerializeField] internal WearableGridItemComponentView wearableGridItemPrefab;
 15        [SerializeField] internal PageSelectorComponentView wearablePageSelector;
 16        [SerializeField] internal InfoCardComponentView infoCardComponentView;
 17        [SerializeField] internal GameObject emptyStateContainer;
 18        [SerializeField] internal GameObject emptyStateContainerForSignUp;
 19        [SerializeField] internal Button goToMarketplaceButton;
 20        [SerializeField] internal GameObject loadingSpinner;
 21
 3722        private readonly Dictionary<WearableGridItemComponentView, PoolableObject> wearablePooledObjects = new ();
 3723        private readonly Dictionary<string, WearableGridItemComponentView> wearablesById = new ();
 24
 25        private Pool wearableGridItemsPool;
 26        private WearableGridItemComponentView selectedWearableItem;
 27
 28        public event Action<int> OnWearablePageChanged;
 29        public event Action<string> OnFilterSelected;
 30        public event Action<string> OnFilterRemoved;
 31        public event Action OnGoToMarketplace;
 32        public event Action<WearableGridItemModel> OnWearableSelected;
 33        public event Action<WearableGridItemModel, EquipWearableSource> OnWearableEquipped;
 34        public event Action<WearableGridItemModel, UnequipWearableSource> OnWearableUnequipped;
 35
 36        private void Awake()
 37        {
 3538            wearablePageSelector.OnValueChanged += i => OnWearablePageChanged?.Invoke(i + 1);
 39
 3540            wearableGridItemsPool = PoolManager.i.AddPool(
 41                $"GridWearableItems_{GetInstanceID()}",
 42                Instantiate(wearableGridItemPrefab).gameObject,
 43                maxPrewarmCount: 15,
 44                isPersistent: true);
 45
 3546            wearableGridItemsPool.ForcePrewarm();
 47
 3548            wearablesBreadcrumbComponentView.OnFilterSelected += reference => OnFilterSelected?.Invoke(reference);
 3549            wearablesBreadcrumbComponentView.OnFilterRemoved += reference => OnFilterRemoved?.Invoke(reference);
 50
 3551            infoCardComponentView.OnEquipWearable += () => OnWearableEquipped?.Invoke(selectedWearableItem.Model, EquipW
 3552            infoCardComponentView.OnUnEquipWearable += () => OnWearableUnequipped?.Invoke(selectedWearableItem.Model, Un
 53
 3554            goToMarketplaceButton.onClick.AddListener(() => OnGoToMarketplace?.Invoke());
 3555        }
 56
 57        private void OnEnable()
 58        {
 3659            ClearWearableSelection();
 3660        }
 61
 62        public void Dispose()
 63        {
 1864            if (this && gameObject)
 1865                Destroy(gameObject);
 1866        }
 67
 68        public void SetWearablePages(int pageNumber, int totalPages)
 69        {
 470            if (totalPages <= 1)
 71            {
 172                wearablePageSelector.gameObject.SetActive(false);
 173                return;
 74            }
 75
 376            wearablePageSelector.gameObject.SetActive(true);
 377            wearablePageSelector.Setup(totalPages, true);
 378            wearablePageSelector.SelectPage(pageNumber - 1, false);
 379        }
 80
 81        public void ShowWearables(IEnumerable<WearableGridItemModel> wearables)
 82        {
 1683            foreach (WearableGridItemModel wearable in wearables)
 484                SetWearable(wearable);
 85
 486            UpdateEmptyState();
 487        }
 88
 89        public void ClearWearables()
 90        {
 491            wearablesGridContainer.ExtractItems();
 92
 1293            foreach ((WearableGridItemComponentView wearableGridItem, PoolableObject poolObj) in wearablePooledObjects)
 94            {
 295                wearableGridItem.OnSelected -= HandleWearableSelected;
 296                wearableGridItem.OnEquipped -= HandleWearableEquipped;
 297                wearableGridItem.OnUnequipped -= HandleWearableUnequipped;
 98
 299                poolObj.Release();
 100            }
 101
 4102            wearablePooledObjects.Clear();
 4103            wearablesById.Clear();
 104
 4105            UpdateEmptyState();
 4106        }
 107
 108        public void SetWearable(WearableGridItemModel model)
 109        {
 10110            string shortenedWearableId = ExtendedUrnParser.GetShortenedUrn(model.WearableId);
 111
 10112            if (wearablesById.TryGetValue(shortenedWearableId, out var view))
 1113                view.SetModel(model);
 114            else
 115            {
 9116                PoolableObject poolObj = wearableGridItemsPool.Get();
 9117                WearableGridItemComponentView wearableGridItem = poolObj.gameObject.GetComponent<WearableGridItemCompone
 9118                wearablePooledObjects[wearableGridItem] = poolObj;
 9119                wearablesById[shortenedWearableId] = wearableGridItem;
 9120                wearableGridItem.SetModel(model);
 9121                wearablesGridContainer.AddItem(wearableGridItem);
 9122                wearableGridItem.OnSelected += HandleWearableSelected;
 9123                wearableGridItem.OnEquipped += HandleWearableEquipped;
 9124                wearableGridItem.OnUnequipped += HandleWearableUnequipped;
 125            }
 126
 10127            if (model.IsEquipped)
 3128                infoCardComponentView.Equip(model.WearableId);
 129            else
 7130                infoCardComponentView.UnEquip(model.WearableId);
 131
 10132            UpdateEmptyState();
 10133        }
 134
 135        public void ClearWearableSelection()
 136        {
 78137            foreach (WearableGridItemComponentView view in wearablePooledObjects.Keys)
 2138                view.Unselect();
 139
 37140            selectedWearableItem = null;
 37141            SetInfoCardVisible(false);
 37142        }
 143
 144        public void SelectWearable(string wearableId)
 145        {
 1146            selectedWearableItem = wearablesById[wearableId];
 1147            selectedWearableItem.Select();
 1148            SetInfoCardVisible(true);
 1149        }
 150
 151        public void FillInfoCard(InfoCardComponentModel model) =>
 1152            infoCardComponentView.SetModel(model);
 153
 154        public void SetInfoCardVisible(bool isVisible) =>
 40155            infoCardComponentView.SetVisible(isVisible);
 156
 157        public void SetLoadingActive(bool isActive)
 158        {
 2159            loadingSpinner.SetActive(isActive);
 2160            UpdateEmptyState();
 2161        }
 162
 163        public void SetWearableBreadcrumb(NftBreadcrumbModel model) =>
 1164            wearablesBreadcrumbComponentView.SetModel(model);
 165
 166        public void RefreshWearable(string wearableId)
 167        {
 0168            if (!wearablesById.TryGetValue(wearableId, out var view))
 0169                return;
 170
 0171            view.RefreshControl();
 0172        }
 173
 174        public void RefreshAllWearables()
 175        {
 0176            foreach (WearableGridItemComponentView view in wearablePooledObjects.Keys)
 0177                view.RefreshControl();
 0178        }
 179
 180        private void HandleWearableSelected(WearableGridItemModel model) =>
 0181            OnWearableSelected?.Invoke(model);
 182
 183        private void HandleWearableEquipped(WearableGridItemModel model) =>
 0184            OnWearableEquipped?.Invoke(model, EquipWearableSource.Wearable);
 185
 186        private void HandleWearableUnequipped(WearableGridItemModel model) =>
 0187            OnWearableUnequipped?.Invoke(model, UnequipWearableSource.Wearable);
 188
 189        private void UpdateEmptyState()
 190        {
 20191            bool isEmpty = wearablesById.Count == 0;
 192
 20193            wearablesGridContainer.gameObject.SetActive(!isEmpty && !loadingSpinner.activeSelf);
 194
 20195            emptyStateContainer.SetActive(isEmpty && !loadingSpinner.activeSelf && !DataStore.i.common.isSignUpFlow.Get(
 20196            emptyStateContainerForSignUp.SetActive(isEmpty && !loadingSpinner.activeSelf && DataStore.i.common.isSignUpF
 20197        }
 198    }
 199}