< Summary

Class:UserProfileController
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileController.cs
Covered lines:15
Uncovered lines:30
Coverable lines:45
Total lines:106
Line coverage:33.3% (15 of 45)
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%110100%
GetProfileByName(...)0%3.213071.43%
GetProfileByUserId(...)0%2100%
RemoveUserProfilesFromCatalog(...)0%6200%
RemoveUserProfileFromCatalog(...)0%6200%
ClearProfilesCatalog()0%220100%

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{
 5726    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        {
 20417            if (userProfilesCatalogValue == null)
 18            {
 119                userProfilesCatalogValue = Resources.Load<UserProfileDictionary>("UserProfilesCatalog");
 20            }
 21
 20422            return userProfilesCatalogValue;
 23        }
 24    }
 25
 26    [NonSerialized] public UserProfile ownUserProfile;
 27
 28    public void Awake()
 29    {
 3930        i = this;
 3931        ownUserProfile = UserProfile.GetOwnUserProfile();
 3932    }
 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    {
 5969        var userProfile = ScriptableObject.CreateInstance<UserProfile>();
 5970        userProfile.UpdateData(model);
 5971        userProfilesCatalog.Add(model.userId, userProfile);
 5972    }
 73
 74    public static UserProfile GetProfileByName(string targetUserName)
 75    {
 1076        foreach (var userProfile in userProfilesCatalogValue)
 77        {
 478            if (userProfile.Value.userName.ToLower() == targetUserName.ToLower())
 079                return userProfile.Value;
 80        }
 81
 182        return null;
 083    }
 84
 085    public static UserProfile GetProfileByUserId(string targetUserId) { return userProfilesCatalogValue.Get(targetUserId
 86
 87    public void RemoveUserProfilesFromCatalog(string payload)
 88    {
 089        string[] usernames = JsonUtility.FromJson<string[]>(payload);
 090        for (int index = 0; index < usernames.Length; index++)
 91        {
 092            RemoveUserProfileFromCatalog(userProfilesCatalog.Get(usernames[index]));
 93        }
 094    }
 95
 96    public void RemoveUserProfileFromCatalog(UserProfile userProfile)
 97    {
 098        if (userProfile == null)
 099            return;
 100
 0101        userProfilesCatalog.Remove(userProfile.userId);
 0102        Destroy(userProfile);
 0103    }
 104
 14105    public void ClearProfilesCatalog() { userProfilesCatalog?.Clear(); }
 106}