< 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:77
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
 104214        internal string bodyShapeId = "";
 104215        internal readonly List<string> emotes = new List<string>();
 16
 104217        public EmoteAnimationEquipper(IAnimator animator, DataStore_Emotes dataStoreEmotes)
 18        {
 104219            this.animator = animator;
 104220            this.dataStoreEmotes = dataStoreEmotes;
 104221            this.dataStoreEmotes.animations.OnAdded += OnAnimationAdded;
 104222            this.dataStoreEmotes.animations.OnRemoved += OnAnimationRemoved;
 104223        }
 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;
 32
 133            animator.EquipEmote(values.emoteId, emoteClipData);
 134        }
 35
 36        private void OnAnimationRemoved((string bodyshapeId, string emoteId) values, EmoteClipData emoteClipData)
 37        {
 038            if (bodyShapeId != values.bodyshapeId)
 039                return;
 40
 041            animator.UnequipEmote(values.emoteId);
 042        }
 43
 44        public void SetEquippedEmotes(string bodyShapeId, IEnumerable<WearableItem> newEmotes)
 45        {
 446            this.bodyShapeId = bodyShapeId;
 3247            foreach (WearableItem emote in newEmotes)
 48            {
 1249                dataStoreEmotes.emotesOnUse.IncreaseRefCount((bodyShapeId, emote.id));
 50
 51                //If the clip is not ready by the time we equip it
 52                //we will receive it once its added to the collection in the DataStore
 1253                if (dataStoreEmotes.animations.TryGetValue((this.bodyShapeId, emote.id),
 54                        out EmoteClipData emoteClipData))
 255                    animator.EquipEmote(emote.id, emoteClipData);
 56            }
 57
 1458            foreach (string emoteId in this.emotes)
 59            {
 360                dataStoreEmotes.emotesOnUse.DecreaseRefCount((this.bodyShapeId, emoteId));
 61            }
 462            this.emotes.Clear();
 1663            this.emotes.AddRange(newEmotes.Select(e => e.id));
 464        }
 65
 66        public void Dispose()
 67        {
 768            dataStoreEmotes.animations.OnAdded -= OnAnimationAdded;
 769            dataStoreEmotes.animations.OnRemoved -= OnAnimationRemoved;
 5070            foreach (string emoteId in this.emotes)
 71            {
 1872                dataStoreEmotes.emotesOnUse.DecreaseRefCount((bodyShapeId, emoteId));
 73            }
 774            emotes.Clear();
 775        }
 76    }
 77}