< Summary

Class:DCL.Components.GetAnchorPointsHandler
Assembly:DCL.ECSComponents.AvatarAttach
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/ECS7/ECSComponents/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/DCLPlugins/ECS7/ECSComponents/AvatarAttach/AnchorPointsGetterHandlers/GetAnchorPointsHandler.cs

#LineLine coverage
 1using System;
 2
 3namespace DCL.Components
 4{
 5    public class GetAnchorPointsHandler : IDisposable
 6    {
 7        public event Action OnAvatarRemoved;
 8
 9        private Action<IAvatarAnchorPoints> onAvatarFound;
 10
 1511        private string ownPlayerId => UserProfile.GetOwnUserProfile().userId;
 12
 013        private IAnchorPointsGetterHandler ownPlayerAnchorPointsGetterHandler => new OwnPlayerGetAnchorPointsHandler();
 2814        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        {
 1524            CleanUp();
 25
 1526            if (string.IsNullOrEmpty(avatarId))
 027                return;
 28
 1529            onAvatarFound = onSuccess;
 30
 1531            currentAnchorPointsGetterHandler = GetHandler(avatarId);
 1532            currentAnchorPointsGetterHandler.OnAvatarFound += OnAvatarFoundEvent;
 1533            currentAnchorPointsGetterHandler.OnAvatarRemoved += OnAvatarRemovedEvent;
 1534            currentAnchorPointsGetterHandler.GetAnchorPoints(avatarId);
 1535        }
 36
 37        /// <summary>
 38        /// Cancel the active search/waiting of the `avatarId`
 39        /// </summary>
 40        public void CancelCurrentSearch()
 41        {
 2842            CleanUp();
 2843        }
 44
 45        public void Dispose()
 46        {
 1547            CleanUp();
 1548            ownPlayerAnchorPointsGetterHandler.Dispose();
 1549            otherPlayerAnchorPointsGetterHandler.Dispose();
 1550        }
 51
 52        private void CleanUp()
 53        {
 5854            onAvatarFound = null;
 55
 5856            if (currentAnchorPointsGetterHandler != null)
 57            {
 2158                currentAnchorPointsGetterHandler.CleanUp();
 2159                currentAnchorPointsGetterHandler.OnAvatarFound -= OnAvatarFoundEvent;
 2160                currentAnchorPointsGetterHandler.OnAvatarRemoved -= OnAvatarRemovedEvent;
 61            }
 5862        }
 63
 64        private IAnchorPointsGetterHandler GetHandler(string id)
 65        {
 1566            return id == ownPlayerId ? ownPlayerAnchorPointsGetterHandler : otherPlayerAnchorPointsGetterHandler;
 67        }
 68
 69        private void OnAvatarFoundEvent(string id, IAvatarAnchorPoints anchorPoints)
 70        {
 1371            onAvatarFound?.Invoke(anchorPoints);
 1272        }
 73
 74        private void OnAvatarRemovedEvent(string id)
 75        {
 376            OnAvatarRemoved?.Invoke();
 277        }
 78    }
 79}