< Summary

Class:FriendTracker
Assembly:ExploreV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Common/Friends/FriendTracker.cs
Covered lines:0
Uncovered lines:38
Coverable lines:38
Total lines:84
Line coverage:0% (0 of 38)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
FriendTracker(...)0%2100%
SetStatus(...)0%2100%
AddListener(...)0%2100%
RemoveListener(...)0%2100%
HasListeners()0%2100%
HasChangedLocation(...)0%12300%
RemoveAllListeners()0%12300%
IsOnline()0%12300%
OnListenerDisposed(...)0%2100%
OnListenerRemoved(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/ExploreV2/Scripts/Common/Friends/FriendTracker.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using UnityEngine;
 4
 5class FriendTracker
 6{
 07    HashSet<TrackedSceneInfo> friendListeners = new HashSet<TrackedSceneInfo>();
 8
 09    public UserProfile profile { private set; get; }
 010    public FriendsController.UserStatus status { private set; get; }
 11    Color backgroundColor;
 12
 013    public FriendTracker(string userId, Color backgroundColor)
 14    {
 015        profile = UserProfileController.userProfilesCatalog.Get(userId);
 016        this.backgroundColor = backgroundColor;
 017    }
 18
 019    public void SetStatus(FriendsController.UserStatus newStatus) { status = newStatus; }
 20
 21    public void AddListener(TrackedSceneInfo listener)
 22    {
 023        listener.OnListenerDisposed += OnListenerDisposed;
 024        friendListeners.Add(listener);
 025        listener.OnFriendAdded(profile, backgroundColor);
 026    }
 27
 28    public void RemoveListener(TrackedSceneInfo listener)
 29    {
 030        OnListenerRemoved(listener);
 031        friendListeners.Remove(listener);
 032    }
 33
 034    public bool HasListeners() { return friendListeners.Count > 0; }
 35
 36    public bool HasChangedLocation(Vector2Int coords)
 37    {
 038        if (friendListeners.Count > 0 && friendListeners.First().ContainCoords(coords))
 39        {
 040            return false;
 41        }
 42
 043        return true;
 44    }
 45
 46    public void RemoveAllListeners()
 47    {
 048        if (!HasListeners())
 49        {
 050            return;
 51        }
 52
 053        using (var listenerIterator = friendListeners.GetEnumerator())
 54        {
 055            while (listenerIterator.MoveNext())
 56            {
 057                OnListenerRemoved(listenerIterator.Current);
 58            }
 059        }
 60
 061        friendListeners.Clear();
 062    }
 63
 64    public bool IsOnline()
 65    {
 066        if (status.presence != PresenceStatus.ONLINE)
 067            return false;
 068        if (status.realm == null)
 069            return false;
 070        return !string.IsNullOrEmpty(status.realm.serverName);
 71    }
 72
 73    void OnListenerDisposed(TrackedSceneInfo listener)
 74    {
 075        listener.OnListenerDisposed -= OnListenerDisposed;
 076        friendListeners.Remove(listener);
 077    }
 78
 79    void OnListenerRemoved(TrackedSceneInfo listener)
 80    {
 081        listener.OnListenerDisposed -= OnListenerDisposed;
 082        listener.OnFriendRemoved(profile);
 083    }
 84}