< Summary

Class:TeleportPromptHUDController
Assembly:TeleportPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TeleportPromptHUD/TeleportPromptHUDController.cs
Covered lines:24
Uncovered lines:31
Coverable lines:55
Total lines:142
Line coverage:43.6% (24 of 55)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TeleportPromptHUDController()0%110100%
SetVisibility(...)0%4.254075%
RequestTeleport(...)0%6.975057.14%
Dispose()0%220100%
SetSceneEvent()0%56700%
OnTeleportPressed()0%56700%
TeleportData()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TeleportPromptHUD/TeleportPromptHUDController.cs

#LineLine coverage
 1using UnityEngine;
 2using System;
 3using DCL.Helpers;
 4using DCL.Interface;
 5
 6public class TeleportPromptHUDController : IHUD
 7{
 8    const string TELEPORT_COMMAND_MAGIC = "magic";
 9    const string TELEPORT_COMMAND_CROWD = "crowd";
 10
 11    const string EVENT_STRING_LIVE = "Current event";
 12    const string EVENT_STRING_TODAY = "Today @ {0:HH:mm}";
 13
 014    internal TeleportPromptHUDView view { get; private set; }
 15
 16    TeleportData teleportData;
 17
 318    public TeleportPromptHUDController()
 19    {
 320        view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("TeleportPromptHUD")).GetComponent<TeleportProm
 321        view.name = "_TeleportPromptHUD";
 322        view.content.SetActive(false);
 323        view.OnTeleportEvent += OnTeleportPressed;
 324    }
 25
 26    public void SetVisibility(bool visible)
 27    {
 228        if (view.contentAnimator.isVisible && !visible)
 29        {
 030            view.contentAnimator.Hide();
 031        }
 232        else if (!view.contentAnimator.isVisible && visible)
 33        {
 234            view.content.SetActive(true);
 235            view.contentAnimator.Show();
 36
 237            AudioScriptableObjects.fadeIn.Play(true);
 38        }
 239    }
 40
 41    public void RequestTeleport(string teleportDataJson)
 42    {
 143        if (view.contentAnimator.isVisible)
 044            return;
 45
 146        Utils.UnlockCursor();
 47
 148        view.Reset();
 149        SetVisibility(true);
 50
 151        teleportData = Utils.SafeFromJson<TeleportData>(teleportDataJson);
 52
 153        switch (teleportData.destination)
 54        {
 55            case TELEPORT_COMMAND_MAGIC:
 156                view.ShowTeleportToMagic();
 157                break;
 58            case TELEPORT_COMMAND_CROWD:
 059                view.ShowTeleportToCrowd();
 060                break;
 61            default:
 062                view.ShowTeleportToCoords(teleportData.destination,
 63                    teleportData.sceneData.name,
 64                    teleportData.sceneData.owner,
 65                    teleportData.sceneData.previewImageUrl);
 066                SetSceneEvent();
 67                break;
 68        }
 069    }
 70
 71    public void Dispose()
 72    {
 373        if (view)
 74        {
 375            UnityEngine.Object.Destroy(view.gameObject);
 76        }
 377    }
 78
 79    private void SetSceneEvent()
 80    {
 081        EventData eventData = teleportData.sceneEvent;
 82
 083        if (eventData == null)
 084            return;
 85
 086        DateTime dateNow = DateTime.Now;
 87        DateTime eventStart;
 88        DateTime eventEnd;
 089        if (DateTime.TryParse(eventData.start_at, out eventStart) && DateTime.TryParse(eventData.finish_at, out eventEnd
 90        {
 091            bool startsToday = eventStart.Date == dateNow.Date;
 092            bool isNow = eventStart <= dateNow && dateNow <= eventEnd;
 93
 094            if (isNow || startsToday)
 95            {
 096                string eventStatus = EVENT_STRING_LIVE;
 097                if (!isNow && startsToday)
 098                    eventStatus = string.Format(EVENT_STRING_TODAY, eventStart);
 099                view.SetEventInfo(eventData.name, eventStatus, eventData.total_attendees);
 100            }
 101        }
 0102    }
 103
 104    private void OnTeleportPressed()
 105    {
 0106        switch (teleportData.destination)
 107        {
 108            case TELEPORT_COMMAND_CROWD:
 0109                WebInterface.GoToCrowd();
 0110                break;
 111            case TELEPORT_COMMAND_MAGIC:
 0112                WebInterface.GoToMagic();
 0113                break;
 114            default:
 115                int x, y;
 0116                string[] coordSplit = teleportData.destination.Split(',');
 0117                if (coordSplit.Length == 2 && int.TryParse(coordSplit[0], out x) && int.TryParse(coordSplit[1], out y))
 118                {
 0119                    WebInterface.GoTo(x, y);
 120                }
 121
 122                break;
 123        }
 0124    }
 125
 126    [Serializable]
 127    internal class TeleportData
 128    {
 1129        public string destination = "";
 130        public MinimapMetadata.MinimapSceneInfo sceneData = null;
 131        public EventData sceneEvent = null;
 132    }
 133
 134    [Serializable]
 135    internal class EventData
 136    {
 137        public string name;
 138        public int total_attendees;
 139        public string start_at;
 140        public string finish_at;
 141    }
 142}