< 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:49
Uncovered lines:1
Coverable lines:50
Total lines:104
Line coverage:98% (49 of 50)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
Initialize(...)0%110100%
OnQuestPanelVisibleChanged(...)0%110100%
OnToggleActionTriggered(...)0%110100%
OnQuestUpdated(...)0%550100%
OnQuestAdded(...)0%440100%
OnQuestRemoved(...)0%110100%
OnQuestSet(...)0%330100%
SetVisibility(...)0%330100%
SetViewActive(...)0%220100%
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        internal InputAction_Trigger toggleQuestsPanel;
 16
 17        public void Initialize(IQuestsController newQuestsController)
 18        {
 1219            questsController = newQuestsController;
 1220            view = CreateView();
 1221            SetViewActive(false);
 22
 1223            toggleQuestsPanel = Resources.Load<InputAction_Trigger>("ToggleQuestsPanelHud");
 1224            toggleQuestsPanel.OnTriggered += OnToggleActionTriggered;
 25
 1226            questsController.OnQuestUpdated += OnQuestUpdated;
 1227            quests.OnAdded += OnQuestAdded;
 1228            quests.OnRemoved += OnQuestRemoved;
 1229            quests.OnSet += OnQuestSet;
 30
 1231            DataStore.i.HUDs.questsPanelVisible.OnChange -= OnQuestPanelVisibleChanged;
 1232            DataStore.i.HUDs.questsPanelVisible.OnChange += OnQuestPanelVisibleChanged;
 33
 1234            OnQuestSet(quests.Get());
 1235        }
 36
 4437        private void OnQuestPanelVisibleChanged(bool current, bool previous) { SetViewActive(current); }
 38
 39        private void OnToggleActionTriggered(DCLAction_Trigger action)
 40        {
 2141            bool value = !DataStore.i.HUDs.questsPanelVisible.Get();
 2142            QuestsUIAnalytics.SendQuestLogVisibiltyChanged(value, "input_action");
 2143            SetVisibility(value);
 2144        }
 45
 46        private void OnQuestUpdated(string questId, bool hasProgress)
 47        {
 448            if (!quests.TryGetValue(questId, out QuestModel model) || model.status == QuestsLiterals.Status.BLOCKED || (
 49            {
 350                view.RemoveQuest(questId);
 351                return;
 52            }
 53
 154            view.RequestAddOrUpdateQuest(questId);
 155        }
 56
 57        private void OnQuestAdded(string questId, QuestModel questModel)
 58        {
 1559            if (questModel.status == QuestsLiterals.Status.BLOCKED || (questModel.visibility == QuestsLiterals.Visibilit
 360                return;
 1261            view.RequestAddOrUpdateQuest(questId);
 1262        }
 63
 264        private void OnQuestRemoved(string questId, QuestModel questModel) { view.RemoveQuest(questId); }
 65
 66        private void OnQuestSet(IEnumerable<KeyValuePair<string, QuestModel>> quests)
 67        {
 1568            view.ClearQuests();
 6069            foreach ((string key, QuestModel value) in quests)
 70            {
 1571                OnQuestAdded(key, value);
 72            }
 1573        }
 74
 75        public void SetVisibility(bool visible)
 76        {
 2277            if ( CommonScriptableObjects.rendererState.Get() )
 78            {
 2279                if (visible)
 1280                    Utils.UnlockCursor();
 81                else
 1082                    Utils.LockCursor();
 83            }
 84
 2285            DataStore.i.HUDs.questsPanelVisible.Set(visible);
 2286        }
 87
 6888        private void SetViewActive(bool visible) { view?.SetVisibility(visible); }
 89
 190        internal virtual IQuestsPanelHUDView CreateView() => QuestsPanelHUDView.Create();
 91
 92        public void Dispose()
 93        {
 194            view.Dispose();
 195            toggleQuestsPanel.OnTriggered -= OnToggleActionTriggered;
 196            if (questsController != null)
 197                questsController.OnQuestUpdated -= OnQuestUpdated;
 198            quests.OnAdded -= OnQuestAdded;
 199            quests.OnRemoved -= OnQuestRemoved;
 1100            quests.OnSet -= OnQuestSet;
 1101            DataStore.i.HUDs.questsPanelVisible.OnChange -= OnQuestPanelVisibleChanged;
 1102        }
 103    }
 104}