< Summary

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

Metrics

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

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/ExploreHUD/Scripts/Friends/FriendTracker.cs

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using UnityEngine;
 4
 5class FriendTracker
 6{
 37    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
 313    public FriendTracker(string userId, Color backgroundColor)
 14    {
 315        profile = UserProfileController.userProfilesCatalog.Get(userId);
 316        this.backgroundColor = backgroundColor;
 317    }
 18
 019    public void SetStatus(FriendsController.UserStatus newStatus) { status = newStatus; }
 20
 21    public void AddListener(TrackedSceneInfo listener)
 22    {
 223        listener.OnListenerDisposed += OnListenerDisposed;
 224        friendListeners.Add(listener);
 225        listener.OnFriendAdded(profile, backgroundColor);
 226    }
 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    {
 238        if (friendListeners.Count > 0 && friendListeners.First().ContainCoords(coords))
 39        {
 040            return false;
 41        }
 42
 243        return true;
 44    }
 45
 46    public void RemoveAllListeners()
 47    {
 548        if (!HasListeners())
 49        {
 350            return;
 51        }
 52
 253        using (var listenerIterator = friendListeners.GetEnumerator())
 54        {
 455            while (listenerIterator.MoveNext())
 56            {
 257                OnListenerRemoved(listenerIterator.Current);
 58            }
 259        }
 60
 261        friendListeners.Clear();
 262    }
 63
 64    public bool IsOnline()
 65    {
 1466        if (status.presence != PresenceStatus.ONLINE)
 567            return false;
 968        if (status.realm == null)
 069            return false;
 970        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    {
 281        listener.OnListenerDisposed -= OnListenerDisposed;
 282        listener.OnFriendRemoved(profile);
 283    }
 84}