< Summary

Class:DCL.Social.Passports.PlayerPassportHUDController
Assembly:PassportHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PlayerPassportHUDController.cs
Covered lines:27
Uncovered lines:14
Coverable lines:41
Total lines:109
Line coverage:65.8% (27 of 41)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerPassportHUDController(...)0%110100%
SetVisibility(...)0%110100%
OnCloseButtonPressed(...)0%2100%
Dispose()0%220100%
OnCurrentPlayerIdChanged(...)0%7.464040%
UpdateUserProfile(...)0%2100%
UpdateUserProfileInSubpanels(...)0%2100%
RemoveCurrentPlayer()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Passport/Passport/PlayerPassportHUDController.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using System.Collections;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6using DCL;
 7using DCL.Helpers;
 8using SocialFeaturesAnalytics;
 9
 10namespace DCL.Social.Passports
 11{
 12    public class PlayerPassportHUDController : IHUD
 13    {
 14        internal readonly IPlayerPassportHUDView view;
 15        internal readonly StringVariable currentPlayerId;
 16        internal readonly IUserProfileBridge userProfileBridge;
 17        private readonly ISocialAnalytics socialAnalytics;
 18
 19        internal UserProfile currentUserProfile;
 20
 21        private readonly InputAction_Trigger closeWindowTrigger;
 22
 23        private PassportPlayerInfoComponentController playerInfoController;
 24        private PassportPlayerPreviewComponentController playerPreviewController;
 25        private PassportNavigationComponentController passportNavigationController;
 26
 227        public PlayerPassportHUDController(
 28            IPlayerPassportHUDView view,
 29            PassportPlayerInfoComponentController playerInfoController,
 30            PassportPlayerPreviewComponentController playerPreviewController,
 31            PassportNavigationComponentController passportNavigationController,
 32            StringVariable currentPlayerId,
 33            IUserProfileBridge userProfileBridge,
 34            ISocialAnalytics socialAnalytics)
 35        {
 236            this.view = view;
 237            this.playerInfoController = playerInfoController;
 238            this.playerPreviewController = playerPreviewController;
 239            this.passportNavigationController = passportNavigationController;
 240            this.currentPlayerId = currentPlayerId;
 241            this.userProfileBridge = userProfileBridge;
 242            this.socialAnalytics = socialAnalytics;
 43
 244            view.Initialize();
 245            view.OnClose += RemoveCurrentPlayer;
 46
 247            closeWindowTrigger = Resources.Load<InputAction_Trigger>("CloseWindow");
 248            closeWindowTrigger.OnTriggered -= OnCloseButtonPressed;
 249            closeWindowTrigger.OnTriggered += OnCloseButtonPressed;
 50
 251            currentPlayerId.OnChange += OnCurrentPlayerIdChanged;
 252            OnCurrentPlayerIdChanged(currentPlayerId, null);
 253        }
 54
 55        public void SetVisibility(bool visible)
 56        {
 257            view.SetVisibility(visible);
 258        }
 59
 60        private void OnCloseButtonPressed(DCLAction_Trigger action = DCLAction_Trigger.CloseWindow)
 61        {
 062            RemoveCurrentPlayer();
 063        }
 64
 65        public void Dispose()
 66        {
 267            closeWindowTrigger.OnTriggered -= OnCloseButtonPressed;
 268            currentPlayerId.OnChange -= OnCurrentPlayerIdChanged;
 269            if (view != null)
 270                view.Dispose();
 271        }
 72
 73        private void OnCurrentPlayerIdChanged(string current, string previous)
 74        {
 275            if (currentUserProfile != null)
 076                currentUserProfile.OnUpdate -= UpdateUserProfile;
 77
 278            currentUserProfile = string.IsNullOrEmpty(current)
 79                ? null
 80                : userProfileBridge.Get(current);
 81
 282            if (currentUserProfile == null)
 83            {
 284                view.SetPassportPanelVisibility(false);
 85            }
 86            else
 87            {
 088                userProfileBridge.RequestFullUserProfile(currentUserProfile.userId);
 089                currentUserProfile.OnUpdate += UpdateUserProfile;
 090                view.SetPassportPanelVisibility(true);
 091                UpdateUserProfileInSubpanels(currentUserProfile);
 92            }
 093        }
 94
 095        private void UpdateUserProfile(UserProfile userProfile) => UpdateUserProfileInSubpanels(userProfile);
 96
 97        private void UpdateUserProfileInSubpanels(UserProfile userProfile)
 98        {
 099            playerInfoController.UpdateWithUserProfile(userProfile);
 0100            passportNavigationController.UpdateWithUserProfile(userProfile);
 0101        }
 102
 103        private void RemoveCurrentPlayer()
 104        {
 0105            currentPlayerId.Set(null);
 0106        }
 107
 108    }
 109}