< Summary

Class:DCL.EmotesWheel.EmotesWheelView
Assembly:EmotesWheelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmotesWheelHUD/EmotesWheelView.cs
Covered lines:20
Uncovered lines:28
Coverable lines:48
Total lines:143
Line coverage:41.6% (20 of 48)
Covered branches:0
Total branches:0
Covered methods:5
Total methods:9
Method coverage:55.5% (5 of 9)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Create()0%110100%
Awake()0%220100%
SetVisiblity(...)0%3.033085.71%
SetEmotes(...)0%12300%
SetupEmoteWheelSlot(...)0%30500%
OnSlotHover(...)0%2100%
Close()0%6200%
OnDestroy()0%220100%
CleanUp()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/EmotesWheelHUD/EmotesWheelView.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using TMPro;
 5using UnityEngine;
 6
 7namespace DCL.EmotesWheel
 8{
 9    public class EmotesWheelView : MonoBehaviour
 10    {
 11        public class EmoteSlotData
 12        {
 13            public string emoteId;
 14            public WearableItem emoteItem;
 15            public Sprite thumbnailSprite;
 16        }
 17
 18        [Serializable]
 19        internal class RarityColor
 20        {
 21            public string rarity;
 22            public Color markColor;
 23        }
 24
 25        private const string PATH = "EmotesWheelHUD";
 26
 27
 28        public event Action<string> onEmoteClicked;
 29        public event Action OnClose;
 30        public event Action OnCustomizeClicked;
 31
 32        [SerializeField] internal Sprite nonAssignedEmoteSprite;
 33        [SerializeField] internal EmoteWheelSlot[] emoteButtons;
 34        [SerializeField] internal Button_OnPointerDown[] closeButtons;
 35        [SerializeField] internal ButtonComponentView openCustomizeButton;
 36        [SerializeField] internal TMP_Text selectedEmoteName;
 37        [SerializeField] internal List<RarityColor> rarityColors;
 38        [SerializeField] internal GameObject customizeTitle;
 39
 40        private HUDCanvasCameraModeController hudCanvasCameraModeController;
 41
 342        public static EmotesWheelView Create() { return Instantiate(Resources.Load<GameObject>(PATH)).GetComponent<Emote
 43
 44        private void Awake()
 45        {
 1846            for (int i = 0; i < closeButtons.Length; i++)
 47            {
 648                closeButtons[i].onPointerDown += Close;
 49            }
 50
 351            openCustomizeButton.onClick.AddListener(() =>
 52            {
 053                OnCustomizeClicked?.Invoke();
 054            });
 55
 356            selectedEmoteName.text = string.Empty;
 357            hudCanvasCameraModeController = new HUDCanvasCameraModeController(GetComponent<Canvas>(), DataStore.i.camera
 358        }
 59
 60        public void SetVisiblity(bool visible)
 61        {
 562            if (visible == gameObject.activeSelf)
 063                return;
 64
 565            gameObject.SetActive(visible);
 566            if (visible)
 67            {
 168                AudioScriptableObjects.dialogOpen.Play(true);
 69            }
 70            else
 71            {
 472                AudioScriptableObjects.dialogClose.Play(true);
 73            }
 474        }
 75
 76        public List<EmoteWheelSlot> SetEmotes(List<EmoteSlotData> emotes)
 77        {
 078            for (int i = 0; i < emotes.Count; i++)
 79            {
 080                EmoteSlotData equippedEmote = emotes[i];
 81
 082                if (i >= emoteButtons.Length) continue;
 83
 084                EmoteWheelSlot emoteWheelSlot = emoteButtons[i];
 085                SetupEmoteWheelSlot(emoteWheelSlot, equippedEmote);
 86            }
 87
 088            return emoteButtons.ToList();
 89        }
 90
 91        public void SetupEmoteWheelSlot(EmoteWheelSlot emoteWheelSlot, EmoteSlotData slotData)
 92        {
 093            emoteWheelSlot.button.onClick.RemoveAllListeners();
 094            emoteWheelSlot.onSlotHover -= OnSlotHover;
 095            emoteWheelSlot.onSlotHover += OnSlotHover;
 96
 097            if (slotData is { emoteItem: not null })
 98            {
 099                emoteWheelSlot.button.onClick.AddListener(() => onEmoteClicked?.Invoke(slotData.emoteItem.id));
 100
 0101                if (slotData.thumbnailSprite != null)
 0102                    emoteWheelSlot.SetImage(slotData.thumbnailSprite);
 103                else
 0104                    emoteWheelSlot.SetImage(slotData.emoteItem.ComposeThumbnailUrl());
 105
 0106                emoteWheelSlot.SetId(slotData.emoteItem.id);
 0107                emoteWheelSlot.SetName(slotData.emoteItem.GetName());
 108
 0109                RarityColor rarityColor = rarityColors.FirstOrDefault(x => x.rarity == slotData.emoteItem.rarity);
 0110                emoteWheelSlot.SetRarity(
 111                    rarityColor != null,
 112                    rarityColor != null ? rarityColor.markColor : Color.white);
 113            }
 114            else
 115            {
 0116                emoteWheelSlot.SetImage(nonAssignedEmoteSprite);
 0117                emoteWheelSlot.SetId(string.Empty);
 0118                emoteWheelSlot.SetName(string.Empty);
 0119                emoteWheelSlot.SetRarity(false, Color.white);
 120            }
 0121        }
 122
 0123        private void OnSlotHover(string emoteName) { selectedEmoteName.text = emoteName; }
 124
 0125        private void Close() { OnClose?.Invoke(); }
 126
 127        public void OnDestroy()
 128        {
 3129            CleanUp();
 3130            hudCanvasCameraModeController?.Dispose();
 3131        }
 132
 133        public void CleanUp()
 134        {
 36135            for (int i = 0; i < closeButtons.Length; i++)
 136            {
 12137                closeButtons[i].onPointerDown -= Close;
 138            }
 139
 6140            openCustomizeButton.onClick.RemoveAllListeners();
 6141        }
 142    }
 143}