< Summary

Class:DCL.EmotesCustomization.EmotesCustomizationComponentView
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/EmotesCustomization/EmotesCustomizationComponentView.cs
Covered lines:0
Uncovered lines:110
Coverable lines:110
Total lines:256
Line coverage:0% (0 of 110)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:29
Method coverage:0% (0 of 29)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%2100%
Start()0%2100%
RefreshControl()0%6200%
Dispose()0%2100%
CleanEmotes()0%2100%
AddEmote(...)0%2100%
RemoveEmote(...)0%6200%
EquipEmote(...)0%1101000%
UnequipEmote(...)0%30500%
OpenEmoteInfoPanel(...)0%2100%
SetEmoteInfoPanelActive(...)0%2100%
GetEmoteCardById(...)0%2100%
SetActive(...)0%2100%
GetSlot(...)0%2100%
Refresh()0%2100%
RefreshEmotesGrid()0%2100%
ClickOnEmote(...)0%6200%
OnEmoteSelected(...)0%2100%
ConfigureEmotesPool()0%6200%
InstantiateAndConfigureEmoteCard(...)0%2100%
OnSlotSelected(...)0%12300%
GetAllEmoteCards()0%6200%
Create(...)0%2100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using UnityEngine;
 5
 6namespace DCL.EmotesCustomization
 7{
 8    public class EmotesCustomizationComponentView : BaseComponentView, IEmotesCustomizationComponentView
 9    {
 10        internal const string EMOTE_CARDS_POOL_NAME = "EmotesCustomization_EmoteCardsPool";
 11        internal const int EMOTE_CARDS_POOL_PREWARM = 40;
 12        internal const int DEFAULT_SELECTED_SLOT = 1;
 13
 14        [Header("Assets References")]
 15        [SerializeField] internal EmoteCardComponentView emoteCardPrefab;
 16
 17        [Header("Prefab References")]
 18        [SerializeField] internal EmoteSlotSelectorComponentView emoteSlotSelector;
 19        [SerializeField] internal GridContainerComponentView emotesGrid;
 20        [SerializeField] internal NFTItemInfo emoteInfoPanel;
 21        [SerializeField] internal ColumnsOrganizerComponentView columnsOrganizerComponentView;
 22
 23        public event Action<string, int> onEmoteEquipped;
 24        public event Action<string, int> onEmoteUnequipped;
 25        public event Action<string> onSellEmoteClicked;
 26        public event Action<string, int, bool> onSlotSelected;
 27
 28        internal Pool emoteCardsPool;
 29
 030        public bool isActive => gameObject.activeInHierarchy;
 031        public Transform viewTransform => transform;
 032        public int selectedSlot => emoteSlotSelector.selectedSlot;
 033        public List<EmoteSlotCardComponentView> currentSlots => emoteSlotSelector.GetAllSlots();
 034        public EmoteCardComponentView selectedCard { get; private set; }
 35
 36        public override void Awake()
 37        {
 038            base.Awake();
 39
 040            emoteSlotSelector.onSlotSelected += OnSlotSelected;
 041            emoteInfoPanel.closeButton.onClick.AddListener(() => SetEmoteInfoPanelActive(false));
 42
 043            ConfigureEmotesPool();
 044        }
 45
 46        public void Start()
 47        {
 048            emoteSlotSelector.SelectSlot(DEFAULT_SELECTED_SLOT);
 049        }
 50
 51        public override void RefreshControl()
 52        {
 053            emoteSlotSelector.RefreshControl();
 054            emotesGrid.RefreshControl();
 055            columnsOrganizerComponentView?.RefreshControl();
 056        }
 57
 58        public override void Dispose()
 59        {
 060            CleanEmotes();
 61
 062            emoteSlotSelector.onSlotSelected -= OnSlotSelected;
 063            emoteInfoPanel.closeButton.onClick.RemoveAllListeners();
 064            emoteInfoPanel.sellButton.onClick.RemoveAllListeners();
 65
 066            base.Dispose();
 067        }
 68
 69        public void CleanEmotes()
 70        {
 071            emotesGrid.ExtractItems();
 072            emoteCardsPool.ReleaseAll();
 073        }
 74
 75        public EmoteCardComponentView AddEmote(EmoteCardComponentModel emote)
 76        {
 077            EmoteCardComponentView emoteGO = InstantiateAndConfigureEmoteCard(emote);
 078            emotesGrid.AddItemWithResize(emoteGO);
 79
 080            return emoteGO;
 81        }
 82
 83        public void RemoveEmote(string emoteId)
 84        {
 085            EmoteCardComponentView emoteToRemove = GetEmoteCardById(emoteId);
 086            if (emoteToRemove != null)
 087                emotesGrid.RemoveItem(emoteToRemove);
 088        }
 89
 90        public void EquipEmote(string emoteId, string emoteName, int slotNumber, bool selectSlotAfterEquip = true, bool 
 91        {
 092            if (string.IsNullOrEmpty(emoteId))
 093                return;
 94
 095            EmoteCardComponentView emoteCardsToUpdate = GetEmoteCardById(emoteId);
 096            if (emoteCardsToUpdate != null && emoteCardsToUpdate.model.assignedSlot == slotNumber)
 097                return;
 98
 099            List<EmoteCardComponentView> currentEmoteCards = GetAllEmoteCards();
 0100            foreach (var existingEmoteCard in currentEmoteCards)
 101            {
 0102                if (existingEmoteCard.model.assignedSlot == slotNumber)
 0103                    existingEmoteCard.UnassignSlot();
 104
 0105                if (existingEmoteCard.model.id == emoteId)
 106                {
 0107                    existingEmoteCard.AssignSlot(slotNumber);
 0108                    emoteSlotSelector.AssignEmoteIntoSlot(
 109                        slotNumber,
 110                        emoteId,
 111                        emoteName,
 112                        existingEmoteCard.model.pictureSprite,
 113                        existingEmoteCard.model.pictureUri,
 114                        existingEmoteCard.model.rarity);
 115
 0116                    if (selectSlotAfterEquip)
 0117                        emoteSlotSelector.SelectSlot(slotNumber);
 118                }
 119
 0120                existingEmoteCard.SetEmoteAsAssignedInSelectedSlot(existingEmoteCard.model.assignedSlot == selectedSlot)
 121            }
 122
 0123            SetEmoteInfoPanelActive(false);
 124
 0125            if (notifyEvent)
 0126                onEmoteEquipped?.Invoke(emoteId, slotNumber);
 0127        }
 128
 129        public void UnequipEmote(string emoteId, int slotNumber, bool notifyEvent = true)
 130        {
 0131            if (string.IsNullOrEmpty(emoteId))
 0132                return;
 133
 0134            EmoteCardComponentView emoteCardsToUpdate = GetEmoteCardById(emoteId);
 0135            if (emoteCardsToUpdate != null)
 136            {
 0137                emoteCardsToUpdate.AssignSlot(-1);
 0138                emoteCardsToUpdate.SetEmoteAsAssignedInSelectedSlot(false);
 139            }
 140
 0141            emoteSlotSelector.AssignEmoteIntoSlot(
 142                slotNumber,
 143                string.Empty,
 144                string.Empty,
 145                null,
 146                null,
 147                string.Empty);
 148
 0149            SetEmoteInfoPanelActive(false);
 150
 0151            if (notifyEvent)
 0152                onEmoteUnequipped?.Invoke(emoteId, slotNumber);
 0153        }
 154
 155        public void OpenEmoteInfoPanel(EmoteCardComponentModel emoteModel, Color backgroundColor, Transform anchorTransf
 156        {
 0157            emoteInfoPanel.SetModel(NFTItemInfo.Model.FromEmoteItem(emoteModel));
 0158            emoteInfoPanel.SetBackgroundColor(backgroundColor);
 0159            emoteInfoPanel.SetRarityName(emoteModel.rarity);
 0160            SetEmoteInfoPanelActive(true);
 0161            var emoteInfoPanelTransform = emoteInfoPanel.transform;
 0162            emoteInfoPanelTransform.SetParent(anchorTransform);
 0163            emoteInfoPanelTransform.localPosition = Vector3.zero;
 0164            emoteInfoPanel.sellButton.onClick.RemoveAllListeners();
 0165            emoteInfoPanel.sellButton.onClick.AddListener(() => onSellEmoteClicked?.Invoke(emoteModel.id));
 0166        }
 167
 0168        public void SetEmoteInfoPanelActive(bool isActive) { emoteInfoPanel.SetActive(isActive); }
 169
 0170        public EmoteCardComponentView GetEmoteCardById(string emoteId) { return GetAllEmoteCards().FirstOrDefault(x => x
 171
 0172        public void SetActive(bool isActive) { gameObject.SetActive(isActive); }
 173
 0174        public EmoteSlotCardComponentView GetSlot(int slotNumber) { return currentSlots.FirstOrDefault(x => x.model.slot
 175
 176        public void Refresh()
 177        {
 0178            RefreshControl();
 0179        }
 180
 181        public void RefreshEmotesGrid() =>
 0182            emotesGrid.RefreshControl();
 183
 184        internal void ClickOnEmote(string emoteId, string emoteName, int slotNumber, bool isAssignedInSelectedSlot)
 185        {
 0186            if (!isAssignedInSelectedSlot)
 0187                EquipEmote(emoteId, emoteName, slotNumber);
 188            else
 0189                UnequipEmote(emoteId, selectedSlot);
 190
 0191            SetEmoteInfoPanelActive(false);
 0192        }
 193
 0194        internal void OnEmoteSelected(string emoteId) { selectedCard = GetEmoteCardById(emoteId); }
 195
 196        internal void ConfigureEmotesPool()
 197        {
 0198            emoteCardsPool = PoolManager.i.GetPool(EMOTE_CARDS_POOL_NAME);
 0199            if (emoteCardsPool == null)
 200            {
 0201                emoteCardsPool = PoolManager.i.AddPool(
 202                    EMOTE_CARDS_POOL_NAME,
 203                    GameObject.Instantiate(emoteCardPrefab).gameObject,
 204                    maxPrewarmCount: EMOTE_CARDS_POOL_PREWARM,
 205                    isPersistent: true);
 206
 0207                emoteCardsPool.ForcePrewarm(forceActive: false);
 208            }
 0209        }
 210
 211        internal EmoteCardComponentView InstantiateAndConfigureEmoteCard(EmoteCardComponentModel emotesInfo)
 212        {
 0213            EmoteCardComponentView emoteGO = emoteCardsPool.Get().gameObject.GetComponent<EmoteCardComponentView>();
 0214            emoteGO.Configure(emotesInfo);
 0215            emoteGO.onMainClick.RemoveAllListeners();
 0216            emoteGO.onMainClick.AddListener(() => ClickOnEmote(emoteGO.model.id, emoteGO.model.name, selectedSlot, emote
 0217            emoteGO.onInfoClick.RemoveAllListeners();
 0218            emoteGO.onInfoClick.AddListener(() => OpenEmoteInfoPanel(
 219                emoteGO.model,
 220                emoteGO.rarityMark.gameObject.activeSelf ? emoteGO.rarityMark.color : Color.grey,
 221                emoteGO.emoteInfoAnchor));
 0222            emoteGO.onEmoteSelected -= OnEmoteSelected;
 0223            emoteGO.onEmoteSelected += OnEmoteSelected;
 224
 0225            return emoteGO;
 226        }
 227
 228        internal void OnSlotSelected(int slotNumber, string emoteId, bool playEmote)
 229        {
 0230            List<EmoteCardComponentView> currentEmoteCards = GetAllEmoteCards();
 0231            foreach (var existingEmoteCard in currentEmoteCards)
 232            {
 0233                existingEmoteCard.SetEmoteAsAssignedInSelectedSlot(existingEmoteCard.model.assignedSlot == slotNumber);
 234            }
 235
 0236            SetEmoteInfoPanelActive(false);
 0237            onSlotSelected?.Invoke(emoteId, slotNumber, playEmote);
 0238        }
 239
 240        internal List<EmoteCardComponentView> GetAllEmoteCards()
 241        {
 0242            return emotesGrid
 243                .GetItems()
 0244                .Select(x => x as EmoteCardComponentView)
 245                .ToList();
 246        }
 247
 248        internal static IEmotesCustomizationComponentView Create(string path = "EmotesCustomization/EmotesCustomizationS
 249        {
 0250            EmotesCustomizationComponentView emotesCustomizationComponentView = Instantiate(Resources.Load<GameObject>(p
 0251            emotesCustomizationComponentView.name = "_EmotesCustomizationSection";
 252
 0253            return emotesCustomizationComponentView;
 254        }
 255    }
 256}