< Summary

Class:DCL.EmotesCustomization.EmoteCardComponentView
Assembly:AvatarEditorHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/AvatarEditorHUD/Scripts/EmotesCustomization/EmoteCardComponentView.cs
Covered lines:118
Uncovered lines:16
Coverable lines:134
Total lines:287
Line coverage:88% (118 of 134)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmoteCardComponentView()0%110100%
Awake()0%330100%
Configure(...)0%2.032080%
RefreshControl()0%44094.44%
OnEnable()0%110100%
OnFocus()0%220100%
OnLoseFocus()0%220100%
Dispose()0%220100%
SetEmoteId(...)0%3.583060%
SetEmoteName(...)0%2.032080%
SetEmoteDescription(...)0%2100%
SetEmotePicture(...)0%4.054085.71%
SetEmotePicture(...)0%5.25080%
SetEmoteAsAssignedInSelectedSlot(...)0%110100%
AssignSlot(...)0%2.022083.33%
UnassignSlot()0%110100%
SetEmoteAsSelected(...)0%550100%
SetRarity(...)0%3.033085.71%
SetIsInL2(...)0%2100%
SetIsCollectible(...)0%110100%
SetAsLoading(...)0%330100%
RefreshVisualCardStatus()0%110100%
RefreshAssignedSlotTextVisibility()0%220100%
RefreshSelectionFrameVisibility()0%440100%
RefreshCardButtonsVisibility()0%220100%
OnEmoteImageLoaded(...)0%220100%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7
 8namespace DCL.EmotesCustomization
 9{
 10    public class EmoteCardComponentView : BaseComponentView, IEmoteCardComponentView, IComponentModelConfig<EmoteCardCom
 11    {
 112        internal static readonly int ON_SELECTED_CARD_COMPONENT_BOOL = Animator.StringToHash("OnSelected");
 13
 14        [Header("Prefab References")]
 15        [SerializeField] internal ImageComponentView emoteImage;
 16        [SerializeField] internal GameObject emoteNameContainer;
 17        [SerializeField] internal TMP_Text emoteNameText;
 18        [SerializeField] internal TMP_Text assignedSlotNumberText;
 19        [SerializeField] internal ButtonComponentView mainButton;
 20        [SerializeField] internal ButtonComponentView infoButton;
 21        [SerializeField] internal GameObject cardSelectionFrame;
 22        [SerializeField] internal Animator selectionAnimator;
 23        [SerializeField] internal Image rarityMark;
 24        [SerializeField] internal Transform emoteInfoAnchor;
 25        [SerializeField] internal GameObject loadingSpinnerGO;
 26
 27        [Header("Configuration")]
 28        [SerializeField] internal Sprite defaultEmotePicture;
 29        [SerializeField] internal Sprite nonEmoteAssignedPicture;
 30        [SerializeField] internal List<EmoteRarity> rarityColors;
 31        [SerializeField] internal EmoteCardComponentModel model;
 32
 033        public Button.ButtonClickedEvent onMainClick => mainButton?.onClick;
 034        public Button.ButtonClickedEvent onInfoClick => infoButton?.onClick;
 35
 36        public event Action<string> onEmoteSelected;
 37
 38        public override void Awake()
 39        {
 8540            base.Awake();
 41
 8542            if (emoteImage != null)
 8443                emoteImage.OnLoaded += OnEmoteImageLoaded;
 44
 8545            if (cardSelectionFrame != null)
 8446                cardSelectionFrame.SetActive(false);
 8547        }
 48
 49        public void Configure(EmoteCardComponentModel newModel)
 50        {
 2051            if (model == newModel)
 052                return;
 53
 2054            model = newModel;
 2055            RefreshControl();
 2056        }
 57
 58        public override void RefreshControl()
 59        {
 12460            if (model == null)
 161                return;
 62
 12363            SetEmoteId(model.id);
 12364            SetEmoteName(model.name);
 12365            SetEmoteDescription(model.description);
 66
 12367            if (model.pictureSprite != null)
 11668                SetEmotePicture(model.pictureSprite);
 769            else if (!string.IsNullOrEmpty(model.pictureUri))
 770                SetEmotePicture(model.pictureUri);
 71            else
 072                OnEmoteImageLoaded(null);
 73
 12374            SetEmoteAsAssignedInSelectedSlot(model.isAssignedInSelectedSlot);
 12375            AssignSlot(model.assignedSlot);
 12376            SetEmoteAsSelected(model.isSelected);
 12377            SetRarity(model.rarity);
 12378            SetIsInL2(model.isInL2);
 12379            SetIsCollectible(model.isCollectible);
 12380            SetAsLoading(model.isLoading);
 12381        }
 82
 83        public override void OnEnable()
 84        {
 10485            base.OnEnable();
 86
 10487            RefreshControl();
 10488        }
 89
 90        public override void OnFocus()
 91        {
 192            base.OnFocus();
 93
 194            if (emoteNameContainer != null)
 195                emoteNameContainer.SetActive(true);
 96
 197            SetEmoteAsSelected(true);
 198        }
 99
 100        public override void OnLoseFocus()
 101        {
 105102            base.OnLoseFocus();
 103
 105104            if (emoteNameContainer != null)
 104105                emoteNameContainer.SetActive(false);
 106
 105107            SetEmoteAsSelected(false);
 105108        }
 109
 110        public override void Dispose()
 111        {
 118112            base.Dispose();
 113
 118114            if (emoteImage != null)
 115            {
 117116                emoteImage.OnLoaded -= OnEmoteImageLoaded;
 117117                emoteImage.Dispose();
 118            }
 118119        }
 120
 121        public void SetEmoteId(string id)
 122        {
 124123            model.id = id;
 124
 124125            if (string.IsNullOrEmpty(id))
 126            {
 0127                if (nonEmoteAssignedPicture != null)
 0128                    SetEmotePicture(nonEmoteAssignedPicture);
 129            }
 124130        }
 131
 132        public void SetEmoteName(string name)
 133        {
 124134            model.name = name;
 135
 124136            if (emoteNameText == null)
 0137                return;
 138
 124139            emoteNameText.text = name;
 124140        }
 141
 142        public void SetEmoteDescription(string description)
 143        {
 0144            model.description = description;
 0145        }
 146
 147        public void SetEmotePicture(Sprite sprite)
 148        {
 121149            if (sprite == null && defaultEmotePicture != null)
 2150                sprite = defaultEmotePicture;
 151
 121152            model.pictureSprite = sprite;
 153
 121154            if (emoteImage == null)
 0155                return;
 156
 121157            emoteImage.SetImage(sprite);
 121158        }
 159
 160        public void SetEmotePicture(string uri)
 161        {
 9162            if (string.IsNullOrEmpty(uri) && defaultEmotePicture != null)
 163            {
 1164                SetEmotePicture(defaultEmotePicture);
 1165                return;
 166            }
 167
 8168            model.pictureUri = uri;
 169
 8170            if (!Application.isPlaying)
 0171                return;
 172
 8173            if (emoteImage == null)
 0174                return;
 175
 8176            emoteImage.SetImage(uri);
 8177        }
 178
 179        public void SetEmoteAsAssignedInSelectedSlot(bool isAssigned)
 180        {
 139181            model.isAssignedInSelectedSlot = isAssigned;
 182
 139183            RefreshVisualCardStatus();
 139184        }
 185
 186        public void AssignSlot(int slotNumber)
 187        {
 135188            model.assignedSlot = slotNumber;
 189
 135190            if (assignedSlotNumberText == null)
 0191                return;
 192
 135193            assignedSlotNumberText.text = slotNumber.ToString();
 194
 135195            RefreshVisualCardStatus();
 135196        }
 197
 2198        public void UnassignSlot() { AssignSlot(-1); }
 199
 200        public void SetEmoteAsSelected(bool isSelected)
 201        {
 231202            model.isSelected = isSelected;
 203
 231204            if (selectionAnimator != null)
 230205                selectionAnimator.SetBool(ON_SELECTED_CARD_COMPONENT_BOOL, isSelected);
 206
 231207            RefreshVisualCardStatus();
 208
 231209            if (isSelected)
 84210                onEmoteSelected?.Invoke(model.id);
 211            else
 147212                onEmoteSelected?.Invoke(null);
 56213        }
 214
 215        public void SetRarity(string rarity)
 216        {
 125217            model.rarity = rarity;
 218
 125219            if (rarityMark == null)
 0220                return;
 221
 294222            EmoteRarity emoteRarity = rarityColors.FirstOrDefault(x => x.rarity == rarity);
 125223            rarityMark.gameObject.SetActive(emoteRarity != null);
 125224            rarityMark.color = emoteRarity != null ? emoteRarity.markColor : Color.white;
 125225        }
 226
 227        public void SetIsInL2(bool isInL2)
 228        {
 0229            model.isInL2 = isInL2;
 0230        }
 231
 232        public void SetIsCollectible(bool isCollectible)
 233        {
 125234            model.isCollectible = isCollectible;
 235
 125236            RefreshVisualCardStatus();
 125237        }
 238
 239        public void SetAsLoading(bool isLoading)
 240        {
 126241            model.isLoading = isLoading;
 242
 126243            if (loadingSpinnerGO != null)
 125244                loadingSpinnerGO.SetActive(isLoading);
 245
 126246            if (mainButton != null)
 125247                mainButton.gameObject.SetActive(!isLoading);
 126248        }
 249
 250        internal void RefreshVisualCardStatus()
 251        {
 630252            RefreshAssignedSlotTextVisibility();
 630253            RefreshSelectionFrameVisibility();
 630254            RefreshCardButtonsVisibility();
 630255        }
 256
 257        internal void RefreshAssignedSlotTextVisibility()
 258        {
 632259            if (assignedSlotNumberText == null)
 1260                return;
 261
 631262            assignedSlotNumberText.gameObject.SetActive(model.assignedSlot >= 0);
 631263        }
 264
 265        internal void RefreshSelectionFrameVisibility()
 266        {
 632267            if (cardSelectionFrame == null)
 1268                return;
 269
 631270            cardSelectionFrame.SetActive(model.isSelected || model.isAssignedInSelectedSlot);
 631271        }
 272
 273        internal void RefreshCardButtonsVisibility()
 274        {
 632275            if (infoButton != null)
 631276                infoButton.gameObject.SetActive(model.isCollectible);
 632277        }
 278
 279        internal void OnEmoteImageLoaded(Sprite sprite)
 280        {
 2281            if (sprite != null)
 1282                SetEmotePicture(sprite);
 283            else
 1284                SetEmotePicture(sprite: null);
 1285        }
 286    }
 287}