< Summary

Class:AvatarSystem.EmoteAnimationEquipper
Assembly:AvatarSystem
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/AvatarSystem/EmoteAnimationEquipper.cs
Covered lines:29
Uncovered lines:5
Coverable lines:34
Total lines:76
Line coverage:85.2% (29 of 34)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmoteAnimationEquipper(...)0%110100%
OnAnimationAdded(...)0%3.043083.33%
OnAnimationRemoved(...)0%6200%
SetEquippedEmotes(...)0%660100%
Dispose()0%220100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using System.Linq;
 3using DCL;
 4using DCL.Emotes;
 5using UnityEngine;
 6
 7namespace AvatarSystem
 8{
 9    public class EmoteAnimationEquipper : IEmoteAnimationEquipper
 10    {
 11        internal readonly IAnimator animator;
 12        internal readonly DataStore_Emotes dataStoreEmotes;
 13
 66914        internal string bodyShapeId = "";
 66915        internal readonly List<string> emotes = new List<string>();
 16
 66917        public EmoteAnimationEquipper(IAnimator animator, DataStore_Emotes dataStoreEmotes)
 18        {
 66919            this.animator = animator;
 66920            this.dataStoreEmotes = dataStoreEmotes;
 66921            this.dataStoreEmotes.animations.OnAdded += OnAnimationAdded;
 66922            this.dataStoreEmotes.animations.OnRemoved += OnAnimationRemoved;
 66923        }
 24
 25        private void OnAnimationAdded((string bodyshapeId, string emoteId) values, EmoteClipData emoteClipData)
 26        {
 427            if (bodyShapeId != values.bodyshapeId)
 328                return;
 29
 130            if (!emotes.Contains(values.emoteId))
 031                return;
 132            animator.EquipEmote(values.emoteId, emoteClipData);
 133        }
 34
 35        private void OnAnimationRemoved((string bodyshapeId, string emoteId) values, EmoteClipData emoteClipData)
 36        {
 037            if (bodyShapeId != values.bodyshapeId)
 038                return;
 39
 040            animator.UnequipEmote(values.emoteId);
 041        }
 42
 43        public void SetEquippedEmotes(string bodyShapeId, IEnumerable<WearableItem> newEmotes)
 44        {
 445            this.bodyShapeId = bodyShapeId;
 3246            foreach (WearableItem emote in newEmotes)
 47            {
 1248                dataStoreEmotes.emotesOnUse.IncreaseRefCount((bodyShapeId, emote.id));
 49
 50                //If the clip is not ready by the time we equip it
 51                //we will receive it once its added to the collection in the DataStore
 1252                if (dataStoreEmotes.animations.TryGetValue((this.bodyShapeId, emote.id),
 53                        out EmoteClipData emoteClipData))
 254                    animator.EquipEmote(emote.id, emoteClipData);
 55            }
 56
 1457            foreach (string emoteId in this.emotes)
 58            {
 359                dataStoreEmotes.emotesOnUse.DecreaseRefCount((this.bodyShapeId, emoteId));
 60            }
 461            this.emotes.Clear();
 1662            this.emotes.AddRange(newEmotes.Select(e => e.id));
 463        }
 64
 65        public void Dispose()
 66        {
 767            dataStoreEmotes.animations.OnAdded -= OnAnimationAdded;
 768            dataStoreEmotes.animations.OnRemoved -= OnAnimationRemoved;
 5069            foreach (string emoteId in this.emotes)
 70            {
 1871                dataStoreEmotes.emotesOnUse.DecreaseRefCount((bodyShapeId, emoteId));
 72            }
 773            emotes.Clear();
 774        }
 75    }
 76}