< Summary

Class:AvatarModel
Assembly:AvatarModel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Models/AvatarModel/AvatarModel.cs
Covered lines:29
Uncovered lines:10
Coverable lines:39
Total lines:115
Line coverage:74.3% (29 of 39)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarModel()0%110100%
HaveSameWearablesAndColors(...)0%42.3617055.56%
HaveSameExpressions(...)0%12300%
Equals(...)0%1321100%
CopyFrom(...)0%330100%
GetDataFromJSON(...)0%110100%

File(s)

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

#LineLine coverage
 1using System;
 2using DCL.Helpers;
 3using System.Collections.Generic;
 4using System.Linq;
 5using UnityEngine;
 6
 7[Serializable]
 8public class AvatarModel : BaseModel
 9{
 10    [Serializable]
 11    public class AvatarEmoteEntry
 12    {
 13        public int slot;
 14        public string urn;
 15    }
 16
 17    public string id;
 18    public string name;
 19    public string bodyShape;
 20    public Color skinColor;
 21    public Color hairColor;
 22    public Color eyeColor;
 223223    public List<string> wearables = new List<string>();
 24
 223225    public List<AvatarEmoteEntry> emotes = new List<AvatarEmoteEntry>();
 26
 27    public string expressionTriggerId = null;
 223228    public long expressionTriggerTimestamp = -1;
 29    public string stickerTriggerId = null;
 223230    public long stickerTriggerTimestamp = -1;
 31    public bool talking = false;
 32
 33    public bool HaveSameWearablesAndColors(AvatarModel other)
 34    {
 535        if (other == null)
 036            return false;
 37
 38        //wearables are the same
 539        if (!(wearables.Count == other.wearables.Count
 40              && wearables.All(other.wearables.Contains)
 41              && other.wearables.All(wearables.Contains)))
 442            return false;
 43
 44        //emotes are the same
 145        if (emotes == null && other.emotes != null)
 046            return false;
 147        if (emotes != null && other.emotes == null)
 048            return false;
 149        if (emotes != null && other.emotes != null)
 50        {
 151            if (emotes.Count != other.emotes.Count)
 052                return false;
 53
 254            for (var i = 0; i < emotes.Count; i++)
 55            {
 056                AvatarEmoteEntry emote = emotes[i];
 057                if (other.emotes.FirstOrDefault(x => x.urn == emote.urn) == null)
 058                    return false;
 59            }
 60        }
 61
 162        return bodyShape == other.bodyShape &&
 63               skinColor == other.skinColor &&
 64               hairColor == other.hairColor &&
 65               eyeColor == other.eyeColor;
 66    }
 67
 68    public bool HaveSameExpressions(AvatarModel other)
 69    {
 070        return expressionTriggerId == other.expressionTriggerId &&
 71               expressionTriggerTimestamp == other.expressionTriggerTimestamp &&
 72               stickerTriggerTimestamp == other.stickerTriggerTimestamp;
 73    }
 74
 75    public bool Equals(AvatarModel other)
 76    {
 077        bool wearablesAreEqual = wearables.All(other.wearables.Contains)
 78                                 && other.wearables.All(wearables.Contains)
 79                                 && wearables.Count == other.wearables.Count;
 80
 081        return id == other.id &&
 82               name == other.name &&
 83               bodyShape == other.bodyShape &&
 84               skinColor == other.skinColor &&
 85               hairColor == other.hairColor &&
 86               eyeColor == other.eyeColor &&
 87               expressionTriggerId == other.expressionTriggerId &&
 88               expressionTriggerTimestamp == other.expressionTriggerTimestamp &&
 89               stickerTriggerTimestamp == other.stickerTriggerTimestamp &&
 90               wearablesAreEqual;
 91    }
 92
 93    public void CopyFrom(AvatarModel other)
 94    {
 56095        if (other == null)
 47696            return;
 97
 8498        id = other.id;
 8499        name = other.name;
 84100        bodyShape = other.bodyShape;
 84101        skinColor = other.skinColor;
 84102        hairColor = other.hairColor;
 84103        eyeColor = other.eyeColor;
 84104        expressionTriggerId = other.expressionTriggerId;
 84105        expressionTriggerTimestamp = other.expressionTriggerTimestamp;
 84106        stickerTriggerId = other.stickerTriggerId;
 84107        stickerTriggerTimestamp = other.stickerTriggerTimestamp;
 84108        wearables = new List<string>(other.wearables);
 84109        emotes = other.emotes.Select(x => new AvatarEmoteEntry() { slot = x.slot, urn = x.urn }).ToList();
 110
 111
 84112    }
 113
 5114    public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<AvatarModel>(json); }
 115}