< 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:75
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 UnityEngine;
 5
 6namespace AvatarSystem
 7{
 8    public class EmoteAnimationEquipper : IEmoteAnimationEquipper
 9    {
 10        internal readonly IAnimator animator;
 11        internal readonly DataStore_Emotes dataStoreEmotes;
 12
 102213        internal string bodyShapeId = "";
 102214        internal readonly List<string> emotes = new List<string>();
 15
 102216        public EmoteAnimationEquipper(IAnimator animator, DataStore_Emotes dataStoreEmotes)
 17        {
 102218            this.animator = animator;
 102219            this.dataStoreEmotes = dataStoreEmotes;
 102220            this.dataStoreEmotes.animations.OnAdded += OnAnimationAdded;
 102221            this.dataStoreEmotes.animations.OnRemoved += OnAnimationRemoved;
 102222        }
 23
 24        private void OnAnimationAdded((string bodyshapeId, string emoteId) values, AnimationClip animationClip)
 25        {
 426            if (bodyShapeId != values.bodyshapeId)
 327                return;
 28
 129            if (!emotes.Contains(values.emoteId))
 030                return;
 31
 132            animator.EquipEmote(values.emoteId, animationClip);
 133        }
 34
 35        private void OnAnimationRemoved((string bodyshapeId, string emoteId) values, AnimationClip animationClip)
 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), out AnimationClip clip))
 253                    animator.EquipEmote(emote.id, clip);
 54            }
 55
 1456            foreach (string emoteId in this.emotes)
 57            {
 358                dataStoreEmotes.emotesOnUse.DecreaseRefCount((this.bodyShapeId, emoteId));
 59            }
 460            this.emotes.Clear();
 1661            this.emotes.AddRange(newEmotes.Select(e => e.id));
 462        }
 63
 64        public void Dispose()
 65        {
 766            dataStoreEmotes.animations.OnAdded -= OnAnimationAdded;
 767            dataStoreEmotes.animations.OnRemoved -= OnAnimationRemoved;
 5068            foreach (string emoteId in this.emotes)
 69            {
 1870                dataStoreEmotes.emotesOnUse.DecreaseRefCount((bodyShapeId, emoteId));
 71            }
 772            emotes.Clear();
 773        }
 74    }
 75}