< Summary

Class:UserProfileController
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfileController.cs
Covered lines:14
Uncovered lines:31
Coverable lines:45
Total lines:106
Line coverage:31.1% (14 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{
 06    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        {
 22817            if (userProfilesCatalogValue == null)
 18            {
 119                userProfilesCatalogValue = Resources.Load<UserProfileDictionary>("UserProfilesCatalog");
 20            }
 21
 22822            return userProfilesCatalogValue;
 23        }
 24    }
 25
 26    [NonSerialized] public UserProfile ownUserProfile;
 27
 28    public void Awake()
 29    {
 13030        i = this;
 13031        ownUserProfile = UserProfile.GetOwnUserProfile();
 13032    }
 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    {
 7069        var userProfile = ScriptableObject.CreateInstance<UserProfile>();
 7070        userProfile.UpdateData(model);
 7071        userProfilesCatalog.Add(model.userId, userProfile);
 7072    }
 73
 74    public static UserProfile GetProfileByName(string targetUserName)
 75    {
 1676        foreach (var userProfile in userProfilesCatalogValue)
 77        {
 778            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
 26105    public void ClearProfilesCatalog() { userProfilesCatalog?.Clear(); }
 106}