< Summary

Class:DCL.Huds.QuestsPanel.QuestsPanelHUDController
Assembly:QuestsPanelHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsPanelHUD/QuestsPanelHUDController.cs
Covered lines:42
Uncovered lines:1
Coverable lines:43
Total lines:90
Line coverage:97.6% (42 of 43)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
OnQuestPanelVisibleChanged(...)0%110100%
OnQuestUpdated(...)0%550100%
OnQuestAdded(...)0%440100%
OnQuestRemoved(...)0%110100%
OnQuestSet(...)0%330100%
SetVisibility(...)0%110100%
SetViewActive(...)0%440100%
CreateView()0%110100%
Dispose()0%220100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsPanelHUD/QuestsPanelHUDController.cs

#LineLine coverage
 1using System;
 2using DCL.Helpers;
 3using DCL.QuestsController;
 4using System.Collections.Generic;
 5using UnityEngine;
 6
 7namespace DCL.Huds.QuestsPanel
 8{
 9    public class QuestsPanelHUDController : IHUD
 10    {
 11        internal IQuestsPanelHUDView view;
 12        internal IQuestsController questsController;
 013        private static BaseDictionary<string, QuestModel> quests => DataStore.i.Quests.quests;
 14
 15        public void Initialize(IQuestsController newQuestsController)
 16        {
 1017            questsController = newQuestsController;
 1018            view = CreateView();
 1019            SetViewActive(false);
 20
 1021            questsController.OnQuestUpdated += OnQuestUpdated;
 1022            quests.OnAdded += OnQuestAdded;
 1023            quests.OnRemoved += OnQuestRemoved;
 1024            quests.OnSet += OnQuestSet;
 25
 1026            DataStore.i.HUDs.questsPanelVisible.OnChange -= OnQuestPanelVisibleChanged;
 1027            DataStore.i.HUDs.questsPanelVisible.OnChange += OnQuestPanelVisibleChanged;
 28
 1029            OnQuestSet(quests.Get());
 1030        }
 31
 232        private void OnQuestPanelVisibleChanged(bool current, bool previous) { SetViewActive(current); }
 33
 34        private void OnQuestUpdated(string questId, bool hasProgress)
 35        {
 436            if (!quests.TryGetValue(questId, out QuestModel model) || model.status == QuestsLiterals.Status.BLOCKED || (
 37            {
 338                view.RemoveQuest(questId);
 339                return;
 40            }
 41
 142            view.RequestAddOrUpdateQuest(questId);
 143        }
 44
 45        private void OnQuestAdded(string questId, QuestModel questModel)
 46        {
 1347            if (questModel.status == QuestsLiterals.Status.BLOCKED || (questModel.visibility == QuestsLiterals.Visibilit
 348                return;
 1049            view.RequestAddOrUpdateQuest(questId);
 1050        }
 51
 252        private void OnQuestRemoved(string questId, QuestModel questModel) { view.RemoveQuest(questId); }
 53
 54        private void OnQuestSet(IEnumerable<KeyValuePair<string, QuestModel>> quests)
 55        {
 1356            view.ClearQuests();
 5257            foreach ((string key, QuestModel value) in quests)
 58            {
 1359                OnQuestAdded(key, value);
 60            }
 1361        }
 62
 263        public void SetVisibility(bool visible) { DataStore.i.HUDs.questsPanelVisible.Set(visible); }
 64
 65        private void SetViewActive(bool visible)
 66        {
 1167            if ( CommonScriptableObjects.rendererState.Get() )
 68            {
 1169                if (visible)
 170                    Utils.UnlockCursor();
 71                else
 1072                    Utils.LockCursor();
 73            }
 1174            view?.SetVisibility(visible);
 1175        }
 76
 177        internal virtual IQuestsPanelHUDView CreateView() => QuestsPanelHUDView.Create();
 78
 79        public void Dispose()
 80        {
 181            view.Dispose();
 182            if (questsController != null)
 183                questsController.OnQuestUpdated -= OnQuestUpdated;
 184            quests.OnAdded -= OnQuestAdded;
 185            quests.OnRemoved -= OnQuestRemoved;
 186            quests.OnSet -= OnQuestSet;
 187            DataStore.i.HUDs.questsPanelVisible.OnChange -= OnQuestPanelVisibleChanged;
 188        }
 89    }
 90}