< 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:0
Uncovered lines:56
Coverable lines:56
Total lines:137
Line coverage:0% (0 of 56)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:10
Method coverage:0% (0 of 10)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%2100%
Configure(...)0%6200%
RefreshControl()0%6200%
Dispose()0%2100%
SelectSlot(...)0%30500%
AssignEmoteIntoSlot(...)0%30500%
ConfigureSlotButtons()0%6200%
UnsubscribeSlotButtons()0%20400%
GetAllSlots()0%12300%

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
 016        public int selectedSlot => model.selectedSlot;
 17
 18        public event Action<int, string, bool> onSlotSelected;
 19
 20        public void Start()
 21        {
 022            ConfigureSlotButtons();
 023        }
 24
 25        public void Configure(EmoteSlotSelectorComponentModel newModel)
 26        {
 027            if (model == newModel)
 028                return;
 29
 030            model = newModel;
 031            RefreshControl();
 032        }
 33
 34        public override void RefreshControl()
 35        {
 036            if (model == null)
 037                return;
 38
 039            SelectSlot(model.selectedSlot);
 040            emotesSlots.RefreshControl();
 041        }
 42
 43        public override void Dispose()
 44        {
 045            base.Dispose();
 46
 047            UnsubscribeSlotButtons();
 048        }
 49
 50        public void SelectSlot(int slotNumber)
 51        {
 052            bool isInitialized = model.selectedSlot < 0;
 53
 054            model.selectedSlot = slotNumber;
 55
 056            if (emotesSlots == null)
 057                return;
 58
 059            List<EmoteSlotCardComponentView> currentSlots = GetAllSlots();
 060            foreach (EmoteSlotCardComponentView slot in currentSlots)
 61            {
 062                if (slot.model.slotNumber == slotNumber)
 63                {
 064                    slot.SetEmoteAsSelected(true);
 65
 066                    onSlotSelected?.Invoke(slotNumber, slot.model.emoteId, !isInitialized);
 67                }
 68                else
 69                {
 070                    slot.SetEmoteAsSelected(false);
 71                }
 72            }
 073        }
 74
 75        public void AssignEmoteIntoSlot(int slotNumber, string emoteId, string emoteName, Sprite pictureSprite, string p
 76        {
 077            List<EmoteSlotCardComponentView> currentSlots = GetAllSlots();
 078            foreach (EmoteSlotCardComponentView slot in currentSlots)
 79            {
 080                if (slot.model.slotNumber == slotNumber)
 81                {
 082                    slot.SetEmoteName(emoteName);
 083                    if (pictureSprite != null)
 84                    {
 085                        slot.SetEmotePicture(pictureSprite);
 086                        slot.model.pictureUri = pictureUri;
 87                    }
 88                    else
 089                        slot.SetEmotePicture(pictureUri);
 090                    slot.SetEmoteId(emoteId);
 091                    slot.SetRarity(rarity);
 92                }
 093                else if (slot.model.emoteId == emoteId)
 94                {
 095                    slot.SetEmoteId(string.Empty);
 096                    slot.SetEmoteName(string.Empty);
 097                    slot.SetRarity(string.Empty);
 98                }
 99            }
 0100        }
 101
 102        internal void ConfigureSlotButtons()
 103        {
 0104            List<EmoteSlotCardComponentView> currentSlots = GetAllSlots();
 0105            foreach (EmoteSlotCardComponentView slot in currentSlots)
 106            {
 0107                slot.onClick.AddListener(() => SelectSlot(slot.model.slotNumber));
 108            }
 0109        }
 110
 111        internal void UnsubscribeSlotButtons()
 112        {
 0113            IEnumerable<EmoteSlotCardComponentView> currentSlots = emotesSlots
 114                .GetItems()
 0115                .Select(x => x as EmoteSlotCardComponentView);
 116
 0117            foreach (EmoteSlotCardComponentView slot in currentSlots)
 118            {
 0119                slot.onClick.RemoveAllListeners();
 120            }
 0121        }
 122
 123        internal List<EmoteSlotCardComponentView> GetAllSlots()
 124        {
 0125            if (emotesSlots == null)
 126            {
 0127                Debug.LogError("EmotesSlotSelectorComponentView: emotesSlots are accessed before serialized reference wa
 0128                return new List<EmoteSlotCardComponentView>();
 129            }
 130
 0131            return emotesSlots
 132                .GetItems()
 0133                .Select(x => x as EmoteSlotCardComponentView)
 134                .ToList();
 135        }
 136    }
 137}