< Summary

Class:UserProfile
Assembly:UserProfile
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/UserProfile/UserProfile.cs
Covered lines:50
Uncovered lines:21
Coverable lines:71
Total lines:140
Line coverage:70.4% (50 of 71)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
UserProfile()0%2100%
UserProfile()0%110100%
UpdateData(...)0%5.015091.67%
GetItemAmount(...)0%330100%
OverrideAvatar(...)0%220100%
SetAvatarExpression(...)0%330100%
SetInventory(...)0%440100%
GetInventoryItemsIds()0%2100%
GetOwnUserProfile()0%220100%
CloneModel()0%2100%
OnEnable()0%110100%
CleanUp()0%6200%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using DCL;
 5using DCL.Helpers;
 6using DCL.Interface;
 7using UnityEngine;
 8
 9[CreateAssetMenu(fileName = "UserProfile", menuName = "UserProfile")]
 10public class UserProfile : ScriptableObject //TODO Move to base variable
 11{
 012    static DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
 13    public event Action<UserProfile> OnUpdate;
 14    public event Action<string, long> OnAvatarExpressionSet;
 15
 016    public string userId => model.userId;
 017    public string ethAddress => model.ethAddress;
 018    public string userName => model.name;
 019    public string description => model.description;
 020    public string email => model.email;
 021    public string bodySnapshotURL => model.snapshots.body;
 022    public string face128SnapshotURL => model.snapshots.face128;
 023    public UserProfileModel.ParcelsWithAccess[] parcelsWithAccess => model.parcelsWithAccess;
 9424    public List<string> blocked => model.blocked != null ? model.blocked : new List<string>();
 325    public List<string> muted => model.muted ?? new List<string>();
 026    public bool hasConnectedWeb3 => model.hasConnectedWeb3;
 027    public bool hasClaimedName => model.hasClaimedName;
 028    public AvatarModel avatar => model.avatar;
 029    public int tutorialStep => model.tutorialStep;
 30
 11831    internal Dictionary<string, int> inventory = new Dictionary<string, int>();
 32
 11833    public ILazyTextureObserver snapshotObserver = new LazyTextureObserver();
 34
 11835    internal UserProfileModel model = new UserProfileModel() //Empty initialization to avoid nullchecks
 36    {
 37        avatar = new AvatarModel()
 38    };
 39
 40    public void UpdateData(UserProfileModel newModel)
 41    {
 17542        if (newModel == null)
 43        {
 044            model = null;
 045            return;
 46        }
 47
 17548        bool faceSnapshotDirty = model.snapshots.face256 != newModel.snapshots.face256;
 49
 17550        model.userId = newModel.userId;
 17551        model.ethAddress = newModel.ethAddress;
 17552        model.parcelsWithAccess = newModel.parcelsWithAccess;
 17553        model.tutorialStep = newModel.tutorialStep;
 17554        model.hasClaimedName = newModel.hasClaimedName;
 17555        model.name = newModel.name;
 17556        model.email = newModel.email;
 17557        model.description = newModel.description;
 17558        model.avatar.CopyFrom(newModel.avatar);
 17559        model.snapshots = newModel.snapshots;
 17560        model.hasConnectedWeb3 = newModel.hasConnectedWeb3;
 17561        model.inventory = newModel.inventory;
 17562        model.blocked = newModel.blocked;
 17563        model.muted = newModel.muted;
 64
 17565        if (model.inventory != null)
 66        {
 1267            SetInventory(model.inventory);
 68        }
 69
 17570        if (model.snapshots != null && faceSnapshotDirty)
 71        {
 572            this.snapshotObserver.RefreshWithUri(model.snapshots.face256);
 73        }
 74
 17575        OnUpdate?.Invoke(this);
 5976    }
 77
 78    public int GetItemAmount(string itemId)
 79    {
 499280        if (inventory == null || !inventory.ContainsKey(itemId))
 495881            return 0;
 82
 3483        return inventory[itemId];
 84    }
 85
 86    public void OverrideAvatar(AvatarModel newModel, Texture2D newFaceSnapshot)
 87    {
 188        model.avatar.CopyFrom(newModel);
 189        this.snapshotObserver.RefreshWithTexture(newFaceSnapshot);
 90
 191        OnUpdate?.Invoke(this);
 192    }
 93
 94    public void SetAvatarExpression(string id)
 95    {
 296        var timestamp = (long) (DateTime.UtcNow - epochStart).TotalMilliseconds;
 297        avatar.expressionTriggerId = id;
 298        avatar.expressionTriggerTimestamp = timestamp;
 299        WebInterface.SendExpression(id, timestamp);
 2100        OnUpdate?.Invoke(this);
 2101        OnAvatarExpressionSet?.Invoke(id, timestamp);
 2102    }
 103
 104    public void SetInventory(string[] inventoryIds)
 105    {
 44106        inventory.Clear();
 269107        inventory = inventoryIds.GroupBy(x => x).ToDictionary(x => x.Key, x => x.Count());
 44108    }
 109
 0110    public string[] GetInventoryItemsIds() { return inventory.Keys.ToArray(); }
 111
 112    internal static UserProfile ownUserProfile;
 113
 114    public static UserProfile GetOwnUserProfile()
 115    {
 1575116        if (ownUserProfile == null)
 117        {
 1118            ownUserProfile = Resources.Load<UserProfile>("ScriptableObjects/OwnUserProfile");
 119        }
 120
 1575121        return ownUserProfile;
 122    }
 123
 0124    public UserProfileModel CloneModel() => model.Clone();
 125
 126#if UNITY_EDITOR
 127    private void OnEnable()
 128    {
 118129        Application.quitting -= CleanUp;
 118130        Application.quitting += CleanUp;
 118131    }
 132
 133    private void CleanUp()
 134    {
 0135        Application.quitting -= CleanUp;
 0136        if (UnityEditor.AssetDatabase.Contains(this))
 0137            Resources.UnloadAsset(this);
 0138    }
 139#endif
 140}