| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Threading; |
| | 5 | | using UnityEngine; |
| | 6 | |
|
| | 7 | | namespace DCL.Controllers.LoadingScreenV2 |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// RemoteHintRequestSource provides remote hint request functionality. |
| | 11 | | /// It retrieves hints asynchronously from a specified source URL using an ISourceWebRequestHandler. |
| | 12 | | /// The hints are parsed from the received JSON data using HintSceneParserUtil. |
| | 13 | | /// </summary> |
| | 14 | | public class RemoteHintRequestSource : IHintRequestSource |
| | 15 | | { |
| 0 | 16 | | public RemoteHintRequestSource(string sourceUrlJson, SourceTag sourceTag, ISourceWebRequestHandler webRequestHan |
| | 17 | | { |
| 0 | 18 | | Source = sourceUrlJson; |
| 0 | 19 | | this.SourceTag = sourceTag; |
| 0 | 20 | | LoadingHints = new List<Hint>(); |
| 0 | 21 | | this.webRequestHandler = webRequestHandler; |
| 0 | 22 | | } |
| | 23 | |
|
| 0 | 24 | | public ISourceWebRequestHandler webRequestHandler { get; } |
| 0 | 25 | | public string Source { get; } |
| 0 | 26 | | public SourceTag SourceTag { get; } |
| 0 | 27 | | public List<Hint> LoadingHints { get; private set; } |
| | 28 | |
|
| | 29 | | public async UniTask<List<Hint>> GetHintsAsync(CancellationToken ctx) |
| | 30 | | { |
| | 31 | | try |
| | 32 | | { |
| | 33 | | // If the CancellationToken is already canceled, return an empty list. |
| 0 | 34 | | if (ctx.IsCancellationRequested) { return LoadingHints; } |
| | 35 | |
|
| 0 | 36 | | string json = await webRequestHandler.Get(Source); |
| | 37 | |
|
| 0 | 38 | | if (!string.IsNullOrEmpty(json)) { LoadingHints = HintSceneParserUtil.ParseJsonToHints(json); } |
| 0 | 39 | | } |
| 0 | 40 | | catch (Exception ex) { Debug.LogWarning($"Exception in RemoteHintRequestSource.GetHintsAsync: {ex.Message}\n |
| | 41 | |
|
| 0 | 42 | | return LoadingHints; |
| 0 | 43 | | } |
| | 44 | |
|
| | 45 | | public void Dispose() |
| | 46 | | { |
| 0 | 47 | | LoadingHints.Clear(); |
| 0 | 48 | | } |
| | 49 | | } |
| | 50 | | } |