< Summary

Class:LandElementView
Assembly:BuilderProjectsPanel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/LandElementView.cs
Covered lines:73
Uncovered lines:16
Coverable lines:89
Total lines:207
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/DCLPlugins/BuilderInWorld/HUD/ProjectsPanelHUD/Scripts/Views/LandElementView.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using DCL.Builder;
 4using DCL.Interface;
 5using TMPro;
 6using UnityEngine;
 7using UnityEngine.UI;
 8using Object = UnityEngine.Object;
 9
 10internal class LandElementView : MonoBehaviour, IDisposable
 11{
 12    internal const string SIZE_TEXT_FORMAT = "{0} LAND";
 13
 14    public event Action<Vector2Int> OnJumpInPressed;
 15    public event Action<Vector2Int> OnEditorPressed;
 16    public event Action<string> OnSettingsPressed;
 17    public event Action<string> OnOpenInDappPressed;
 18
 19    [SerializeField] private Texture2D defaultThumbnail;
 20    [SerializeField] private RawImageFillParent thumbnail;
 21    [SerializeField] internal TextMeshProUGUI landName;
 22    [SerializeField] private TextMeshProUGUI landCoords;
 23    [SerializeField] internal TextMeshProUGUI landSize;
 24    [SerializeField] internal GameObject landSizeGO;
 25    [SerializeField] internal GameObject roleOwner;
 26    [SerializeField] internal GameObject roleOperator;
 27    [SerializeField] internal Button buttonSettings;
 28    [SerializeField] internal Button buttonJumpIn;
 29    [SerializeField] internal Button buttonEditor;
 30    [SerializeField] internal Button buttonOpenInBuilderDapp;
 31    [SerializeField] internal UIHoverTriggerShowHideAnimator editorLocked;
 32    [SerializeField] private ShowHideAnimator editorLockedTooltipEstate;
 33    [SerializeField] private ShowHideAnimator editorLockedTooltipSdkScene;
 34    [SerializeField] internal Animator loadingAnimator;
 35
 136    private static readonly int isLoadingAnimation = Animator.StringToHash("isLoading");
 37
 1538    public ISearchInfo searchInfo { get; } = new SearchInfo();
 39
 40    private bool isDestroyed = false;
 41    private string landId;
 42    private string landCoordinates;
 43    private string thumbnailUrl;
 44    private AssetPromise_Texture thumbnailPromise;
 45    private Vector2Int coords;
 46    private bool isLoadingThumbnail = false;
 47
 48    private LandWithAccess currentLand;
 49    private void Awake()
 50    {
 1451        buttonSettings.onClick.AddListener(() => OnSettingsPressed?.Invoke(landId));
 1352        buttonJumpIn.onClick.AddListener(JumpInButtonPressed);
 1353        buttonEditor.onClick.AddListener(EditorButtonPressed);
 1454        buttonOpenInBuilderDapp.onClick.AddListener(() => OnOpenInDappPressed?.Invoke(landId));
 55
 1356        editorLockedTooltipEstate.gameObject.SetActive(false);
 1357        editorLockedTooltipSdkScene.gameObject.SetActive(false);
 1358    }
 59
 60    private void JumpInButtonPressed()
 61    {
 162        if (currentLand != null)
 63        {
 064            string ownership = currentLand.role == LandRole.OWNER ? "Owner" : "Operator";
 065            BIWAnalytics.PlayerJumpOrEdit("Lands", "JumpIn", coords, ownership);
 66        }
 167        OnJumpInPressed?.Invoke(coords);
 168    }
 69
 70    private void EditorButtonPressed()
 71    {
 172        if (currentLand != null)
 73        {
 074            string ownership = currentLand.role == LandRole.OWNER ? "Owner" : "Operator";
 075            BIWAnalytics.PlayerJumpOrEdit("Lands", "Editor", coords, ownership);
 76        }
 177        OnEditorPressed?.Invoke(coords);
 178    }
 79
 80    private void OnDestroy()
 81    {
 1382        isDestroyed = true;
 83
 1384        if (thumbnailPromise != null)
 85        {
 386            AssetPromiseKeeper_Texture.i.Forget(thumbnailPromise);
 387            thumbnailPromise = null;
 88        }
 1389    }
 90
 3491    private void OnEnable() { loadingAnimator.SetBool(isLoadingAnimation, isLoadingThumbnail); }
 92
 1093    public void SetActive(bool active) { gameObject.SetActive(active); }
 94
 95    public void Setup(LandWithAccess land)
 96    {
 597        currentLand = land;
 598        bool estate = land.type == LandType.ESTATE;
 99
 5100        SetId(land.id);
 5101        SetName(land.name);
 5102        SetCoords(land.baseCoords.x, land.baseCoords.y);
 5103        SetSize(land.size);
 5104        SetRole(land.role == LandRole.OWNER);
 5105        SetEditable(!estate);
 106
 5107        if (estate)
 108        {
 0109            editorLocked.SetShowHideAnimator(editorLockedTooltipEstate);
 0110        }
 5111        else if (land.scenes != null && land.scenes.Count > 0 && land.scenes[0].source == Scene.Source.SDK)
 112        {
 0113            editorLocked.SetShowHideAnimator(editorLockedTooltipSdkScene);
 0114            SetEditable(false);
 115        }
 5116    }
 117
 118    public void SetId(string id)
 119    {
 5120        landId = id;
 5121        searchInfo.SetId(id);
 5122    }
 123
 0124    public string GetId() { return landId; }
 125
 126    public void SetName(string name)
 127    {
 6128        landName.text = name;
 6129        searchInfo.SetName(name);
 6130    }
 131
 132    public void SetCoords(int x, int y)
 133    {
 5134        landCoordinates = $"{x},{y}";
 5135        landCoords.text = landCoordinates;
 5136        searchInfo.SetCoords(landCoordinates);
 5137        coords.Set(x, y);
 5138    }
 139
 140    public void SetSize(int size)
 141    {
 7142        landSizeGO.SetActive(size > 0);
 7143        landSize.text = string.Format(SIZE_TEXT_FORMAT, size);
 7144        searchInfo.SetSize(size);
 7145    }
 146
 147    public void SetRole(bool isOwner)
 148    {
 7149        roleOwner.SetActive(isOwner);
 7150        roleOperator.SetActive(!isOwner);
 7151        searchInfo.SetRole(isOwner);
 7152    }
 153
 12154    public Transform GetParent() { return transform.parent; }
 155
 10156    public void SetParent(Transform parent) { transform.SetParent(parent); }
 157
 158    public void SetThumbnail(string url)
 159    {
 5160        if (url == thumbnailUrl)
 2161            return;
 162
 3163        isLoadingThumbnail = true;
 3164        loadingAnimator.SetBool(isLoadingAnimation, isLoadingThumbnail);
 3165        thumbnailUrl = url;
 166
 3167        var prevPromise = thumbnailPromise;
 168
 3169        if (string.IsNullOrEmpty(url))
 170        {
 0171            SetThumbnail(defaultThumbnail);
 0172        }
 173        else
 174        {
 3175            thumbnailPromise = new AssetPromise_Texture(url);
 3176            thumbnailPromise.OnSuccessEvent += asset => SetThumbnail(asset.texture);
 3177            thumbnailPromise.OnFailEvent += (asset, error) => SetThumbnail(defaultThumbnail);
 3178            AssetPromiseKeeper_Texture.i.Keep(thumbnailPromise);
 179        }
 180
 3181        if (prevPromise != null)
 182        {
 0183            AssetPromiseKeeper_Texture.i.Forget(prevPromise);
 184        }
 3185    }
 186
 187    public void SetThumbnail(Texture thumbnailTexture)
 188    {
 0189        thumbnail.texture = thumbnailTexture;
 0190        isLoadingThumbnail = false;
 0191        loadingAnimator.SetBool(isLoadingAnimation, isLoadingThumbnail);
 0192    }
 193
 194    public void SetEditable(bool isEditable)
 195    {
 5196        buttonEditor.gameObject.SetActive(isEditable);
 5197        editorLocked.gameObject.SetActive(!isEditable);
 5198    }
 199
 200    public void Dispose()
 201    {
 3202        if (!isDestroyed)
 203        {
 3204            Destroy(gameObject);
 205        }
 3206    }
 207}