< Summary

Class:DCL.Controllers.LoadingScreenV2.SceneHintRequestSource
Assembly:DCL.LoadingScreenV2
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreenV2/HintServiceScripts/SceneHintRequestSource.cs
Covered lines:0
Uncovered lines:32
Coverable lines:32
Total lines:86
Line coverage:0% (0 of 32)
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
SceneHintRequestSource(...)0%2100%
GetHintsAsync()0%1561200%
Dispose()0%2100%
SceneController_OnNewSceneAdded(...)0%12300%
CheckTargetSceneWithCoords(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/LoadingScreenV2/HintServiceScripts/SceneHintRequestSource.cs

#LineLine coverage
 1using Cysharp.Threading.Tasks;
 2using DCL.Models;
 3using System;
 4using System.Collections.Generic;
 5using System.Threading;
 6using UnityEngine;
 7
 8namespace DCL.Controllers.LoadingScreenV2
 9{
 10    /// <summary>
 11    ///     The SceneHintRequestSource class implements the IHintRequestSource interface for retrieving loading hints fr
 12    ///     It monitors the scene loading process, checking the loading status and extracting hints.
 13    /// </summary>
 14    public class SceneHintRequestSource : IHintRequestSource
 15    {
 16        private const int MAX_WAIT_FOR_SCENE = 1;
 17
 18        private readonly Vector2Int currentDestination;
 19        private readonly ISceneController sceneController;
 20        private LoadParcelScenesMessage.UnityParcelScene currentSceneBeingLoaded;
 21        private UniTaskCompletionSource<bool> sceneLoadedCompletionSource;
 22
 023        public SceneHintRequestSource(string sceneJson, SourceTag sourceTag, ISceneController sceneController, Vector2In
 24        {
 025            Source = sceneJson;
 026            this.SourceTag = sourceTag;
 027            LoadingHints = new List<Hint>();
 28
 029            this.sceneController = sceneController;
 030            this.currentDestination = currentDestination;
 31
 032            sceneLoadedCompletionSource = new UniTaskCompletionSource<bool>();
 033            sceneController.OnNewSceneAdded += SceneController_OnNewSceneAdded;
 034        }
 35
 036        public string Source { get; }
 037        public SourceTag SourceTag { get; }
 038        public List<Hint> LoadingHints { get; }
 39
 40        public async UniTask<List<Hint>> GetHintsAsync(CancellationToken ctx)
 41        {
 42            try
 43            {
 044                await UniTask.WhenAny(sceneLoadedCompletionSource.Task, UniTask.Delay(TimeSpan.FromSeconds(MAX_WAIT_FOR_
 45
 046                if (ctx.IsCancellationRequested)
 047                    return LoadingHints;
 48
 049                bool sceneLoaded = sceneLoadedCompletionSource.Task.Status == UniTaskStatus.Succeeded;
 50
 051                if (sceneLoaded && currentSceneBeingLoaded?.loadingScreenHints != null && currentSceneBeingLoaded.loadin
 52                {
 053                    foreach (Hint basehint in currentSceneBeingLoaded.loadingScreenHints)
 54                    {
 055                        if (basehint is Hint hint) { LoadingHints.Add(hint); }
 56                    }
 57                }
 058            }
 059            catch (Exception ex) { Debug.LogWarning($"Exception in SceneHintRequestSource.GetHintsAsync: {ex.Message}\n{
 60
 61            // Returns an empty list if the scene is not loaded or the hints are not present
 062            return LoadingHints;
 063        }
 64
 65        public void Dispose()
 66        {
 067            sceneController.OnNewSceneAdded -= SceneController_OnNewSceneAdded;
 068            LoadingHints.Clear();
 069        }
 70
 71        private void SceneController_OnNewSceneAdded(IParcelScene scene)
 72        {
 073            if (scene != null && CheckTargetSceneWithCoords(scene))
 74            {
 075                currentSceneBeingLoaded = scene.sceneData;
 076                sceneLoadedCompletionSource.TrySetResult(true);
 77
 78                // Recreate the UniTaskCompletionSource to avoid InvalidOperationException on next scene load
 079                sceneLoadedCompletionSource = new UniTaskCompletionSource<bool>();
 80            }
 081        }
 82
 83        public bool CheckTargetSceneWithCoords(IParcelScene scene) =>
 084            Environment.i.world.state.GetSceneNumberByCoords(currentDestination).Equals(scene.sceneData.sceneNumber);
 85    }
 86}