Make descriptions optional, open constructors for plugins

In rare occurances, we might not have a description assigned to the item. This is most notable in inactive trade offers, but we permit this to happen even in inventory fetches.

Assigning "default" description is unwanted if caller wants to have a way to determine that description wasn't there to begin with. It makes more sense to make it nullable and *expect* it to be null, then caller can do appropriate checking and decide what they want to do with that.

Also open constructors for plugins usage in case they'd like to construct assets manually, e.g. for sending.
This commit is contained in:
Archi
2024-03-18 11:53:14 +01:00
parent 91b09dc43f
commit 5a07f8a2a3
4 changed files with 15 additions and 61 deletions

View File

@@ -362,22 +362,11 @@ public sealed class ArchiWebHandler : IDisposable {
descriptions.TryAdd(key, description);
}
foreach (Asset asset in response.Content.Assets) {
if (!assetIDs.Add(asset.AssetID)) {
continue;
foreach (Asset asset in response.Content.Assets.Where(asset => assetIDs.Add(asset.AssetID))) {
if (descriptions.TryGetValue((asset.ClassID, asset.InstanceID), out InventoryDescription? description)) {
asset.Description = description;
}
(ulong ClassID, ulong InstanceID) key = (asset.ClassID, asset.InstanceID);
if (!descriptions.TryGetValue(key, out InventoryDescription? description)) {
// Best effort only
description = new InventoryDescription(appID, asset.ClassID, asset.InstanceID);
descriptions.Add(key, description);
}
asset.Description = description;
yield return asset;
}
@@ -2390,14 +2379,9 @@ public sealed class ArchiWebHandler : IDisposable {
foreach (Asset asset in assets) {
(uint AppID, ulong ClassID, ulong InstanceID) key = (asset.AppID, asset.ClassID, asset.InstanceID);
if (!descriptions.TryGetValue(key, out InventoryDescription? description)) {
// Best effort only - we can guarantee tradable property at best, and only at the time of the trade offer
description = new InventoryDescription(asset.AppID, asset.ClassID, asset.InstanceID, tradable: true);
descriptions.Add(key, description);
if (descriptions.TryGetValue(key, out InventoryDescription? description)) {
asset.Description = description;
}
asset.Description = description;
}
}