< Summary

Class:DCL.Huds.QuestsTracker.QuestsTrackerTask
Assembly:QuestsTrackerHUD
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/HUD/QuestsTrackerHUD/QuestsTrackerTask.cs
Covered lines:23
Uncovered lines:21
Coverable lines:44
Total lines:108
Line coverage:52.2% (23 of 44)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
QuestsTrackerTask()0%110100%
Awake()0%110100%
SetIsNew(...)0%2100%
Populate(...)0%660100%
ProgressAndCompleteSequence()0%1561200%
SetProgressText(...)0%110100%
SetExpandedStatus(...)0%2.52050%

File(s)

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

#LineLine coverage
 1using DCL.Interface;
 2using System;
 3using System.Collections;
 4using System.Linq;
 5using TMPro;
 6using UnityEngine;
 7using UnityEngine.UI;
 8
 9namespace DCL.Huds.QuestsTracker
 10{
 11    public class QuestsTrackerTask : MonoBehaviour
 12    {
 13        private const string TASK_COMPLETED_ANIMATION_NAME = "QuestTrackerTaskCompleted";
 114        private static readonly int EXPAND_ANIMATOR_TRIGGER = Animator.StringToHash("Expand");
 115        private static readonly int COLLAPSE_ANIMATOR_TRIGGER = Animator.StringToHash("Collapse");
 116        private static readonly int COMPLETED_ANIMATOR_TRIGGER = Animator.StringToHash("Completed");
 117        private static readonly int NEW_ANIMATOR_TRIGGER = Animator.StringToHash("New");
 18
 19        public event Action<string> OnDestroyed;
 20
 21        [SerializeField] internal TextMeshProUGUI taskTitle;
 22        [SerializeField] internal Image progress;
 23        [SerializeField] internal TextMeshProUGUI progressText;
 24        [SerializeField] internal Button jumpInButton;
 25        [SerializeField] internal Animator animator;
 26
 27        [Header("Audio Events")]
 28        [SerializeField] internal AudioEvent progressBarIncrementAudioEvent;
 29        [SerializeField] internal AudioEvent taskCompleteAudioEvent;
 30
 31        private QuestTask task = null;
 32        private float progressTarget = 0;
 33        private Action jumpInDelegate;
 34
 4235        public void Awake() { jumpInButton.onClick.AddListener(() => { jumpInDelegate?.Invoke(); }); }
 36
 037        public void SetIsNew(bool isNew) { animator.SetBool(NEW_ANIMATOR_TRIGGER, isNew); }
 38
 39        public void Populate(QuestTask newTask)
 40        {
 2241            StopAllCoroutines();
 2242            task = newTask;
 2243            taskTitle.text = task.name;
 2244            jumpInDelegate = () => WebInterface.SendChatMessage(new ChatMessage
 45            {
 46                messageType = ChatMessage.Type.NONE,
 47                recipient = string.Empty,
 48                body = $"/goto {task.coordinates}",
 49            });
 2250            Vector3 scale = progress.transform.localScale;
 2251            scale.x =  newTask.oldProgress;
 2252            progress.transform.localScale = scale;
 2253            jumpInButton.gameObject.SetActive(task.progress < 1 && !string.IsNullOrEmpty(task.coordinates));
 2254            progressTarget = task.progress;
 2255            switch (task.type)
 56            {
 57                case "single":
 1258                    SetProgressText(task.progress, 1);
 1259                    break;
 60                case "numeric":
 61                case "step-based":
 1062                    var payload = JsonUtility.FromJson<TaskPayload_Numeric>(task.payload);
 1063                    SetProgressText(payload.current, payload.end);
 64                    break;
 65            }
 1066        }
 67
 68        public IEnumerator ProgressAndCompleteSequence()
 69        {
 070            Vector3 scale = progress.transform.localScale;
 071            if (Math.Abs(scale.x - progressTarget) > Mathf.Epsilon)
 072                progressBarIncrementAudioEvent.Play();
 073            while (Math.Abs(scale.x - progressTarget) > Mathf.Epsilon)
 74            {
 075                scale.x = Mathf.MoveTowards(scale.x, progressTarget, Time.deltaTime);
 076                progress.transform.localScale = scale;
 077                yield return null;
 78            }
 079            if (progressTarget < 1)
 080                yield break;
 81
 82            //Dont play completed animation if is already playing
 083            if (animator.GetCurrentAnimatorClipInfo(0).All(x => x.clip.name != TASK_COMPLETED_ANIMATION_NAME))
 84            {
 085                yield return WaitForSecondsCache.Get(0.5f);
 086                animator.SetTrigger(COMPLETED_ANIMATOR_TRIGGER);
 087                taskCompleteAudioEvent.Play();
 088                yield return null; // Wait for the animator to update its clipInfo
 89            }
 90
 091            yield return new WaitUntil(() => animator.GetCurrentAnimatorStateInfo(0).normalizedTime > 0.95f);
 92
 093            OnDestroyed?.Invoke(task.id);
 094            Destroy(gameObject);
 095        }
 96
 4497        internal void SetProgressText(float current, float end) { progressText.text = $"{current}/{end}"; }
 98
 99        public void SetExpandedStatus(bool active)
 100        {
 18101            if (active)
 18102                animator.SetTrigger(EXPAND_ANIMATOR_TRIGGER);
 103            else
 0104                animator.SetTrigger(COLLAPSE_ANIMATOR_TRIGGER);
 0105        }
 106
 107    }
 108}