< Summary

Class:DCL.Emotes.EmoteAnimationsPlugin
Assembly:Emotes
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/EmoteAnimationsPlugin/EmoteAnimationsPlugin.cs
Covered lines:0
Uncovered lines:27
Coverable lines:27
Total lines:79
Line coverage:0% (0 of 27)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EmoteAnimationsPlugin(...)0%2100%
InitializeEmbeddedEmotes()0%20400%
OnRefCountUpdated(...)0%6200%
InitializeEmotes(...)0%12300%
LoadEmote(...)0%2100%
UnloadEmote(...)0%2100%
Dispose()0%2100%

File(s)

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

#LineLine coverage
 1using System.Collections.Generic;
 2using UnityEngine;
 3
 4namespace DCL.Emotes
 5{
 6    public class EmoteAnimationsPlugin : IPlugin
 7    {
 8        private readonly DataStore_Emotes dataStore;
 9
 010        public EmoteAnimationsPlugin(DataStore_Emotes dataStore)
 11        {
 012            this.dataStore = dataStore;
 013            this.dataStore.animations.Clear();
 014            this.dataStore.emotesOnUse.OnRefCountUpdated += OnRefCountUpdated;
 15
 016            InitializeEmbeddedEmotes();
 017            InitializeEmotes(this.dataStore.emotesOnUse.GetAllRefCounts());
 018        }
 19
 20        private void InitializeEmbeddedEmotes()
 21        {
 22            //To avoid circular references in assemblies we hardcode this here instead of using WearableLiterals
 23            //Embedded Emotes are only temporary until they can be retrieved from the content server
 24            const string FEMALE = "urn:decentraland:off-chain:base-avatars:BaseFemale";
 25            const string MALE = "urn:decentraland:off-chain:base-avatars:BaseMale";
 26
 027            var embeddedEmotes = Resources.Load<EmbeddedEmotesSO>("EmbeddedEmotes");
 28
 029            foreach (EmbeddedEmote embeddedEmote in embeddedEmotes.emotes)
 30            {
 031                if (embeddedEmote.maleAnimation != null)
 32                {
 33                    //We match the animation id with its name due to performance reasons
 34                    //Unity's Animation uses the name to play the clips.
 035                    embeddedEmote.maleAnimation.name = embeddedEmote.id;
 036                    dataStore.animations.Add((MALE, embeddedEmote.id), embeddedEmote.maleAnimation);
 37                }
 38
 039                if (embeddedEmote.femaleAnimation != null)
 40                {
 41                    //We match the animation id with its name due to performance reasons
 42                    //Unity's Animation uses the name to play the clips.
 043                    embeddedEmote.femaleAnimation.name = embeddedEmote.id;
 044                    dataStore.animations.Add((FEMALE, embeddedEmote.id), embeddedEmote.femaleAnimation);
 45                }
 46            }
 047            CatalogController.i.EmbedWearables(embeddedEmotes.emotes);
 048        }
 49
 50        private void OnRefCountUpdated(string emoteId, int refCount)
 51        {
 052            if (refCount > 0)
 053                LoadEmote(emoteId);
 54            else
 055                UnloadEmote(emoteId);
 056        }
 57
 58        private void InitializeEmotes(IEnumerable<KeyValuePair<string, int>> refCounts)
 59        {
 060            foreach (KeyValuePair<string, int> keyValuePair in refCounts)
 61            {
 062                LoadEmote(keyValuePair.Key);
 63            }
 064        }
 65
 66        private void LoadEmote(string id)
 67        {
 68            //TODO when working with emotes in the content server
 069        }
 70
 71        private void UnloadEmote(string id)
 72        {
 73            //TODO when working with emotes in the content server
 074        }
 75
 076        public void Dispose() { this.dataStore.emotesOnUse.OnRefCountUpdated -= OnRefCountUpdated; }
 77    }
 78
 79}