< Summary

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

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
AvatarModel()0%110100%
HaveSameWearablesAndColors(...)0%38.4716055.56%
HaveSameExpressions(...)0%12300%
Equals(...)0%1101000%
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;
 222623    public List<string> wearables = new List<string>();
 24
 25    // if version < 1 Emotes are contained in wearables instead of the emotes propery.
 26    public int version = 0;
 222627    public List<AvatarEmoteEntry> emotes = new List<AvatarEmoteEntry>();
 28
 29    public string expressionTriggerId = null;
 222630    public long expressionTriggerTimestamp = -1;
 31    public string stickerTriggerId = null;
 222632    public long stickerTriggerTimestamp = -1;
 33    public bool talking = false;
 34
 35    public bool HaveSameWearablesAndColors(AvatarModel other)
 36    {
 537        if (other == null)
 038            return false;
 39
 40        //wearables are the same
 541        if (!(wearables.Count == other.wearables.Count && wearables.All(other.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) && wearables.Count == other.wearables.Count;
 78
 079        return id == other.id &&
 80               name == other.name &&
 81               bodyShape == other.bodyShape &&
 82               skinColor == other.skinColor &&
 83               hairColor == other.hairColor &&
 84               eyeColor == other.eyeColor &&
 85               expressionTriggerId == other.expressionTriggerId &&
 86               expressionTriggerTimestamp == other.expressionTriggerTimestamp &&
 87               stickerTriggerTimestamp == other.stickerTriggerTimestamp &&
 88               wearablesAreEqual;
 89    }
 90
 91    public void CopyFrom(AvatarModel other)
 92    {
 56093        if (other == null)
 47694            return;
 95
 8496        id = other.id;
 8497        name = other.name;
 8498        bodyShape = other.bodyShape;
 8499        skinColor = other.skinColor;
 84100        hairColor = other.hairColor;
 84101        eyeColor = other.eyeColor;
 84102        expressionTriggerId = other.expressionTriggerId;
 84103        expressionTriggerTimestamp = other.expressionTriggerTimestamp;
 84104        stickerTriggerId = other.stickerTriggerId;
 84105        stickerTriggerTimestamp = other.stickerTriggerTimestamp;
 84106        wearables = new List<string>(other.wearables);
 84107        emotes = other.emotes.Select(x => new AvatarEmoteEntry() { slot = x.slot, urn = x.urn }).ToList();
 84108        version = other.version;
 84109    }
 110
 5111    public override BaseModel GetDataFromJSON(string json) { return Utils.SafeFromJson<AvatarModel>(json); }
 112}