< Summary

Class:UserProfileController
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileController.cs
Covered lines:12
Uncovered lines:35
Coverable lines:47
Total lines:110
Line coverage:25.5% (12 of 47)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Awake()0%110100%
LoadProfile(...)0%12300%
AddUserProfileToCatalog(...)0%2100%
AddUserProfilesToCatalog(...)0%6200%
AddUserProfileToCatalog(...)0%220100%
GetProfileByName(...)0%12300%
GetProfileByUserId(...)0%2100%
RemoveUserProfilesFromCatalog(...)0%6200%
RemoveUserProfileFromCatalog(...)0%6200%
ClearProfilesCatalog()0%6200%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileController.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using UnityEngine;
 4
 5public class UserProfileController : MonoBehaviour
 6{
 5847    public static UserProfileController i { get; private set; }
 8
 9    public event Action OnBaseWereablesFail;
 10
 11    private static UserProfileDictionary userProfilesCatalogValue;
 12    private bool baseWearablesAlreadyRequested = false;
 13
 14    public static UserProfileDictionary userProfilesCatalog
 15    {
 16        get
 17        {
 12118            if (userProfilesCatalogValue == null)
 19            {
 120                userProfilesCatalogValue = Resources.Load<UserProfileDictionary>("UserProfilesCatalog");
 21            }
 22
 12123            return userProfilesCatalogValue;
 24        }
 25    }
 26
 27    [NonSerialized] public UserProfile ownUserProfile;
 28
 29    public void Awake()
 30    {
 1431        i = this;
 1432        ownUserProfile = UserProfile.GetOwnUserProfile();
 1433    }
 34
 35    public void LoadProfile(string payload)
 36    {
 037        if (!baseWearablesAlreadyRequested)
 38        {
 039            baseWearablesAlreadyRequested = true;
 040            CatalogController.RequestBaseWearables()
 41                             .Catch((error) =>
 42                             {
 043                                 OnBaseWereablesFail?.Invoke();
 044                                 Debug.LogError(error);
 045                             });
 46        }
 47
 048        if (payload == null)
 049            return;
 50
 051        var model = JsonUtility.FromJson<UserProfileModel>(payload);
 052        DataStore.i.emotes.newFlowEnabled.Set(model.avatar.version >= 1);
 053        ownUserProfile.UpdateData(model);
 054        userProfilesCatalog.Add(model.userId, ownUserProfile);
 055    }
 56
 057    public void AddUserProfileToCatalog(string payload) { AddUserProfileToCatalog(JsonUtility.FromJson<UserProfileModel>
 58
 59    public void AddUserProfilesToCatalog(string payload)
 60    {
 061        UserProfileModel[] items = JsonUtility.FromJson<UserProfileModel[]>(payload);
 062        int count = items.Length;
 063        for (int i = 0; i < count; ++i)
 64        {
 065            AddUserProfileToCatalog(items[i]);
 66        }
 067    }
 68
 69    public void AddUserProfileToCatalog(UserProfileModel model)
 70    {
 1771        if (!userProfilesCatalog.TryGetValue(model.userId, out UserProfile userProfile))
 572            userProfile = ScriptableObject.CreateInstance<UserProfile>();
 73
 1774        userProfile.UpdateData(model);
 1775        userProfilesCatalog.Add(model.userId, userProfile);
 1776    }
 77
 78    public static UserProfile GetProfileByName(string targetUserName)
 79    {
 080        foreach (var userProfile in userProfilesCatalogValue)
 81        {
 082            if (userProfile.Value.userName.ToLower() == targetUserName.ToLower())
 083                return userProfile.Value;
 84        }
 85
 086        return null;
 087    }
 88
 089    public static UserProfile GetProfileByUserId(string targetUserId) { return userProfilesCatalogValue.Get(targetUserId
 90
 91    public void RemoveUserProfilesFromCatalog(string payload)
 92    {
 093        string[] usernames = JsonUtility.FromJson<string[]>(payload);
 094        for (int index = 0; index < usernames.Length; index++)
 95        {
 096            RemoveUserProfileFromCatalog(userProfilesCatalog.Get(usernames[index]));
 97        }
 098    }
 99
 100    public void RemoveUserProfileFromCatalog(UserProfile userProfile)
 101    {
 0102        if (userProfile == null)
 0103            return;
 104
 0105        userProfilesCatalog.Remove(userProfile.userId);
 0106        Destroy(userProfile);
 0107    }
 108
 0109    public void ClearProfilesCatalog() { userProfilesCatalog?.Clear(); }
 110}