< Summary

Class:DCL.Huds.QuestsTracker.QuestsTrackerHUDController
Assembly:QuestsTrackerHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/QuestsTrackerHUDController.cs
Covered lines:43
Uncovered lines:10
Coverable lines:53
Total lines:105
Line coverage:81.1% (43 of 53)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%330100%
AddReward(...)0%5.935066.67%
OnQuestsAdded(...)0%12300%
OnQuestsSet(...)0%110100%
OnPinnedQuestsSet(...)0%440100%
OnQuestUpdated(...)0%10.147060%
OnPinnedQuest(...)0%770100%
OnUnpinnedQuest(...)0%6200%
OnQuestRemoved(...)0%220100%
SetVisibility(...)0%220100%
Dispose()0%220100%
CreateView()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/QuestsTrackerHUDController.cs

#LineLine coverage
 1using DCL.QuestsController;
 2using System.Collections.Generic;
 3
 4namespace DCL.Huds.QuestsTracker
 5{
 6    public class QuestsTrackerHUDController : IHUD
 7    {
 08        private static BaseDictionary<string, QuestModel> quests => DataStore.i.Quests.quests;
 09        private static BaseCollection<string> pinnedQuests => DataStore.i.Quests.pinnedQuests;
 10
 11        internal IQuestsTrackerHUDView view;
 12        internal IQuestsController questsController;
 13
 14        public void Initialize(IQuestsController controller)
 15        {
 816            questsController = controller;
 817            view = CreateView();
 18
 819            questsController.OnQuestUpdated += OnQuestUpdated;
 820            questsController.OnRewardObtained += AddReward;
 821            pinnedQuests.OnAdded += OnPinnedQuest;
 822            pinnedQuests.OnRemoved += OnUnpinnedQuest;
 823            pinnedQuests.OnSet += OnPinnedQuestsSet;
 824            quests.OnSet += OnQuestsSet;
 825            quests.OnAdded += OnQuestsAdded;
 826            quests.OnRemoved += OnQuestRemoved;
 27
 2028            foreach (string questId in pinnedQuests.Get())
 29            {
 230                OnPinnedQuest(questId);
 31            }
 832        }
 33
 34        private void AddReward(string questId, string rewardId)
 35        {
 136            if (!quests.TryGetValue(questId, out QuestModel model) || model.status == QuestsLiterals.Status.BLOCKED)
 037                return;
 38
 139            if (!model.TryGetReward(rewardId, out QuestReward reward))
 040                return;
 141            view?.AddReward(questId, reward);
 142        }
 43
 44        private void OnQuestsAdded(string questId, QuestModel quest)
 45        {
 046            if (pinnedQuests.Contains(questId))
 047                view?.PinQuest(questId);
 048        }
 49
 250        private void OnQuestsSet(IEnumerable<KeyValuePair<string, QuestModel>> pairs) { OnPinnedQuestsSet(pinnedQuests.G
 51
 52        private void OnPinnedQuestsSet(IEnumerable<string> pinnedQuests)
 53        {
 254            view?.ClearEntries();
 1255            foreach (string questId in pinnedQuests)
 56            {
 457                OnPinnedQuest(questId);
 58            }
 259        }
 60
 61        private void OnQuestUpdated(string questId, bool hasProgress)
 62        {
 163            if (!quests.TryGetValue(questId, out QuestModel model) || model.status == QuestsLiterals.Status.BLOCKED || (
 64            {
 065                view?.RemoveEntry(questId);
 066                return;
 67            }
 68
 169            view?.UpdateQuest(questId, hasProgress);
 170        }
 71
 72        private void OnPinnedQuest(string questId)
 73        {
 774            if (!quests.TryGetValue(questId, out QuestModel model) || model.status == QuestsLiterals.Status.BLOCKED || (
 75            {
 276                view?.RemoveEntry(questId);
 277                return;
 78            }
 579            view?.PinQuest(questId);
 580        }
 81
 082        private void OnUnpinnedQuest(string questId) { view?.UnpinQuest(questId); }
 83
 284        private void OnQuestRemoved(string questId, QuestModel quest) { view?.RemoveEntry(questId); }
 85
 286        public void SetVisibility(bool visible) { view?.SetVisibility(visible); }
 87
 88        public void Dispose()
 89        {
 190            view.Dispose();
 191            if (questsController != null)
 92            {
 193                questsController.OnQuestUpdated -= OnQuestUpdated;
 194                questsController.OnRewardObtained -= AddReward;
 95            }
 196            pinnedQuests.OnAdded -= OnPinnedQuest;
 197            pinnedQuests.OnRemoved -= OnUnpinnedQuest;
 198            pinnedQuests.OnSet -= OnPinnedQuestsSet;
 199            quests.OnSet -= OnQuestsSet;
 1100            quests.OnRemoved -= OnQuestRemoved;
 1101        }
 102
 1103        internal virtual IQuestsTrackerHUDView CreateView() => QuestsTrackerHUDView.Create();
 104    }
 105}