< Summary

Class:ExploreV2MenuComponentController
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/MainMenu/ExploreV2Menu/ExploreV2MenuComponentController.cs
Covered lines:51
Uncovered lines:3
Coverable lines:54
Total lines:109
Line coverage:94.4% (51 of 54)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize()0%110100%
CreateControllers()0%110100%
Dispose()0%330100%
SetVisibility(...)0%6.566075%
UpdateRealmInfo(...)0%11110100%
UpdateProfileInfo(...)0%110100%
OnCloseButtonPressed()0%110100%
OnActivateFromTaskbar(...)0%110100%
CreateView()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/MainMenu/ExploreV2Menu/ExploreV2MenuComponentController.cs

#LineLine coverage
 1using DCL;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Variables.RealmsInfo;
 5
 6/// <summary>
 7/// Main controller for the feature "Explore V2".
 8/// </summary>
 9public class ExploreV2MenuComponentController : IExploreV2MenuComponentController
 10{
 2711    internal UserProfile ownUserProfile => UserProfile.GetOwnUserProfile();
 12
 13    internal IExploreV2MenuComponentView view;
 14    internal IPlacesAndEventsSectionComponentController placesAndEventsSectionController;
 15
 16    public void Initialize()
 17    {
 918        view = CreateView();
 919        SetVisibility(false);
 20
 921        DataStore.i.playerRealm.OnChange += UpdateRealmInfo;
 922        UpdateRealmInfo(DataStore.i.playerRealm.Get(), null);
 23
 924        ownUserProfile.OnUpdate += UpdateProfileInfo;
 925        UpdateProfileInfo(ownUserProfile);
 26
 927        view.OnCloseButtonPressed += OnCloseButtonPressed;
 928        DataStore.i.taskbar.isExploreV2Enabled.OnChange += OnActivateFromTaskbar;
 929        DataStore.i.exploreV2.isInitialized.Set(true);
 30
 931        view.OnInitialized += CreateControllers;
 932    }
 33
 34    internal void CreateControllers()
 35    {
 136        placesAndEventsSectionController = new PlacesAndEventsSectionComponentController(view.currentPlacesAndEventsSect
 137        placesAndEventsSectionController.OnCloseExploreV2 += OnCloseButtonPressed;
 138    }
 39
 40    public void Dispose()
 41    {
 942        DataStore.i.playerRealm.OnChange -= UpdateRealmInfo;
 943        ownUserProfile.OnUpdate -= UpdateProfileInfo;
 44
 945        if (view != null)
 46        {
 947            view.OnCloseButtonPressed -= OnCloseButtonPressed;
 948            view.OnInitialized -= CreateControllers;
 949            view.Dispose();
 50        }
 51
 952        DataStore.i.taskbar.isExploreV2Enabled.OnChange -= OnActivateFromTaskbar;
 53
 954        if (placesAndEventsSectionController != null)
 55        {
 156            placesAndEventsSectionController.OnCloseExploreV2 -= OnCloseButtonPressed;
 157            placesAndEventsSectionController.Dispose();
 58        }
 959    }
 60
 61    public void SetVisibility(bool visible)
 62    {
 1463        if (view == null)
 064            return;
 65
 1466        if (visible && !view.isActive)
 267            DataStore.i.exploreV2.isOpen.Set(true);
 1268        else if (!visible && view.isActive)
 069            DataStore.i.exploreV2.isOpen.Set(false);
 70
 1471        view.SetActive(visible);
 1472    }
 73
 74    internal void UpdateRealmInfo(CurrentRealmModel currentRealm, CurrentRealmModel previousRealm)
 75    {
 76        // Get the name of the current realm
 1177        string currentRealmServer = currentRealm?.serverName;
 1178        string currentRealmLayer = currentRealm?.layer;
 1179        string formattedRealmName = currentRealmServer;
 1180        if (!string.IsNullOrEmpty(currentRealmLayer))
 81        {
 282            formattedRealmName = $"{formattedRealmName}-{currentRealmLayer}";
 83        }
 84
 1185        view.currentRealmViewer.SetRealm(formattedRealmName);
 86
 87        // Calculate number of users in the current realm
 1188        List<RealmModel> realmList = DataStore.i.realmsInfo.Get()?.ToList();
 1289        RealmModel currentRealmModel = realmList?.FirstOrDefault(r => r.serverName == currentRealmServer && (r.layer == 
 1190        int realmUsers = 0;
 1191        if (currentRealmModel != null)
 192            realmUsers = currentRealmModel.usersCount;
 93
 1194        view.currentRealmViewer.SetNumberOfUsers(realmUsers);
 1195    }
 96
 97    internal void UpdateProfileInfo(UserProfile profile)
 98    {
 1099        view.currentProfileCard.SetProfileName(profile.userName);
 10100        view.currentProfileCard.SetProfileAddress(profile.ethAddress);
 10101        view.currentProfileCard.SetProfilePicture(profile.face128SnapshotURL);
 10102    }
 103
 2104    internal void OnCloseButtonPressed() { SetVisibility(false); }
 105
 4106    internal void OnActivateFromTaskbar(bool current, bool previous) { SetVisibility(current); }
 107
 0108    internal virtual IExploreV2MenuComponentView CreateView() => ExploreV2MenuComponentView.Create();
 109}