< Summary

Class:DCL.EmotesCustomization.EmoteSlotSelectorComponentView
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/EmotesCustomization/EmoteSlotSelectorComponentView.cs
Covered lines:51
Uncovered lines:5
Coverable lines:56
Total lines:136
Line coverage:91% (51 of 56)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
Configure(...)0%2.032080%
RefreshControl()0%2.032080%
Dispose()0%110100%
SelectSlot(...)0%5.015091.67%
AssignEmoteIntoSlot(...)0%550100%
ConfigureSlotButtons()0%220100%
UnsubscribeSlotButtons()0%440100%
GetAllSlots()0%4.123050%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using UnityEngine;
 4using System.Linq;
 5
 6namespace DCL.EmotesCustomization
 7{
 8    public class EmoteSlotSelectorComponentView : BaseComponentView, IEmoteSlotSelectorComponentView, IComponentModelCon
 9    {
 10        [Header("Prefab References")]
 11        [SerializeField] internal GridContainerComponentView emotesSlots;
 12
 13        [Header("Configuration")]
 14        [SerializeField] internal EmoteSlotSelectorComponentModel model;
 15
 1016        public int selectedSlot => model.selectedSlot;
 17
 18        public event Action<int, string> onSlotSelected;
 19
 20        public override void Start()
 21        {
 2422            base.Start();
 23
 2424            ConfigureSlotButtons();
 2425        }
 26
 27        public void Configure(EmoteSlotSelectorComponentModel newModel)
 28        {
 129            if (model == newModel)
 030                return;
 31
 132            model = newModel;
 133            RefreshControl();
 134        }
 35
 36        public override void RefreshControl()
 37        {
 138            if (model == null)
 039                return;
 40
 141            SelectSlot(model.selectedSlot);
 142            emotesSlots.RefreshControl();
 143        }
 44
 45        public override void Dispose()
 46        {
 9747            base.Dispose();
 48
 9749            UnsubscribeSlotButtons();
 9750        }
 51
 52        public void SelectSlot(int slotNumber)
 53        {
 1154            model.selectedSlot = slotNumber;
 55
 1156            if (emotesSlots == null)
 057                return;
 58
 1159            List<EmoteSlotCardComponentView> currentSlots = GetAllSlots();
 24260            foreach (EmoteSlotCardComponentView slot in currentSlots)
 61            {
 11062                if (slot.model.slotNumber == slotNumber)
 63                {
 1064                    slot.SetEmoteAsSelected(true);
 1065                    onSlotSelected?.Invoke(slotNumber, slot.model.emoteId);
 66                }
 67                else
 68                {
 10069                    slot.SetEmoteAsSelected(false);
 70                }
 71            }
 1172        }
 73
 74        public void AssignEmoteIntoSlot(int slotNumber, string emoteId, string emoteName, Sprite pictureSprite, string p
 75        {
 1076            List<EmoteSlotCardComponentView> currentSlots = GetAllSlots();
 22077            foreach (EmoteSlotCardComponentView slot in currentSlots)
 78            {
 10079                if (slot.model.slotNumber == slotNumber)
 80                {
 981                    slot.SetEmoteName(emoteName);
 982                    if (pictureSprite != null)
 83                    {
 684                        slot.SetEmotePicture(pictureSprite);
 685                        slot.model.pictureUri = pictureUri;
 86                    }
 87                    else
 388                        slot.SetEmotePicture(pictureUri);
 989                    slot.SetEmoteId(emoteId);
 990                    slot.SetRarity(rarity);
 91                }
 9192                else if (slot.model.emoteId == emoteId)
 93                {
 3794                    slot.SetEmoteId(string.Empty);
 3795                    slot.SetEmoteName(string.Empty);
 3796                    slot.SetRarity(string.Empty);
 97                }
 98            }
 1099        }
 100
 101        internal void ConfigureSlotButtons()
 102        {
 27103            List<EmoteSlotCardComponentView> currentSlots = GetAllSlots();
 594104            foreach (EmoteSlotCardComponentView slot in currentSlots)
 105            {
 273106                slot.onClick.AddListener(() => SelectSlot(slot.model.slotNumber));
 107            }
 27108        }
 109
 110        internal void UnsubscribeSlotButtons()
 111        {
 100112            IEnumerable<EmoteSlotCardComponentView> currentSlots = emotesSlots
 113                .GetItems()
 1000114                .Select(x => x as EmoteSlotCardComponentView);
 115
 2200116            foreach (EmoteSlotCardComponentView slot in currentSlots)
 117            {
 1000118                slot.onClick.RemoveAllListeners();
 119            }
 100120        }
 121
 122        internal List<EmoteSlotCardComponentView> GetAllSlots()
 123        {
 1461124            if (emotesSlots == null)
 125            {
 0126                Debug.LogError("EmotesSlotSelectorComponentView: emotesSlots are accessed before serialized reference wa
 0127                return new List<EmoteSlotCardComponentView>();
 128            }
 129
 1461130            return emotesSlots
 131                .GetItems()
 14610132                .Select(x => x as EmoteSlotCardComponentView)
 133                .ToList();
 134        }
 135    }
 136}