< Summary

Class:AvatarModel
Assembly:AvatarModel
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Models/AvatarModel/AvatarModel.cs
Covered lines:32
Uncovered lines:8
Coverable lines:40
Total lines:116
Line coverage:80% (32 of 40)
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%12120100%
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;
 197623    public List<string> wearables = new List<string>();
 24
 197625    public List<AvatarEmoteEntry> emotes = new List<AvatarEmoteEntry>();
 26
 27    public string expressionTriggerId = null;
 197628    public long expressionTriggerTimestamp = -1;
 29    public string stickerTriggerId = null;
 197630    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    {
 8277        if (other == null) return false;
 78
 4079        bool wearablesAreEqual = wearables.All(other.wearables.Contains)
 80                                 && other.wearables.All(wearables.Contains)
 81                                 && wearables.Count == other.wearables.Count;
 82
 4083        return id == other.id &&
 84               name == other.name &&
 85               bodyShape == other.bodyShape &&
 86               skinColor == other.skinColor &&
 87               hairColor == other.hairColor &&
 88               eyeColor == other.eyeColor &&
 89               expressionTriggerId == other.expressionTriggerId &&
 90               expressionTriggerTimestamp == other.expressionTriggerTimestamp &&
 91               stickerTriggerTimestamp == other.stickerTriggerTimestamp &&
 92               wearablesAreEqual;
 93    }
 94
 95    public void CopyFrom(AvatarModel other)
 96    {
 65997        if (other == null)
 57598            return;
 99
 84100        id = other.id;
 84101        name = other.name;
 84102        bodyShape = other.bodyShape;
 84103        skinColor = other.skinColor;
 84104        hairColor = other.hairColor;
 84105        eyeColor = other.eyeColor;
 84106        expressionTriggerId = other.expressionTriggerId;
 84107        expressionTriggerTimestamp = other.expressionTriggerTimestamp;
 84108        stickerTriggerId = other.stickerTriggerId;
 84109        stickerTriggerTimestamp = other.stickerTriggerTimestamp;
 84110        wearables = new List<string>(other.wearables);
 84111        emotes = other.emotes.Select(x => new AvatarEmoteEntry() { slot = x.slot, urn = x.urn }).ToList();
 84112    }
 113
 5114    public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<AvatarModel>(json); }
 115
 116}