-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathIAvatarElementStorage.cs
More file actions
72 lines (59 loc) · 2.97 KB
/
IAvatarElementStorage.cs
File metadata and controls
72 lines (59 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using CommunicationData.URLHelpers;
using DCL.AvatarRendering.Loading.Components;
using DCL.AvatarRendering.Loading.DTO;
using DCL.AvatarRendering.Wearables.Components;
using DCL.Diagnostics;
using DCL.Optimization.PerformanceBudgeting;
using System.Collections.Generic;
namespace DCL.AvatarRendering.Loading
{
/// <summary>
/// Avatar elements cache, each implementation should be thread safe.
/// </summary>
public interface IAvatarElementStorage<TElement, in TDTO> where TElement: IAvatarAttachment<TDTO> where TDTO: AvatarAttachmentDTO
{
/// <summary>
/// Attempts to retrieve an element from the catalog.
/// </summary>
/// <param name="urn">The URN identifier.</param>
/// <param name="element">The element instance if found.</param>
/// <returns>Returns true if the element exists; otherwise, false.</returns>
bool TryGetElement(URN urn, out TElement element);
void Set(URN urn, TElement element);
/// <summary>
/// Retrieves an element by its DTO or adds a new one if it doesn't exist.
/// </summary>
/// <param name="dto">The wearable DTO</param>
/// <param name="qualifiedForUnloading">Determines if the wearable should be unloaded when memory is full</param>
/// <returns>An instance of the <see cref="TElement" /> type.</returns>
TElement GetOrAddByDTO(TDTO dto, bool qualifiedForUnloading = true);
/// <summary>
/// Unloads the wearable from the catalog by a frame time budget provider.
/// </summary>
/// <param name="frameTimeBudget">The frame time budget provider.</param>
void Unload(IPerformanceBudget frameTimeBudget);
void SetOwnedNft(URN urn, NftBlockchainOperationEntry operation);
bool TryGetOwnedNftRegistry(URN nftUrn, out IReadOnlyDictionary<URN, NftBlockchainOperationEntry> registry);
int GetOwnedNftCount(URN nftUrn);
void ClearOwnedNftRegistry();
/// <summary>
/// Clears the owned NFT entries for a specific base URN.
/// Call this before repopulating with fresh data from the API.
/// </summary>
void ClearOwnedNftForUrn(URN nftUrn);
}
public static class AvatarElementCache
{
public static bool TryGetElementWithLogs<TElement, TDTO>(this IAvatarElementStorage<TElement, TDTO> storage, TDTO assetDTO, string reportCategory, out TElement? element)
where TElement: IAvatarAttachment<TDTO>
where TDTO: AvatarAttachmentDTO
{
string? id = assetDTO.Metadata?.id;
bool inCatalog = storage.TryGetElement(id ?? string.Empty, out element);
//An element that has a DTO request should already have an empty representation in the catalog at this point
if (inCatalog == false)
ReportHub.LogError(reportCategory, $"Requested {typeof(TDTO).Name} '{id}' is not in the catalog");
return inCatalog;
}
}
}