< Summary

Class:DCL.Huds.QuestsTracker.QuestsNotificationsController
Assembly:QuestsTrackerHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/QuestsNotificationsController.cs
Covered lines:26
Uncovered lines:14
Coverable lines:40
Total lines:92
Line coverage:65% (26 of 40)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
QuestsNotificationsController()0%110100%
QuestsNotificationsController()0%110100%
Create()0%2100%
Awake()0%110100%
ShowQuestCompleted(...)0%110100%
ShowRewardObtained(...)0%2100%
SetVisibility(...)0%2100%
Dispose()0%6200%
ClearAllNotifications()0%3.033085.71%
OnDestroy()0%110100%
ProcessSectionsNotificationQueue()0%550100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/QuestsNotificationsController.cs

#LineLine coverage
 1using System.Collections;
 2using System.Collections.Generic;
 3using DCL.Huds.QuestsTracker;
 4using UnityEngine;
 5
 6namespace DCL.Huds.QuestsTracker
 7{
 8    public class QuestsNotificationsController : MonoBehaviour
 9    {
 3310        internal static float NOTIFICATIONS_SEPARATION { get; set; } = 0.5f;
 511        public static float DEFAULT_NOTIFICATION_DURATION { get; set; } = 2.5f;
 12
 1513        internal readonly Queue<IQuestNotification> notificationsQueue = new Queue<IQuestNotification>();
 14        private IQuestNotification currentNotification;
 15
 16        [SerializeField] private GameObject questCompletedPrefab;
 17        [SerializeField] private GameObject rewardObtainedPrefab;
 18        private bool isDestroyed = false;
 19
 20        internal static QuestsNotificationsController Create()
 21        {
 022            QuestsNotificationsController view = Instantiate(Resources.Load<GameObject>("QuestsNotificationsHUD")).GetCo
 23#if UNITY_EDITOR
 024            view.gameObject.name = "_QuestsNotificationsHUDView";
 25#endif
 026            return view;
 27        }
 28
 2829        private void Awake() { StartCoroutine(ProcessSectionsNotificationQueue()); }
 30
 31        public void ShowQuestCompleted(QuestModel quest)
 32        {
 333            var questNotification = Instantiate(questCompletedPrefab, transform).GetComponent<QuestNotification_QuestCom
 334            questNotification.Populate(quest);
 335            questNotification.gameObject.SetActive(false);
 336            notificationsQueue.Enqueue(questNotification);
 337        }
 38
 39        public void ShowRewardObtained(QuestReward reward)
 40        {
 041            var questNotification = Instantiate(rewardObtainedPrefab, transform).GetComponent<QuestNotification_RewardOb
 042            questNotification.Populate(reward);
 043            questNotification.gameObject.SetActive(false);
 044            notificationsQueue.Enqueue(questNotification);
 045        }
 46
 047        public void SetVisibility(bool visible) { gameObject.SetActive(visible); }
 48
 49        public void Dispose()
 50        {
 051            if (isDestroyed)
 052                return;
 53
 054            Destroy(gameObject);
 055        }
 56
 57        public void ClearAllNotifications()
 58        {
 3059            foreach ( var noti in notificationsQueue )
 60            {
 161                noti.Dispose();
 62            }
 63
 1464            if ( currentNotification != null )
 065                currentNotification.Dispose();
 1466        }
 67
 68        private void OnDestroy()
 69        {
 1470            ClearAllNotifications();
 1471            isDestroyed = true;
 1472        }
 73
 74        private IEnumerator ProcessSectionsNotificationQueue()
 75        {
 1676            while (true)
 77            {
 3078                if (notificationsQueue.Count > 0)
 79                {
 280                    IQuestNotification notification = notificationsQueue.Dequeue();
 281                    currentNotification = notification;
 282                    notification.Show();
 283                    yield return notification.Waiter();
 284                    notification.Dispose();
 285                    currentNotification = null;
 286                }
 87
 3088                yield return WaitForSecondsCache.Get(NOTIFICATIONS_SEPARATION);
 89            }
 90        }
 91    }
 92}