< Summary

Class:DCL.Components.GetAnchorPointsHandler
Assembly:AvatarAttach
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/AvatarAttach/AnchorPointsGetterHandlers/GetAnchorPointsHandler.cs
Covered lines:27
Uncovered lines:2
Coverable lines:29
Total lines:79
Line coverage:93.1% (27 of 29)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
SearchAnchorPoints(...)0%2.012088.89%
CancelCurrentSearch()0%110100%
Dispose()0%110100%
CleanUp()0%220100%
GetHandler(...)0%220100%
OnAvatarFoundEvent(...)0%220100%
OnAvatarRemovedEvent(...)0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/AvatarAttach/AnchorPointsGetterHandlers/GetAnchorPointsHandler.cs

#LineLine coverage
 1using System;
 2
 3namespace DCL.Components
 4{
 5    internal class GetAnchorPointsHandler : IDisposable
 6    {
 7        public event Action OnAvatarRemoved;
 8
 9        private Action<IAvatarAnchorPoints> onAvatarFound;
 10
 1011        private string ownPlayerId => UserProfile.GetOwnUserProfile().userId;
 12
 013        private IAnchorPointsGetterHandler ownPlayerAnchorPointsGetterHandler => new OwnPlayerGetAnchorPointsHandler();
 1514        private IAnchorPointsGetterHandler otherPlayerAnchorPointsGetterHandler => new OtherPlayerGetAnchorPointsHandler
 15        private IAnchorPointsGetterHandler currentAnchorPointsGetterHandler;
 16
 17        /// <summary>
 18        /// Search for an `avatarId` that could be the own player or any other player.
 19        /// If that `avatarId` is loaded it will call `onSuccess`, otherwise it will wait
 20        /// for that `avatarId` to be loaded
 21        /// </summary>
 22        public void SearchAnchorPoints(string avatarId, Action<IAvatarAnchorPoints> onSuccess)
 23        {
 1024            CleanUp();
 25
 1026            if (string.IsNullOrEmpty(avatarId))
 027                return;
 28
 1029            onAvatarFound = onSuccess;
 30
 1031            currentAnchorPointsGetterHandler = GetHandler(avatarId);
 1032            currentAnchorPointsGetterHandler.OnAvatarFound += OnAvatarFoundEvent;
 1033            currentAnchorPointsGetterHandler.OnAvatarRemoved += OnAvatarRemovedEvent;
 1034            currentAnchorPointsGetterHandler.GetAnchorPoints(avatarId);
 1035        }
 36
 37        /// <summary>
 38        /// Cancel the active search/waiting of the `avatarId`
 39        /// </summary>
 40        public void CancelCurrentSearch()
 41        {
 1342            CleanUp();
 1343        }
 44
 45        public void Dispose()
 46        {
 747            CleanUp();
 748            ownPlayerAnchorPointsGetterHandler.Dispose();
 749            otherPlayerAnchorPointsGetterHandler.Dispose();
 750        }
 51
 52        private void CleanUp()
 53        {
 3054            onAvatarFound = null;
 55
 3056            if (currentAnchorPointsGetterHandler != null)
 57            {
 1058                currentAnchorPointsGetterHandler.CleanUp();
 1059                currentAnchorPointsGetterHandler.OnAvatarFound -= OnAvatarFoundEvent;
 1060                currentAnchorPointsGetterHandler.OnAvatarRemoved -= OnAvatarRemovedEvent;
 61            }
 3062        }
 63
 64        private IAnchorPointsGetterHandler GetHandler(string id)
 65        {
 1066            return id == ownPlayerId ? ownPlayerAnchorPointsGetterHandler : otherPlayerAnchorPointsGetterHandler;
 67        }
 68
 69        private void OnAvatarFoundEvent(string id, IAvatarAnchorPoints anchorPoints)
 70        {
 971            onAvatarFound?.Invoke(anchorPoints);
 872        }
 73
 74        private void OnAvatarRemovedEvent(string id)
 75        {
 276            OnAvatarRemoved?.Invoke();
 177        }
 78    }
 79}