< 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:73
Uncovered lines:4
Coverable lines:77
Total lines:153
Line coverage:94.8% (73 of 77)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize()0%110100%
CreateControllers()0%110100%
OnSectionOpen(...)0%220100%
Dispose()0%330100%
SetVisibility(...)0%110100%
IsOpenChanged(...)0%110100%
SetVisibility_Internal(...)0%4.014091.67%
UpdateRealmInfo(...)0%11110100%
UpdateProfileInfo(...)0%110100%
OnCloseButtonPressed()0%220100%
OnAnyActionExecuted()0%110100%
CreateAnalyticsController()0%2100%
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 DCL.Helpers;
 3using System.Collections.Generic;
 4using System.Linq;
 5using ExploreV2Analytics;
 6using UnityEngine;
 7using Variables.RealmsInfo;
 8
 9/// <summary>
 10/// Main controller for the feature "Explore V2".
 11/// </summary>
 12public class ExploreV2MenuComponentController : IExploreV2MenuComponentController
 13{
 3314    internal UserProfile ownUserProfile => UserProfile.GetOwnUserProfile();
 15
 16    internal IExploreV2MenuComponentView view;
 17    internal IPlacesAndEventsSectionComponentController placesAndEventsSectionController;
 018    internal BaseVariable<bool> isOpen => DataStore.i.exploreV2.isOpen;
 19    internal IExploreV2Analytics exploreV2Analytics;
 20    internal ExploreSection currentOpenSection;
 21
 22    public void Initialize()
 23    {
 1124        exploreV2Analytics = CreateAnalyticsController();
 1125        view = CreateView();
 1126        SetVisibility(false);
 27
 1128        DataStore.i.playerRealm.OnChange += UpdateRealmInfo;
 1129        UpdateRealmInfo(DataStore.i.playerRealm.Get(), null);
 30
 1131        ownUserProfile.OnUpdate += UpdateProfileInfo;
 1132        UpdateProfileInfo(ownUserProfile);
 33
 1134        view.OnCloseButtonPressed += OnCloseButtonPressed;
 1135        DataStore.i.exploreV2.isInitialized.Set(true);
 36
 1137        view.OnInitialized += CreateControllers;
 1138        view.OnSectionOpen += OnSectionOpen;
 39
 1140        isOpen.OnChange += IsOpenChanged;
 1141        IsOpenChanged(isOpen.Get(), false);
 1142    }
 43
 44    internal void CreateControllers()
 45    {
 146        placesAndEventsSectionController = new PlacesAndEventsSectionComponentController(view.currentPlacesAndEventsSect
 147        placesAndEventsSectionController.OnCloseExploreV2 += OnCloseButtonPressed;
 148        placesAndEventsSectionController.OnAnyActionExecuted += OnAnyActionExecuted;
 149    }
 50
 51    internal void OnSectionOpen(ExploreSection section)
 52    {
 353        if (section != currentOpenSection)
 54        {
 355            exploreV2Analytics.SendExploreSectionVisibility(currentOpenSection, false);
 356            exploreV2Analytics.SendExploreSectionVisibility(section, true);
 357            exploreV2Analytics.anyActionExecutedFromLastOpen = true;
 58        }
 59
 360        currentOpenSection = section;
 361    }
 62
 63    public void Dispose()
 64    {
 1165        DataStore.i.playerRealm.OnChange -= UpdateRealmInfo;
 1166        ownUserProfile.OnUpdate -= UpdateProfileInfo;
 1167        isOpen.OnChange -= IsOpenChanged;
 68
 1169        if (view != null)
 70        {
 1171            view.OnCloseButtonPressed -= OnCloseButtonPressed;
 1172            view.OnInitialized -= CreateControllers;
 1173            view.OnSectionOpen -= OnSectionOpen;
 1174            view.Dispose();
 75        }
 76
 1177        if (placesAndEventsSectionController != null)
 78        {
 179            placesAndEventsSectionController.OnCloseExploreV2 -= OnCloseButtonPressed;
 180            placesAndEventsSectionController.OnAnyActionExecuted -= OnAnyActionExecuted;
 181            placesAndEventsSectionController.Dispose();
 82        }
 1183    }
 84
 2885    public void SetVisibility(bool visible) { isOpen.Set(visible); }
 86
 3287    private void IsOpenChanged(bool current, bool previous) { SetVisibility_Internal(current); }
 88
 89    internal void SetVisibility_Internal(bool visible)
 90    {
 1691        if (view == null)
 092            return;
 93
 1694        if (visible)
 95        {
 396            Utils.UnlockCursor();
 397            AudioScriptableObjects.dialogOpen.Play(true);
 398            AudioScriptableObjects.listItemAppear.ResetPitch();
 399        }
 100        else
 101        {
 13102            AudioScriptableObjects.dialogClose.Play(true);
 103        }
 104
 16105        if (!visible)
 13106            exploreV2Analytics.anyActionExecutedFromLastOpen = false;
 107
 16108        view.SetVisible(visible);
 16109    }
 110
 111    internal void UpdateRealmInfo(CurrentRealmModel currentRealm, CurrentRealmModel previousRealm)
 112    {
 113        // Get the name of the current realm
 13114        string currentRealmServer = currentRealm?.serverName;
 13115        string currentRealmLayer = currentRealm?.layer;
 13116        string formattedRealmName = currentRealmServer;
 13117        if (!string.IsNullOrEmpty(currentRealmLayer))
 118        {
 2119            formattedRealmName = $"{formattedRealmName}-{currentRealmLayer}";
 120        }
 121
 13122        view.currentRealmViewer.SetRealm(formattedRealmName);
 123
 124        // Calculate number of users in the current realm
 13125        List<RealmModel> realmList = DataStore.i.realmsInfo.Get()?.ToList();
 14126        RealmModel currentRealmModel = realmList?.FirstOrDefault(r => r.serverName == currentRealmServer && (r.layer == 
 13127        int realmUsers = 0;
 13128        if (currentRealmModel != null)
 1129            realmUsers = currentRealmModel.usersCount;
 130
 13131        view.currentRealmViewer.SetNumberOfUsers(realmUsers);
 13132    }
 133
 134    internal void UpdateProfileInfo(UserProfile profile)
 135    {
 12136        view.currentProfileCard.SetProfileName(profile.userName);
 12137        view.currentProfileCard.SetProfileAddress(profile.ethAddress);
 12138        view.currentProfileCard.SetProfilePicture(profile.face128SnapshotURL);
 12139    }
 140
 141    internal void OnCloseButtonPressed()
 142    {
 1143        if (DataStore.i.exploreV2.isOpen.Get())
 1144            exploreV2Analytics.SendExploreMainMenuVisibility(false, ExploreUIVisibilityMethod.FromClick);
 1145        SetVisibility(false);
 1146    }
 147
 2148    internal void OnAnyActionExecuted() { exploreV2Analytics.anyActionExecutedFromLastOpen = true; }
 149
 0150    internal virtual IExploreV2Analytics CreateAnalyticsController() => new ExploreV2Analytics.ExploreV2Analytics();
 151
 0152    internal virtual IExploreV2MenuComponentView CreateView() => ExploreV2MenuComponentView.Create();
 153}