< Summary

Class:DCL.Quests.QuestDetailsComponentView
Assembly:Quests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestDetails/QuestDetailsComponentView.cs
Covered lines:61
Uncovered lines:21
Coverable lines:82
Total lines:187
Line coverage:74.3% (61 of 82)
Covered branches:0
Total branches:0
Covered methods:13
Total methods:17
Method coverage:76.4% (13 of 17)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
QuestDetailsComponentView()0%110100%
Awake()0%110100%
Dispose()0%330100%
RefreshControl()0%2100%
SetFooter(...)0%2100%
SetQuestName(...)0%110100%
SetQuestCreator(...)0%110100%
SetQuestDescription(...)0%110100%
SetQuestId(...)0%110100%
SetCoordinates(...)0%2100%
SetIsPinned(...)0%330100%
SetQuestSteps(...)0%3.023087.5%
SetQuestRewards(...)0%5.275077.78%
SetIsGuest(...)0%110100%
SetPanel(...)0%2100%
InvokeJumpIn(...)0%220100%
InitializePools()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestDetails/QuestDetailsComponentView.cs

#LineLine coverage
 1using DCL.Helpers;
 2using MainScripts.DCL.Helpers.Utils;
 3using System;
 4using System.Collections.Generic;
 5using TMPro;
 6using UIComponents.Scripts.Components;
 7using UnityEngine;
 8using UnityEngine.UI;
 9
 10namespace DCL.Quests
 11{
 12    public class QuestDetailsComponentView : BaseComponentView<QuestDetailsComponentModel>, IQuestDetailsComponentView
 13    {
 14        private const int MAX_REWARDS_COUNT = 5;
 15        private const int MAX_STEPS_COUNT = 10;
 16        private const string COMPLETED_PANEL = "CompletedQuests";
 17        private const string PROGRESS_PANEL = "InProgressQuests";
 18
 19        [SerializeField] internal TMP_Text questName;
 20        [SerializeField] internal TMP_Text questCreator;
 21        [SerializeField] internal TMP_Text questDescription;
 22        [SerializeField] internal Transform stepsParent;
 23        [SerializeField] internal Transform rewardsParent;
 24        [SerializeField] internal Button pinButton;
 25        [SerializeField] internal TMP_Text pinButtonText;
 26        [SerializeField] internal Button abandonButton;
 27        [SerializeField] internal GameObject rewardsSection;
 28        [SerializeField] internal GameObject guestSection;
 29        [SerializeField] internal GameObject footer;
 30        [SerializeField] internal RectTransform parentContent;
 31        private VerticalLayoutGroup layoutGroup;
 32
 33        [SerializeField] internal QuestRewardComponentView rewardPrefab;
 34        [SerializeField] internal QuestStepComponentView stepPrefab;
 35
 36        public event Action<Vector2Int> OnJumpIn;
 37        public event Action<string, bool> OnPinChange;
 38        public event Action<string> OnQuestAbandon;
 39
 40        private UnityObjectPool<QuestStepComponentView> stepsPool;
 41        private UnityObjectPool<QuestRewardComponentView> rewardsPool;
 42
 1243        private readonly List<QuestRewardComponentView> usedRewards = new ();
 1244        private readonly List<QuestStepComponentView> usedSteps = new ();
 45
 46        public override void Awake()
 47        {
 1148            pinButton.onClick.RemoveAllListeners();
 1149            pinButton.onClick.AddListener(() =>
 50            {
 251                model.isPinned = !model.isPinned;
 252                pinButtonText.text = model.isPinned ? "PINNED" : "PIN";
 253                OnPinChange?.Invoke(model.questId, model.isPinned);
 254            });
 1155            abandonButton.onClick.RemoveAllListeners();
 1256            abandonButton.onClick.AddListener(() => OnQuestAbandon?.Invoke(model.questId));
 1157            InitializePools();
 1158        }
 59
 60        public override void Dispose()
 61        {
 4962            foreach (var pooledReward in usedRewards)
 363                rewardsPool.Release(pooledReward);
 2164            rewardsPool.Clear();
 65
 5066            foreach (var pooledSteps in usedSteps)
 567                stepsPool.Release(pooledSteps);
 1968            stepsPool.Clear();
 1969        }
 70
 71        public override void RefreshControl()
 72        {
 073            SetIsPinned(model.isPinned);
 074            SetQuestId(model.questId);
 075            SetQuestName(model.questName);
 076            SetQuestCreator(model.questCreator);
 077            SetQuestDescription(model.questDescription);
 078            SetCoordinates(model.coordinates);
 079            SetQuestSteps(model.questSteps);
 080            SetQuestRewards(model.questRewards);
 81
 082            Utils.ForceRebuildLayoutImmediate(parentContent);
 083        }
 84
 85        public void SetFooter(bool isFooterVisible)
 86        {
 087            abandonButton.gameObject.SetActive(isFooterVisible);
 088            pinButton.gameObject.SetActive(isFooterVisible);
 089        }
 90
 91        public void SetQuestName(string nameText)
 92        {
 193            model.questName = nameText;
 194            questName.text = nameText;
 195        }
 96
 97        public void SetQuestCreator(string creatorText)
 98        {
 199            model.questCreator = creatorText;
 1100            questCreator.text = creatorText;
 1101        }
 102
 103        public void SetQuestDescription(string description)
 104        {
 1105            model.questDescription = description;
 1106            questDescription.text = description;
 1107        }
 108
 109        public void SetQuestId(string questId) =>
 3110            model.questId = questId;
 111
 112        public void SetCoordinates(Vector2Int coordinates) =>
 0113            model.coordinates = coordinates;
 114
 115        public void SetIsPinned(bool isPinned)
 116        {
 2117            model.isPinned = isPinned;
 2118            pinButtonText.text = isPinned ? "PINNED" : "PIN";
 2119        }
 120
 121        public void SetQuestSteps(List<QuestStepComponentModel> questSteps)
 122        {
 2123            model.questSteps = questSteps;
 124
 4125            foreach (var pooledStep in usedSteps)
 0126                stepsPool.Release(pooledStep);
 127
 2128            usedSteps.Clear();
 129
 10130            foreach (var stepModel in questSteps)
 131            {
 3132                QuestStepComponentView pooledStep = stepsPool.Get();
 3133                pooledStep.OnJumpIn -= InvokeJumpIn;
 3134                pooledStep.OnJumpIn += InvokeJumpIn;
 3135                pooledStep.SetModel(stepModel);
 3136                usedSteps.Add(pooledStep);
 137            }
 2138            Utils.ForceRebuildLayoutImmediate(parentContent);
 2139        }
 140
 141        public void SetQuestRewards(List<QuestRewardComponentModel> questRewards)
 142        {
 1143            model.questRewards = questRewards;
 144
 1145            if (questRewards == null || questRewards.Count == 0)
 146            {
 0147                rewardsSection.SetActive(false);
 0148                return;
 149            }
 150
 1151            rewardsSection.SetActive(true);
 152
 2153            foreach (var pooledReward in usedRewards)
 0154                rewardsPool.Release(pooledReward);
 155
 1156            usedRewards.Clear();
 157
 6158            foreach (var rewardModel in questRewards)
 159            {
 2160                QuestRewardComponentView pooledReward = rewardsPool.Get();
 2161                pooledReward.SetModel(rewardModel);
 2162                usedRewards.Add(pooledReward);
 163            }
 1164            Utils.ForceRebuildLayoutImmediate(parentContent);
 1165        }
 166
 167        public void SetIsGuest(bool isGuest) =>
 2168            guestSection.SetActive(isGuest);
 169
 170        public void SetPanel(string panelName)
 171        {
 0172            footer.SetActive(panelName.Equals(PROGRESS_PANEL));
 0173            footer.SetActive(panelName.Equals(COMPLETED_PANEL));
 0174        }
 175
 176        private void InvokeJumpIn(Vector2Int coordinates) =>
 1177            OnJumpIn?.Invoke(coordinates);
 178
 179        private void InitializePools()
 180        {
 11181            rewardsPool = new UnityObjectPool<QuestRewardComponentView>(rewardPrefab, rewardsParent);
 11182            rewardsPool.Prewarm(MAX_REWARDS_COUNT);
 11183            stepsPool = new UnityObjectPool<QuestStepComponentView>(stepPrefab, stepsParent);
 11184            stepsPool.Prewarm(MAX_STEPS_COUNT);
 11185        }
 186    }
 187}