< Summary

Class:DCL.EquippedEmotes.EquippedEmotesInitializerPlugin
Assembly:EquippedEmotesPlugin
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/EquippedEmotes/EquippedEmotesPlugin.cs
Covered lines:0
Uncovered lines:37
Coverable lines:37
Total lines:102
Line coverage:0% (0 of 37)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EquippedEmotesInitializerPlugin()0%2100%
GetDefaultEmotes()0%2100%
LoadDefaultEquippedEmotes()0%2100%
LoadEquippedEmotesFromLocalStorage()0%6200%
OnEquippedEmotesSet(...)0%2100%
OnEquippedEmoteAddedOrRemoved(...)0%2100%
SaveEquippedEmotesInLocalStorage()0%30500%
SetEquippedEmotes(...)0%12300%
Dispose()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/DCLPlugins/EquippedEmotes/EquippedEmotesPlugin.cs

#LineLine coverage
 1using DCL.Helpers;
 2using Newtonsoft.Json;
 3using System.Collections.Generic;
 4using UnityEngine;
 5
 6namespace DCL.EquippedEmotes
 7{
 8    /// <summary>
 9    /// Plugin feature that initialize the Equipped Emotes feature.
 10    /// </summary>
 11    public class EquippedEmotesInitializerPlugin : IPlugin
 12    {
 13        internal const string PLAYER_PREFS_EQUIPPED_EMOTES_KEY = "EquippedNFTEmotes";
 14
 015        internal DataStore_EmotesCustomization emotesCustomizationDataStore => DataStore.i.emotesCustomization;
 016        internal DataStore_FeatureFlag featureFlagsDataStore => DataStore.i.featureFlags;
 17
 018        public EquippedEmotesInitializerPlugin()
 19        {
 020            LoadDefaultEquippedEmotes();
 21
 022            LoadEquippedEmotesFromLocalStorage();
 23
 024            emotesCustomizationDataStore.equippedEmotes.OnSet += OnEquippedEmotesSet;
 025            emotesCustomizationDataStore.equippedEmotes.OnAdded += OnEquippedEmoteAddedOrRemoved;
 026            emotesCustomizationDataStore.equippedEmotes.OnRemoved += OnEquippedEmoteAddedOrRemoved;
 027        }
 28
 29        internal List<string> GetDefaultEmotes()
 30        {
 031            return new List<string>
 32            {
 33                "handsair",
 34                "wave",
 35                "fistpump",
 36                "dance",
 37                "raiseHand",
 38                "clap",
 39                "money",
 40                "kiss",
 41                "headexplode",
 42                "shrug"
 43            };
 44        }
 45
 046        internal void LoadDefaultEquippedEmotes() { SetEquippedEmotes(GetDefaultEmotes()); }
 47
 48        internal void LoadEquippedEmotesFromLocalStorage()
 49        {
 50            List<string> storedEquippedEmotes;
 51
 52            try
 53            {
 054                storedEquippedEmotes = JsonConvert.DeserializeObject<List<string>>(PlayerPrefsUtils.GetString(PLAYER_PRE
 055            }
 056            catch
 57            {
 058                storedEquippedEmotes = null;
 059            }
 60
 061            if (storedEquippedEmotes == null)
 062                storedEquippedEmotes = GetDefaultEmotes();
 63
 064            SetEquippedEmotes(storedEquippedEmotes);
 065        }
 66
 067        internal void OnEquippedEmotesSet(IEnumerable<EquippedEmoteData> equippedEmotes) { SaveEquippedEmotesInLocalStor
 68
 069        internal void OnEquippedEmoteAddedOrRemoved(EquippedEmoteData equippedEmote) { SaveEquippedEmotesInLocalStorage(
 70
 71        internal void SaveEquippedEmotesInLocalStorage()
 72        {
 073            List<string> emotesIdsToStore = new List<string>();
 074            foreach (EquippedEmoteData equippedEmoteData in emotesCustomizationDataStore.equippedEmotes.Get())
 75            {
 076                emotesIdsToStore.Add(equippedEmoteData != null ? equippedEmoteData.id : null);
 77            }
 78
 79            // TODO: We should avoid static calls and create injectable interfaces
 080            PlayerPrefsUtils.SetString(PLAYER_PREFS_EQUIPPED_EMOTES_KEY, JsonConvert.SerializeObject(emotesIdsToStore));
 081            PlayerPrefsUtils.Save();
 082        }
 83
 84        internal void SetEquippedEmotes(List<string> storedEquippedEmotes)
 85        {
 086            List<EquippedEmoteData> storedEquippedEmotesData = new List<EquippedEmoteData>();
 087            foreach (string emoteId in storedEquippedEmotes)
 88            {
 089                storedEquippedEmotesData.Add(
 90                    string.IsNullOrEmpty(emoteId) ? null : new EquippedEmoteData { id = emoteId, cachedThumbnail = null 
 91            }
 092            emotesCustomizationDataStore.equippedEmotes.Set(storedEquippedEmotesData);
 093        }
 94
 95        public void Dispose()
 96        {
 097            emotesCustomizationDataStore.equippedEmotes.OnSet -= OnEquippedEmotesSet;
 098            emotesCustomizationDataStore.equippedEmotes.OnAdded -= OnEquippedEmoteAddedOrRemoved;
 099            emotesCustomizationDataStore.equippedEmotes.OnRemoved -= OnEquippedEmoteAddedOrRemoved;
 0100        }
 101    }
 102}