< Summary

Class:DCL.Quests.QuestLogController
Assembly:Quests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/Quests/QuestLogController.cs
Covered lines:0
Uncovered lines:34
Coverable lines:34
Total lines:97
Line coverage:0% (0 of 34)
Covered branches:0
Total branches:0
Covered methods:0
Total methods:8
Method coverage:0% (0 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
QuestLogController(...)0%2100%
AddActiveQuest()0%72800%
AddCompletedQuest()0%72800%
RemoveQuestIfExists(...)0%2100%
SetAsFullScreenMenuMode(...)0%2100%
SetIsGuest(...)0%2100%
GetUsername()0%30500%
Dispose()0%6200%

File(s)

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

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Tasks;
 3using DCLServices.QuestsService;
 4using System;
 5using System.Collections;
 6using System.Collections.Generic;
 7using System.Threading;
 8using UnityEngine;
 9
 10namespace DCL.Quests
 11{
 12    public class QuestLogController : IDisposable
 13    {
 14        private readonly IUserProfileBridge userProfileBridge;
 15        private readonly IQuestLogComponentView questLogComponentView;
 16        private readonly IQuestsService questsService;
 17
 18        public event Action<string, bool> OnPinChange;
 19        public event Action<Vector2Int> OnJumpIn;
 20        public event Action<string> OnQuestAbandon;
 21        private CancellationTokenSource disposeCts;
 22
 023        public QuestLogController(
 24            IQuestLogComponentView questLogComponentView,
 25            IUserProfileBridge userProfileBridge,
 26            IQuestsService questsService)
 27        {
 028            disposeCts = new CancellationTokenSource();
 029            this.questLogComponentView = questLogComponentView;
 030            this.userProfileBridge = userProfileBridge;
 031            this.questsService = questsService;
 32
 033            questLogComponentView.OnPinChange += (id, isPinned) => OnPinChange?.Invoke(id, isPinned);
 034            questLogComponentView.OnQuestAbandon += (id) => OnQuestAbandon?.Invoke(id);
 035            questLogComponentView.OnJumpIn += (coords) => OnJumpIn?.Invoke(coords);
 036        }
 37
 38        public async UniTaskVoid AddActiveQuest(QuestDetailsComponentModel activeQuest, CancellationToken ct = default)
 39        {
 040            string creatorName = await GetUsername(activeQuest.questCreator, CancellationTokenSource.CreateLinkedTokenSo
 041            List<QuestRewardComponentModel> questRewards = new List<QuestRewardComponentModel>();
 42
 043            foreach (QuestReward questReward in await questsService.GetQuestRewards(activeQuest.questDefinitionId, ct))
 44            {
 045                questRewards.Add(new QuestRewardComponentModel()
 46                {
 47                    imageUri = questReward.image_link,
 48                    name = questReward.name
 49                });
 050                activeQuest.questRewards = questRewards;
 51            }
 52
 053            Debug.Log(activeQuest.questName + " " + activeQuest.questRewards.Count);
 054            questLogComponentView.AddActiveQuest(activeQuest, creatorName);
 055        }
 56
 57        public async UniTaskVoid AddCompletedQuest(QuestDetailsComponentModel completedQuest, CancellationToken ct = def
 58        {
 059            string creatorName = await GetUsername(completedQuest.questCreator, CancellationTokenSource.CreateLinkedToke
 060            List<QuestRewardComponentModel> questRewards = new List<QuestRewardComponentModel>();
 61
 062            foreach (QuestReward questReward in await questsService.GetQuestRewards(completedQuest.questDefinitionId, ct
 63            {
 064                questRewards.Add(new QuestRewardComponentModel()
 65                {
 66                    imageUri = questReward.image_link,
 67                    name = questReward.name
 68                });
 069                completedQuest.questRewards = questRewards;
 70            }
 71
 072            questLogComponentView.AddCompletedQuest(completedQuest, creatorName);
 073        }
 74
 75        public void RemoveQuestIfExists(string questId) =>
 076            questLogComponentView.RemoveQuestIfExists(questId);
 77
 78        public void SetAsFullScreenMenuMode(Transform parentTransform) =>
 079            questLogComponentView.SetAsFullScreenMenuMode(parentTransform);
 80
 81        public void SetIsGuest(bool isGuest) =>
 082            questLogComponentView.SetIsGuest(isGuest);
 83
 84        private async UniTask<string> GetUsername(string userId, CancellationToken cancellationToken)
 85        {
 086            var profile = userProfileBridge.Get(userId);
 087            if (profile != null)
 088                return profile.userName.ToUpper();
 89
 090            profile ??= await userProfileBridge.RequestFullUserProfileAsync(userId, cancellationToken);
 091            return profile.userName.ToUpper();
 092        }
 93
 94        public void Dispose() =>
 095            disposeCts?.SafeCancelAndDispose();
 96    }
 97}