< Summary

Class:TeleportPromptHUDView
Assembly:TeleportPromptHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/TeleportPromptHUD/TeleportPromptHUDView.cs
Covered lines:28
Uncovered lines:42
Coverable lines:70
Total lines:177
Line coverage:40% (28 of 70)
Covered branches:0
Total branches:0
Covered methods:6
Total methods:15
Method coverage:40% (6 of 15)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
TeleportPromptHUDView()0%110100%
Awake()0%110100%
Reset()0%110100%
SetLoadingCompleted()0%2100%
SetInAnimation()0%110100%
SetOutAnimation()0%2100%
ShowTeleportToMagic()0%110100%
ShowTeleportToCrowd()0%2100%
ShowTeleportToCoords(...)0%12300%
SetEventInfo(...)0%2100%
SetParcelImage(...)0%12300%
DisplayThumbnail(...)0%2100%
OnClosePressed()0%6200%
OnTeleportPressed()0%6200%
OnDestroy()0%5.264057.14%

File(s)

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

#LineLine coverage
 1using System;
 2using UnityEngine;
 3using UnityEngine.UI;
 4using TMPro;
 5using DCL.Helpers;
 6using DCL;
 7
 8public class TeleportPromptHUDView : MonoBehaviour
 9{
 10    [SerializeField] internal GameObject content;
 11    [SerializeField] internal Animator teleportHUDAnimator;
 12    [SerializeField] internal GraphicRaycaster teleportRaycaster;
 13
 14    [Header("Images")]
 15    [SerializeField] private RawImage imageSceneThumbnail;
 16
 17    [SerializeField] private Image imageGotoCrowd;
 18    [SerializeField] internal Image imageGotoMagic;
 19    [SerializeField] private Texture2D nullImage;
 20
 21    [Header("Containers")]
 22    [SerializeField] private GameObject containerCoords;
 23
 24    [SerializeField] private GameObject containerMagic;
 25    [SerializeField] private GameObject containerCrowd;
 26    [SerializeField] private GameObject containerScene;
 27    [SerializeField] private GameObject containerEvent;
 28    [SerializeField] private GameObject creatorContainer;
 29
 30    [Header("Scene info")]
 31    [SerializeField] private TextMeshProUGUI textCoords;
 32
 33    [SerializeField] private TextMeshProUGUI textSceneName;
 34    [SerializeField] private TextMeshProUGUI textSceneOwner;
 35
 36    [Header("Event info")]
 37    [SerializeField] private TextMeshProUGUI textEventInfo;
 38
 39    [SerializeField] private TextMeshProUGUI textEventName;
 40    [SerializeField] private TextMeshProUGUI textEventAttendees;
 41
 42    [SerializeField] private Button continueButton;
 43    [SerializeField] private Button cancelButton;
 44    [SerializeField] private Button backgroundCatcher;
 45
 46    public event Action OnCloseEvent;
 47    public event Action OnTeleportEvent;
 48
 49    IWebRequestAsyncOperation fetchParcelImageOp;
 50    Texture2D downloadedBanner;
 51    private HUDCanvasCameraModeController hudCanvasCameraModeController;
 152    private static readonly int IDLE = Animator.StringToHash("Idle");
 153    private static readonly int OUT = Animator.StringToHash("Out");
 154    private static readonly int IN = Animator.StringToHash("In");
 55
 56    private void Awake()
 57    {
 258        hudCanvasCameraModeController = new HUDCanvasCameraModeController(content.GetComponent<Canvas>(), DataStore.i.ca
 259        cancelButton.onClick.AddListener(OnClosePressed);
 260        backgroundCatcher.onClick.AddListener(OnClosePressed);
 261        continueButton.onClick.AddListener(OnTeleportPressed);
 262        teleportRaycaster.enabled = false;
 263    }
 64
 65    public void Reset()
 66    {
 167        containerCoords.SetActive(false);
 168        containerCrowd.SetActive(false);
 169        containerMagic.SetActive(false);
 170        containerScene.SetActive(false);
 171        containerEvent.SetActive(false);
 72
 173        imageSceneThumbnail.gameObject.SetActive(false);
 174        imageGotoCrowd.gameObject.SetActive(false);
 175        imageGotoMagic.gameObject.SetActive(false);
 176    }
 77
 78    public void SetLoadingCompleted()
 79    {
 080        teleportHUDAnimator.SetTrigger(IDLE);
 081    }
 82
 83    public void SetInAnimation()
 84    {
 185        teleportRaycaster.enabled = true;
 186        teleportHUDAnimator.SetTrigger(IN);
 187    }
 88
 89    public void SetOutAnimation()
 90    {
 091        teleportRaycaster.enabled = false;
 092        teleportHUDAnimator.SetTrigger(OUT);
 093    }
 94
 95    public void ShowTeleportToMagic()
 96    {
 197        containerMagic.SetActive(true);
 198        imageGotoMagic.gameObject.SetActive(true);
 199    }
 100
 101    public void ShowTeleportToCrowd()
 102    {
 0103        containerCrowd.SetActive(true);
 0104        imageGotoCrowd.gameObject.SetActive(true);
 0105    }
 106
 107    public void ShowTeleportToCoords(string coords, string sceneName, string sceneCreator, string previewImageUrl)
 108    {
 0109        containerCoords.SetActive(true);
 0110        containerScene.SetActive(true);
 111
 0112        textCoords.text = coords;
 0113        textSceneName.text = !string.IsNullOrEmpty(sceneName) ? sceneName : "Untitled Scene";
 0114        creatorContainer.SetActive(!string.IsNullOrEmpty(sceneCreator));
 0115        textSceneOwner.text = sceneCreator;
 0116        SetParcelImage(previewImageUrl);
 0117    }
 118
 119    public void SetEventInfo(string eventName, string eventStatus, int attendeesCount)
 120    {
 0121        containerEvent.SetActive(true);
 0122        textEventInfo.text = eventStatus;
 0123        textEventName.text = eventName;
 0124        textEventAttendees.text = $"+{attendeesCount}";
 0125    }
 126
 127    private AssetPromise_Texture texturePromise;
 128
 129    public void SetParcelImage(string imageUrl)
 130    {
 0131        containerMagic.SetActive(false);
 0132        imageSceneThumbnail.gameObject.SetActive(true);
 133
 0134        if (string.IsNullOrEmpty(imageUrl))
 135        {
 0136            DisplayThumbnail(nullImage);
 0137            return;
 138        }
 139
 0140        if (texturePromise != null)
 0141            AssetPromiseKeeper_Texture.i.Forget(texturePromise);
 142
 0143        texturePromise = new AssetPromise_Texture(imageUrl, storeTexAsNonReadable: false);
 0144        texturePromise.OnSuccessEvent += (textureAsset) => { DisplayThumbnail(textureAsset.texture); };
 0145        texturePromise.OnFailEvent += (x, e) => DisplayThumbnail(nullImage);
 0146        AssetPromiseKeeper_Texture.i.Keep(texturePromise);
 0147    }
 148
 149    private void DisplayThumbnail(Texture2D texture)
 150    {
 0151        imageSceneThumbnail.texture = texture;
 0152    }
 153
 154    private void OnClosePressed()
 155    {
 0156        OnCloseEvent?.Invoke();
 0157    }
 158
 159    private void OnTeleportPressed()
 160    {
 0161        OnTeleportEvent?.Invoke();
 0162    }
 163
 164    private void OnDestroy()
 165    {
 2166        hudCanvasCameraModeController?.Dispose();
 167
 2168        if (downloadedBanner != null)
 169        {
 0170            UnityEngine.Object.Destroy(downloadedBanner);
 0171            downloadedBanner = null;
 172        }
 173
 2174        if (fetchParcelImageOp != null)
 0175            fetchParcelImageOp.Dispose();
 2176    }
 177}