< Summary

Class:DCLPlugins.RealmsPlugin.JumpToHomeController
Assembly:DCL.Plugins.RealmsPlugin
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/RealmsPlugin/Utils/JumpToHomeController.cs
Covered lines:6
Uncovered lines:13
Coverable lines:19
Total lines:67
Line coverage:31.5% (6 of 19)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Start()0%110100%
SetVisibility(...)0%12300%
GoHome()0%2100%
GetMostPopulatedRealm()0%12300%
OnDestroy()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/RealmsPlugin/Utils/JumpToHomeController.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL;
 4using DCL.Interface;
 5using UnityEngine;
 6using UnityEngine.UI;
 7using Variables.RealmsInfo;
 8
 9namespace DCLPlugins.RealmsPlugin
 10{
 11    /// <summary>
 12    /// Controller for the Jump to Home logic.
 13    /// Its used to chose the most populated realm to jump home to
 14    /// </summary>
 15    public class JumpToHomeController : MonoBehaviour
 16    {
 17
 18        [SerializeField] private Button jumpButton;
 19        [SerializeField] private ShowHideAnimator showHideAnimator;
 20        [SerializeField] private RectTransform positionWithMiniMap;
 21        [SerializeField] private RectTransform positionWithoutMiniMap;
 22
 023        private BaseCollection<RealmModel> realms => DataStore.i.realm.realmsInfo;
 124        private BaseVariable<bool> jumpHomeButtonVisible => DataStore.i.HUDs.jumpHomeButtonVisible;
 025        private BaseVariable<bool> minimapVisible => DataStore.i.HUDs.minimapVisible;
 26        private RectTransform rectTransform;
 27
 28        private void Start()
 29        {
 130            rectTransform = jumpButton.GetComponent<RectTransform>();
 131            jumpButton.onClick.AddListener(GoHome);
 132            jumpHomeButtonVisible.OnChange += SetVisibility;
 133        }
 34
 35        private void SetVisibility(bool current, bool _)
 36        {
 037            if (current)
 38            {
 039                jumpButton.interactable = true;
 040                rectTransform.anchoredPosition = minimapVisible.Get() ? positionWithMiniMap.anchoredPosition : positionW
 041                showHideAnimator.Show();
 42            }
 43            else
 44            {
 045                showHideAnimator.Hide();
 46            }
 047        }
 48        private void GoHome()
 49        {
 050            jumpButton.interactable = false;
 051            WebInterface.SendChatMessage(new ChatMessage
 52            {
 53                messageType = ChatMessage.Type.NONE,
 54                recipient = string.Empty,
 55                body = $"/goto home"
 56            });
 057        }
 58
 59        private string GetMostPopulatedRealm()
 60        {
 061            List<RealmModel> currentRealms = realms.Get().ToList();
 062            return currentRealms.OrderByDescending(e => e.usersCount).FirstOrDefault()?.serverName;
 63        }
 64
 2265        private void OnDestroy() { jumpButton.onClick.RemoveListener(GoHome); }
 66    }
 67}