< 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:34
Coverable lines:46
Total lines:108
Line coverage:26% (12 of 46)
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 UnityEngine;
 3
 4public class UserProfileController : MonoBehaviour
 5{
 5676    public static UserProfileController i { get; private set; }
 7
 8    public event Action OnBaseWereablesFail;
 9
 10    private static UserProfileDictionary userProfilesCatalogValue;
 11    private bool baseWearablesAlreadyRequested = false;
 12
 13    public static UserProfileDictionary userProfilesCatalog
 14    {
 15        get
 16        {
 12117            if (userProfilesCatalogValue == null)
 18            {
 119                userProfilesCatalogValue = Resources.Load<UserProfileDictionary>("UserProfilesCatalog");
 20            }
 21
 12122            return userProfilesCatalogValue;
 23        }
 24    }
 25
 26    [NonSerialized] public UserProfile ownUserProfile;
 27
 28    public void Awake()
 29    {
 1430        i = this;
 1431        ownUserProfile = UserProfile.GetOwnUserProfile();
 1432    }
 33
 34    public void LoadProfile(string payload)
 35    {
 036        if (!baseWearablesAlreadyRequested)
 37        {
 038            baseWearablesAlreadyRequested = true;
 039            CatalogController.RequestBaseWearables()
 40                             .Catch((error) =>
 41                             {
 042                                 OnBaseWereablesFail?.Invoke();
 043                                 Debug.LogError(error);
 044                             });
 45        }
 46
 047        if (payload == null)
 048            return;
 49
 050        var model = JsonUtility.FromJson<UserProfileModel>(payload);
 051        ownUserProfile.UpdateData(model);
 052        userProfilesCatalog.Add(model.userId, ownUserProfile);
 053    }
 54
 055    public void AddUserProfileToCatalog(string payload) { AddUserProfileToCatalog(JsonUtility.FromJson<UserProfileModel>
 56
 57    public void AddUserProfilesToCatalog(string payload)
 58    {
 059        UserProfileModel[] items = JsonUtility.FromJson<UserProfileModel[]>(payload);
 060        int count = items.Length;
 061        for (int i = 0; i < count; ++i)
 62        {
 063            AddUserProfileToCatalog(items[i]);
 64        }
 065    }
 66
 67    public void AddUserProfileToCatalog(UserProfileModel model)
 68    {
 1769        if (!userProfilesCatalog.TryGetValue(model.userId, out UserProfile userProfile))
 570            userProfile = ScriptableObject.CreateInstance<UserProfile>();
 71
 1772        userProfile.UpdateData(model);
 1773        userProfilesCatalog.Add(model.userId, userProfile);
 1774    }
 75
 76    public static UserProfile GetProfileByName(string targetUserName)
 77    {
 078        foreach (var userProfile in userProfilesCatalogValue)
 79        {
 080            if (userProfile.Value.userName.ToLower() == targetUserName.ToLower())
 081                return userProfile.Value;
 82        }
 83
 084        return null;
 085    }
 86
 087    public static UserProfile GetProfileByUserId(string targetUserId) { return userProfilesCatalogValue.Get(targetUserId
 88
 89    public void RemoveUserProfilesFromCatalog(string payload)
 90    {
 091        string[] usernames = JsonUtility.FromJson<string[]>(payload);
 092        for (int index = 0; index < usernames.Length; index++)
 93        {
 094            RemoveUserProfileFromCatalog(userProfilesCatalog.Get(usernames[index]));
 95        }
 096    }
 97
 98    public void RemoveUserProfileFromCatalog(UserProfile userProfile)
 99    {
 0100        if (userProfile == null)
 0101            return;
 102
 0103        userProfilesCatalog.Remove(userProfile.userId);
 0104        Destroy(userProfile);
 0105    }
 106
 0107    public void ClearProfilesCatalog() { userProfilesCatalog?.Clear(); }
 108}