< Summary

Class:PlayerInfoCardHUDController
Assembly:PlayerInfoCardHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PlayerInfoCardHUD/PlayerInfoCardHUDController.cs
Covered lines:42
Uncovered lines:28
Coverable lines:70
Total lines:178
Line coverage:60% (42 of 70)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
PlayerInfoCardHUDController()0%110100%
CloseCard()0%110100%
OnCloseButtonPressed(...)0%2100%
AddPlayerAsFriend()0%2100%
CancelInvitation()0%2100%
AcceptFriendRequest()0%2100%
RejectFriendRequest()0%2100%
OnCurrentPlayerIdChanged(...)0%440100%
SetUserProfile(...)0%110100%
SetVisibility(...)0%110100%
BlockPlayer()0%6200%
UnblockPlayer()0%6200%
ReportPlayer()0%2100%
Dispose()0%770100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/PlayerInfoCardHUD/PlayerInfoCardHUDController.cs

#LineLine coverage
 1using DCL.Interface;
 2using UnityEngine;
 3
 4public class PlayerInfoCardHUDController : IHUD
 5{
 6    internal const string CURRENT_PLAYER_ID = "CurrentPlayerInfoCardId";
 7
 8    internal PlayerInfoCardHUDView view;
 9    internal StringVariable currentPlayerId;
 10    internal UserProfile currentUserProfile;
 011    private UserProfile ownUserProfile => UserProfile.GetOwnUserProfile();
 12
 13    private InputAction_Trigger toggleFriendsTrigger;
 14    private InputAction_Trigger closeWindowTrigger;
 15    private InputAction_Trigger toggleWorldChatTrigger;
 16
 417    public PlayerInfoCardHUDController()
 18    {
 419        view = PlayerInfoCardHUDView.CreateView();
 420        view.Initialize(() => { OnCloseButtonPressed(); }
 21            , ReportPlayer, BlockPlayer, UnblockPlayer,
 22            AddPlayerAsFriend, CancelInvitation, AcceptFriendRequest, RejectFriendRequest);
 423        currentPlayerId = Resources.Load<StringVariable>(CURRENT_PLAYER_ID);
 424        currentPlayerId.OnChange += OnCurrentPlayerIdChanged;
 425        OnCurrentPlayerIdChanged(currentPlayerId, null);
 26
 427        toggleFriendsTrigger = Resources.Load<InputAction_Trigger>("ToggleFriends");
 428        toggleFriendsTrigger.OnTriggered -= OnCloseButtonPressed;
 429        toggleFriendsTrigger.OnTriggered += OnCloseButtonPressed;
 30
 431        closeWindowTrigger = Resources.Load<InputAction_Trigger>("CloseWindow");
 432        closeWindowTrigger.OnTriggered -= OnCloseButtonPressed;
 433        closeWindowTrigger.OnTriggered += OnCloseButtonPressed;
 34
 435        toggleWorldChatTrigger = Resources.Load<InputAction_Trigger>("ToggleWorldChat");
 436        toggleWorldChatTrigger.OnTriggered -= OnCloseButtonPressed;
 437        toggleWorldChatTrigger.OnTriggered += OnCloseButtonPressed;
 438    }
 39
 240    public void CloseCard() { currentPlayerId.Set(null); }
 41
 042    private void OnCloseButtonPressed(DCLAction_Trigger action = DCLAction_Trigger.CloseWindow) { CloseCard(); }
 43
 44    private void AddPlayerAsFriend()
 45    {
 46// Add fake action to avoid waiting for kernel
 047        UserProfileController.i.AddUserProfileToCatalog(new UserProfileModel()
 48        {
 49            userId = currentPlayerId,
 50            name = currentPlayerId
 51        });
 52
 053        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 54        {
 55            userId = currentPlayerId,
 56            action = FriendshipAction.REQUESTED_TO
 57        });
 058        WebInterface.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 59        {
 60            userId = currentPlayerId, action = FriendshipAction.REQUESTED_TO
 61        });
 062    }
 63
 64    private void CancelInvitation()
 65    {
 66        // Add fake action to avoid waiting for kernel
 067        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 68        {
 69            userId = currentPlayerId,
 70            action = FriendshipAction.CANCELLED
 71        });
 72
 073        WebInterface.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 74        {
 75            userId = currentPlayerId, action = FriendshipAction.CANCELLED
 76        });
 077    }
 78
 79    private void AcceptFriendRequest()
 80    {
 81        // Add fake action to avoid waiting for kernel
 082        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 83        {
 84            userId = currentPlayerId,
 85            action = FriendshipAction.APPROVED
 86        });
 087        WebInterface.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 88        {
 89            userId = currentPlayerId, action = FriendshipAction.APPROVED
 90        });
 091    }
 92
 93    private void RejectFriendRequest()
 94    {
 95// Add fake action to avoid waiting for kernel
 096        FriendsController.i.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 97        {
 98            userId = currentPlayerId,
 99            action = FriendshipAction.REJECTED
 100        });
 0101        WebInterface.UpdateFriendshipStatus(new FriendsController.FriendshipUpdateStatusMessage()
 102        {
 103            userId = currentPlayerId, action = FriendshipAction.REJECTED
 104        });
 0105    }
 106
 107    internal void OnCurrentPlayerIdChanged(string current, string previous)
 108    {
 6109        if (currentUserProfile != null)
 1110            currentUserProfile.OnUpdate -= SetUserProfile;
 111
 6112        currentUserProfile = string.IsNullOrEmpty(currentPlayerId)
 113            ? null
 114            : UserProfileController.userProfilesCatalog.Get(currentPlayerId);
 115
 6116        if (currentUserProfile == null)
 117        {
 4118            view.SetCardActive(false);
 4119        }
 120        else
 121        {
 2122            currentUserProfile.OnUpdate += SetUserProfile;
 2123            SetUserProfile(currentUserProfile);
 2124            view.SetCardActive(true);
 125        }
 2126    }
 127
 4128    private void SetUserProfile(UserProfile userProfile) { view.SetUserProfile(userProfile); }
 129
 2130    public void SetVisibility(bool visible) { view.SetVisibility(visible); }
 131
 132    private void BlockPlayer()
 133    {
 0134        if (ownUserProfile.blocked.Contains(currentUserProfile.userId))
 0135            return;
 136
 0137        ownUserProfile.blocked.Add(currentUserProfile.userId);
 138
 0139        view.SetIsBlocked(true);
 140
 0141        WebInterface.SendBlockPlayer(currentUserProfile.userId);
 0142    }
 143
 144    private void UnblockPlayer()
 145    {
 0146        if (!ownUserProfile.blocked.Contains(currentUserProfile.userId))
 0147            return;
 148
 0149        ownUserProfile.blocked.Remove(currentUserProfile.userId);
 150
 0151        view.SetIsBlocked(false);
 152
 0153        WebInterface.SendUnblockPlayer(currentUserProfile.userId);
 0154    }
 155
 0156    private void ReportPlayer() { WebInterface.SendReportPlayer(currentPlayerId); }
 157
 158    public void Dispose()
 159    {
 4160        if (currentUserProfile != null)
 1161            currentUserProfile.OnUpdate -= SetUserProfile;
 162
 4163        if (currentPlayerId != null)
 4164            currentPlayerId.OnChange -= OnCurrentPlayerIdChanged;
 165
 4166        if (closeWindowTrigger != null)
 4167            closeWindowTrigger.OnTriggered -= OnCloseButtonPressed;
 168
 4169        if (closeWindowTrigger != null)
 4170            closeWindowTrigger.OnTriggered -= OnCloseButtonPressed;
 171
 4172        if (toggleWorldChatTrigger != null)
 4173            toggleWorldChatTrigger.OnTriggered -= OnCloseButtonPressed;
 174
 4175        if (view != null)
 4176            UnityEngine.Object.Destroy(view.gameObject);
 4177    }
 178}