< Summary

Class:LandElementView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Views/LandElementView.cs
Covered lines:73
Uncovered lines:16
Coverable lines:89
Total lines:206
Line coverage:82% (73 of 89)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
LandElementView()0%110100%
LandElementView()0%110100%
Awake()0%110100%
JumpInButtonPressed()0%6.65060%
EditorButtonPressed()0%6.65060%
OnDestroy()0%220100%
OnEnable()0%110100%
SetActive(...)0%110100%
Setup(...)0%5.475073.33%
SetId(...)0%110100%
GetId()0%2100%
SetName(...)0%110100%
SetCoords(...)0%110100%
SetSize(...)0%110100%
SetRole(...)0%110100%
GetParent()0%110100%
SetParent(...)0%110100%
SetThumbnail(...)0%4.114081.25%
SetThumbnail(...)0%2100%
SetEditable(...)0%110100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/BuilderProjectsPanel/Scripts/Views/LandElementView.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using DCL.Interface;
 4using TMPro;
 5using UnityEngine;
 6using UnityEngine.UI;
 7using Object = UnityEngine.Object;
 8
 9internal class LandElementView : MonoBehaviour, IDisposable
 10{
 11    internal const string SIZE_TEXT_FORMAT = "{0} LAND";
 12
 13    public event Action<Vector2Int> OnJumpInPressed;
 14    public event Action<Vector2Int> OnEditorPressed;
 15    public event Action<string> OnSettingsPressed;
 16    public event Action<string> OnOpenInDappPressed;
 17
 18    [SerializeField] private Texture2D defaultThumbnail;
 19    [SerializeField] private RawImageFillParent thumbnail;
 20    [SerializeField] internal TextMeshProUGUI landName;
 21    [SerializeField] private TextMeshProUGUI landCoords;
 22    [SerializeField] internal TextMeshProUGUI landSize;
 23    [SerializeField] internal GameObject landSizeGO;
 24    [SerializeField] internal GameObject roleOwner;
 25    [SerializeField] internal GameObject roleOperator;
 26    [SerializeField] internal Button buttonSettings;
 27    [SerializeField] internal Button buttonJumpIn;
 28    [SerializeField] internal Button buttonEditor;
 29    [SerializeField] internal Button buttonOpenInBuilderDapp;
 30    [SerializeField] internal UIHoverTriggerShowHideAnimator editorLocked;
 31    [SerializeField] private ShowHideAnimator editorLockedTooltipEstate;
 32    [SerializeField] private ShowHideAnimator editorLockedTooltipSdkScene;
 33    [SerializeField] internal Animator loadingAnimator;
 34
 135    private static readonly int isLoadingAnimation = Animator.StringToHash("isLoading");
 36
 1537    public ISearchInfo searchInfo { get; } = new SearchInfo();
 38
 39    private bool isDestroyed = false;
 40    private string landId;
 41    private string landCoordinates;
 42    private string thumbnailUrl;
 43    private AssetPromise_Texture thumbnailPromise;
 44    private Vector2Int coords;
 45    private bool isLoadingThumbnail = false;
 46
 47    private LandWithAccess currentLand;
 48    private void Awake()
 49    {
 1450        buttonSettings.onClick.AddListener(() => OnSettingsPressed?.Invoke(landId));
 1351        buttonJumpIn.onClick.AddListener(JumpInButtonPressed);
 1352        buttonEditor.onClick.AddListener(EditorButtonPressed);
 1453        buttonOpenInBuilderDapp.onClick.AddListener(() => OnOpenInDappPressed?.Invoke(landId));
 54
 1355        editorLockedTooltipEstate.gameObject.SetActive(false);
 1356        editorLockedTooltipSdkScene.gameObject.SetActive(false);
 1357    }
 58
 59    private void JumpInButtonPressed()
 60    {
 161        if (currentLand != null)
 62        {
 063            string ownership = currentLand.role == LandRole.OWNER ? "Owner" : "Operator";
 064            BIWAnalytics.PlayerJumpOrEdit("Lands", "JumpIn", coords, ownership);
 65        }
 166        OnJumpInPressed?.Invoke(coords);
 167    }
 68
 69    private void EditorButtonPressed()
 70    {
 171        if (currentLand != null)
 72        {
 073            string ownership = currentLand.role == LandRole.OWNER ? "Owner" : "Operator";
 074            BIWAnalytics.PlayerJumpOrEdit("Lands", "Editor", coords, ownership);
 75        }
 176        OnEditorPressed?.Invoke(coords);
 177    }
 78
 79    private void OnDestroy()
 80    {
 1381        isDestroyed = true;
 82
 1383        if (thumbnailPromise != null)
 84        {
 385            AssetPromiseKeeper_Texture.i.Forget(thumbnailPromise);
 386            thumbnailPromise = null;
 87        }
 1388    }
 89
 3490    private void OnEnable() { loadingAnimator.SetBool(isLoadingAnimation, isLoadingThumbnail); }
 91
 1092    public void SetActive(bool active) { gameObject.SetActive(active); }
 93
 94    public void Setup(LandWithAccess land)
 95    {
 596        currentLand = land;
 597        bool estate = land.type == LandType.ESTATE;
 98
 599        SetId(land.id);
 5100        SetName(land.name);
 5101        SetCoords(land.baseCoords.x, land.baseCoords.y);
 5102        SetSize(land.size);
 5103        SetRole(land.role == LandRole.OWNER);
 5104        SetEditable(!estate);
 105
 5106        if (estate)
 107        {
 0108            editorLocked.SetShowHideAnimator(editorLockedTooltipEstate);
 0109        }
 5110        else if (land.scenes != null && land.scenes.Count > 0 && land.scenes[0].source == DeployedScene.Source.SDK)
 111        {
 0112            editorLocked.SetShowHideAnimator(editorLockedTooltipSdkScene);
 0113            SetEditable(false);
 114        }
 5115    }
 116
 117    public void SetId(string id)
 118    {
 5119        landId = id;
 5120        searchInfo.SetId(id);
 5121    }
 122
 0123    public string GetId() { return landId; }
 124
 125    public void SetName(string name)
 126    {
 6127        landName.text = name;
 6128        searchInfo.SetName(name);
 6129    }
 130
 131    public void SetCoords(int x, int y)
 132    {
 5133        landCoordinates = $"{x},{y}";
 5134        landCoords.text = landCoordinates;
 5135        searchInfo.SetCoords(landCoordinates);
 5136        coords.Set(x, y);
 5137    }
 138
 139    public void SetSize(int size)
 140    {
 7141        landSizeGO.SetActive(size > 0);
 7142        landSize.text = string.Format(SIZE_TEXT_FORMAT, size);
 7143        searchInfo.SetSize(size);
 7144    }
 145
 146    public void SetRole(bool isOwner)
 147    {
 7148        roleOwner.SetActive(isOwner);
 7149        roleOperator.SetActive(!isOwner);
 7150        searchInfo.SetRole(isOwner);
 7151    }
 152
 12153    public Transform GetParent() { return transform.parent; }
 154
 10155    public void SetParent(Transform parent) { transform.SetParent(parent); }
 156
 157    public void SetThumbnail(string url)
 158    {
 5159        if (url == thumbnailUrl)
 2160            return;
 161
 3162        isLoadingThumbnail = true;
 3163        loadingAnimator.SetBool(isLoadingAnimation, isLoadingThumbnail);
 3164        thumbnailUrl = url;
 165
 3166        var prevPromise = thumbnailPromise;
 167
 3168        if (string.IsNullOrEmpty(url))
 169        {
 0170            SetThumbnail(defaultThumbnail);
 0171        }
 172        else
 173        {
 3174            thumbnailPromise = new AssetPromise_Texture(url);
 3175            thumbnailPromise.OnSuccessEvent += asset => SetThumbnail(asset.texture);
 3176            thumbnailPromise.OnFailEvent += asset => SetThumbnail(defaultThumbnail);
 3177            AssetPromiseKeeper_Texture.i.Keep(thumbnailPromise);
 178        }
 179
 3180        if (prevPromise != null)
 181        {
 0182            AssetPromiseKeeper_Texture.i.Forget(prevPromise);
 183        }
 3184    }
 185
 186    public void SetThumbnail(Texture thumbnailTexture)
 187    {
 0188        thumbnail.texture = thumbnailTexture;
 0189        isLoadingThumbnail = false;
 0190        loadingAnimator.SetBool(isLoadingAnimation, isLoadingThumbnail);
 0191    }
 192
 193    public void SetEditable(bool isEditable)
 194    {
 5195        buttonEditor.gameObject.SetActive(isEditable);
 5196        editorLocked.gameObject.SetActive(!isEditable);
 5197    }
 198
 199    public void Dispose()
 200    {
 3201        if (!isDestroyed)
 202        {
 3203            Destroy(gameObject);
 204        }
 3205    }
 206}