< Summary

Class:NotificationsController
Assembly:NotificationsController
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/NotificationsController/NotificationsController.cs
Covered lines:8
Uncovered lines:23
Coverable lines:31
Total lines:76
Line coverage:25.8% (8 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
Initialize(...)0%2100%
Dispose()0%110100%
ShowNotificationFromJson(...)0%6200%
ShowNotification(...)0%4.123050%
ShowNotification(...)0%3.143075%
DismissAllNotifications(...)0%2.52050%
ShowWelcomeNotification()0%42600%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/NotificationsController/NotificationsController.cs

#LineLine coverage
 1using UnityEngine;
 2
 3public class NotificationsController : MonoBehaviour
 4{
 5    const int NOTIFICATION_DURATION = 5;
 6
 07    public static NotificationsController i { get; private set; }
 8    public static bool disableWelcomeNotification = false;
 9
 010    public bool allowNotifications { get; set; }
 11
 20612    void Awake() { i = this; }
 13
 14    NotificationHUDController controller;
 15
 16    public void Initialize(NotificationHUDController controller)
 17    {
 018        this.controller = controller;
 019        allowNotifications = true;
 020    }
 21
 2022    public void Dispose() { controller.Dispose(); }
 23
 24    public void ShowNotificationFromJson(string notificationJson)
 25    {
 026        if (!allowNotifications)
 027            return;
 28
 029        Notification.Model model = JsonUtility.FromJson<Notification.Model>(notificationJson);
 030        ShowNotification(model);
 031    }
 32
 33    public void ShowNotification(Notification.Model notification)
 34    {
 435        if (!allowNotifications)
 436            return;
 37
 038        controller?.ShowNotification(notification);
 039    }
 40
 41    public void ShowNotification(Notification notification)
 42    {
 243        if (!allowNotifications)
 044            return;
 45
 246        controller?.ShowNotification(notification);
 247    }
 48
 549    public void DismissAllNotifications(string groupID) { controller?.DismissAllNotifications(groupID); }
 50
 51    public void ShowWelcomeNotification()
 52    {
 053        if (!allowNotifications || disableWelcomeNotification)
 054            return;
 55
 56        //TODO(Brian): This should be triggered entirely by kernel
 057        string notificationText = $"Welcome, {UserProfile.GetOwnUserProfile().userName}!";
 058        Vector2Int currentCoords = CommonScriptableObjects.playerCoords.Get();
 059        string parcelName = MinimapMetadata.GetMetadata().GetSceneInfo(currentCoords.x, currentCoords.y)?.name;
 60
 061        if (!string.IsNullOrEmpty(parcelName))
 62        {
 063            notificationText += $" You are in {parcelName} {currentCoords.x}, {currentCoords.y}";
 64        }
 65
 066        Notification.Model model = new Notification.Model()
 67        {
 68            message = notificationText,
 69            scene = "",
 70            type = NotificationFactory.Type.GENERIC_WITHOUT_BUTTON,
 71            timer = NOTIFICATION_DURATION
 72        };
 73
 074        controller.ShowNotification(model);
 075    }
 76}