< Summary

Class:FriendEntryBase
Assembly:FriendsHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/Entries/FriendEntryBase.cs
Covered lines:24
Uncovered lines:5
Coverable lines:29
Total lines:94
Line coverage:82.7% (24 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FriendEntryBase()0%110100%
Awake()0%110100%
OnPointerEnter(...)0%6200%
OnPointerExit(...)0%110100%
OnEnable()0%220100%
OnDisable()0%220100%
OnDestroy()0%220100%
Populate(...)0%660100%
OnAvatarImageChange(...)0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/FriendsHUD/Scripts/Entries/FriendEntryBase.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using DCL.Helpers;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.EventSystems;
 7using UnityEngine.UI;
 8
 9public class FriendEntryBase : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
 10{
 11    public class Model
 12    {
 13        public PresenceStatus status;
 14        public string userName;
 15        public Vector2 coords;
 16        public string realm;
 17        public string realmServerName;
 18        public string realmLayerName;
 19        public ILazyTextureObserver avatarSnapshotObserver;
 20        public bool blocked;
 21    }
 22
 8123    public Model model { get; private set; } = new Model();
 24    [System.NonSerialized] public string userId;
 25
 26    public Image playerBlockedImage;
 27    public Transform menuPositionReference;
 28
 29    [SerializeField] protected internal TextMeshProUGUI playerNameText;
 30    [SerializeField] protected internal RawImage playerImage;
 31    [SerializeField] protected internal Button menuButton;
 32    [SerializeField] protected internal Image backgroundImage;
 33    [SerializeField] protected internal Sprite hoveredBackgroundSprite;
 34    [SerializeField] protected internal AudioEvent audioEventHover;
 35    protected internal Sprite unhoveredBackgroundSprite;
 36
 37    public event System.Action<FriendEntryBase> OnMenuToggle;
 38
 39    public virtual void Awake()
 40    {
 7941        unhoveredBackgroundSprite = backgroundImage.sprite;
 7942        menuButton.onClick.RemoveAllListeners();
 8543        menuButton.onClick.AddListener(() => OnMenuToggle?.Invoke(this));
 7944    }
 45
 46    public void OnPointerEnter(PointerEventData eventData)
 47    {
 048        backgroundImage.sprite = hoveredBackgroundSprite;
 049        menuButton.gameObject.SetActive(true);
 50
 051        if (audioEventHover != null)
 052            audioEventHover.Play(true);
 053    }
 54
 55    public void OnPointerExit(PointerEventData eventData)
 56    {
 12557        backgroundImage.sprite = unhoveredBackgroundSprite;
 12558        menuButton.gameObject.SetActive(false);
 12559    }
 60
 61    private void OnEnable()
 62    {
 12563        model.avatarSnapshotObserver?.AddListener(OnAvatarImageChange);
 1164    }
 65
 66    protected virtual void OnDisable()
 67    {
 12568        model.avatarSnapshotObserver?.RemoveListener(OnAvatarImageChange);
 12569        OnPointerExit(null);
 12570    }
 71
 72    protected void OnDestroy()
 73    {
 7974        model.avatarSnapshotObserver?.RemoveListener(OnAvatarImageChange);
 1675    }
 76
 77    public virtual void Populate(Model model)
 78    {
 4079        if (playerNameText.text != model.userName)
 3980            playerNameText.text = model.userName;
 81
 4082        playerBlockedImage.enabled = model.blocked;
 83
 4084        if (this.model != null && isActiveAndEnabled)
 85        {
 3986            this.model.avatarSnapshotObserver?.RemoveListener(OnAvatarImageChange);
 3987            model.avatarSnapshotObserver?.AddListener(OnAvatarImageChange);
 88        }
 89
 4090        this.model = model;
 4091    }
 92
 693    private void OnAvatarImageChange(Texture2D texture) { playerImage.texture = texture; }
 94}