< Summary

Class:DCLPlugins.RealmPlugin.JumpToHomeController
Assembly:DCL.Plugins.RealmsPlugin
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/RealmsPlugin/Utils/JumpToHomeController.cs
Covered lines:7
Uncovered lines:13
Coverable lines:20
Total lines:68
Line coverage:35% (7 of 20)
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 DCL;
 2using DCL.Interface;
 3using System.Linq;
 4using UnityEngine;
 5using UnityEngine.UI;
 6using Variables.RealmsInfo;
 7
 8namespace DCLPlugins.RealmPlugin
 9{
 10    /// <summary>
 11    /// Controller for the Jump to Home logic.
 12    /// Its used to chose the most populated realm to jump home to
 13    /// </summary>
 14    public class JumpToHomeController : MonoBehaviour
 15    {
 16        [SerializeField] private Button jumpButton;
 17        [SerializeField] private ShowHideAnimator showHideAnimator;
 18        [SerializeField] private RectTransform positionWithMiniMap;
 19        [SerializeField] private RectTransform positionWithoutMiniMap;
 20
 021        private BaseCollection<RealmModel> realms => DataStore.i.realm.realmsInfo;
 122        private BaseVariable<bool> jumpHomeButtonVisible => DataStore.i.HUDs.jumpHomeButtonVisible;
 023        private BaseVariable<bool> minimapVisible => DataStore.i.HUDs.minimapVisible;
 24        private RectTransform rectTransform;
 25
 26        private void Start()
 27        {
 128            rectTransform = jumpButton.GetComponent<RectTransform>();
 129            jumpButton.onClick.AddListener(GoHome);
 130            jumpHomeButtonVisible.OnChange += SetVisibility;
 131        }
 32
 33        private void SetVisibility(bool current, bool _)
 34        {
 035            if (current)
 36            {
 037                jumpButton.interactable = true;
 038                rectTransform.anchoredPosition = minimapVisible.Get() ? positionWithMiniMap.anchoredPosition : positionW
 039                showHideAnimator.Show();
 40            }
 41            else
 042                showHideAnimator.Hide();
 043        }
 44
 45        private void GoHome()
 46        {
 047            jumpButton.interactable = false;
 48
 049            WebInterface.SendChatMessage(new ChatMessage
 50            {
 51                messageType = ChatMessage.Type.NONE,
 52                recipient = string.Empty,
 53                body = "/goto home",
 54            });
 055        }
 56
 57        private string GetMostPopulatedRealm()
 58        {
 059            var currentRealms = realms.Get().ToList();
 060            return currentRealms.OrderByDescending(e => e.usersCount).FirstOrDefault()?.serverName;
 61        }
 62
 63        private void OnDestroy()
 64        {
 1165            jumpButton.onClick.RemoveListener(GoHome);
 1166        }
 67    }
 68}