< 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:74
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%550100%
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 DCL;
 3using UnityEngine;
 4
 5namespace AvatarSystem
 6{
 7    public class EmoteAnimationEquipper : IEmoteAnimationEquipper
 8    {
 9        internal readonly IAnimator animator;
 10        internal readonly DataStore_Emotes dataStoreEmotes;
 11
 131112        internal string bodyShapeId = "";
 131113        internal readonly List<string> emotes = new List<string>();
 14
 131115        public EmoteAnimationEquipper(IAnimator animator, DataStore_Emotes dataStoreEmotes)
 16        {
 131117            this.animator = animator;
 131118            this.dataStoreEmotes = dataStoreEmotes;
 131119            this.dataStoreEmotes.animations.OnAdded += OnAnimationAdded;
 131120            this.dataStoreEmotes.animations.OnRemoved += OnAnimationRemoved;
 131121        }
 22
 23        private void OnAnimationAdded((string bodyshapeId, string emoteId) values, AnimationClip animationClip)
 24        {
 425            if (bodyShapeId != values.bodyshapeId)
 326                return;
 27
 128            if (!emotes.Contains(values.emoteId))
 029                return;
 30
 131            animator.EquipEmote(values.emoteId, animationClip);
 132        }
 33
 34        private void OnAnimationRemoved((string bodyshapeId, string emoteId) values, AnimationClip animationClip)
 35        {
 036            if (bodyShapeId != values.bodyshapeId)
 037                return;
 38
 039            animator.UnequipEmote(values.emoteId);
 040        }
 41
 42        public void SetEquippedEmotes(string bodyShapeId, IEnumerable<WearableItem> emotes)
 43        {
 444            this.bodyShapeId = bodyShapeId;
 1445            foreach (string emoteId in this.emotes)
 46            {
 347                dataStoreEmotes.emotesOnUse.DecreaseRefCount(emoteId);
 48            }
 449            this.emotes.Clear();
 50
 3251            foreach (WearableItem emote in emotes)
 52            {
 1253                this.emotes.Add(emote.id);
 1254                dataStoreEmotes.emotesOnUse.IncreaseRefCount(emote.id);
 55
 56                //If the clip is not ready by the time we equip it
 57                //we will receive it once its added to the collection in the DataStore
 1258                if (dataStoreEmotes.animations.TryGetValue((this.bodyShapeId, emote.id), out AnimationClip clip))
 259                    animator.EquipEmote(emote.id, clip);
 60            }
 461        }
 62
 63        public void Dispose()
 64        {
 765            dataStoreEmotes.animations.OnAdded -= OnAnimationAdded;
 766            dataStoreEmotes.animations.OnRemoved -= OnAnimationRemoved;
 5067            foreach (string emoteId in this.emotes)
 68            {
 1869                dataStoreEmotes.emotesOnUse.DecreaseRefCount(emoteId);
 70            }
 771            emotes.Clear();
 772        }
 73    }
 74}