< Summary

Class:UnreadWorldNotificationBadge
Assembly:NotificationBadge
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/UnreadWorldNotificationBadge.cs
Covered lines:22
Uncovered lines:1
Coverable lines:23
Total lines:68
Line coverage:95.6% (22 of 23)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UnreadWorldNotificationBadge()0%110100%
Start()0%110100%
OnDestroy()0%220100%
OnEnable()0%110100%
Initialize(...)0%110100%
UpdateTotalUnseenMessages(...)0%110100%
UpdateTotalUnseenMessages()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/NotificationBadge/UnreadWorldNotificationBadge.cs

#LineLine coverage
 1using TMPro;
 2using UnityEngine;
 3
 4/// <summary>
 5/// Shows the number of unread messages from a the world chat.
 6/// </summary>
 7public class UnreadWorldNotificationBadge : MonoBehaviour
 8{
 9    public TextMeshProUGUI notificationText;
 10    public GameObject notificationContainer;
 1011    public int maxNumberToShow = 9;
 12
 13    private int currentUnreadMessagesValue;
 14    private IChatController chatController;
 15
 16    public int CurrentUnreadMessages
 17    {
 018        get => currentUnreadMessagesValue;
 19        set
 20        {
 1821            currentUnreadMessagesValue = value;
 1822            if (currentUnreadMessagesValue > 0)
 23            {
 1224                notificationContainer.SetActive(true);
 1225                notificationText.text = currentUnreadMessagesValue <= maxNumberToShow
 26                    ? currentUnreadMessagesValue.ToString()
 27                    : $"+{maxNumberToShow}";
 1228            }
 29            else
 30            {
 631                notificationContainer.SetActive(false);
 32            }
 633        }
 34    }
 35
 36    private void Start()
 37    {
 238        Initialize(ChatController.i);
 239    }
 40
 41    private void OnDestroy()
 42    {
 743        if (chatController != null)
 544            chatController.OnTotalUnseenMessagesUpdated -= UpdateTotalUnseenMessages;
 745    }
 46
 947    private void OnEnable() => UpdateTotalUnseenMessages();
 48
 49    /// <summary>
 50    /// Prepares the notification badge for listening to the world chat
 51    /// </summary>
 52    /// <param name="chatController">Chat Controlled to be listened</param>
 53    public void Initialize(IChatController chatController)
 54    {
 555        this.chatController = chatController;
 556        chatController.OnTotalUnseenMessagesUpdated += UpdateTotalUnseenMessages;
 557        UpdateTotalUnseenMessages();
 558    }
 59
 60    private void UpdateTotalUnseenMessages(int totalUnseenMessages) =>
 1361        CurrentUnreadMessages = totalUnseenMessages;
 62
 63    private void UpdateTotalUnseenMessages()
 64    {
 2365        if (chatController == null) return;
 566        CurrentUnreadMessages = chatController.TotalUnseenMessages;
 567    }
 68}