Skip to content

Commit b3b000a

Browse files
AlmightyMikkelkirre-bylund
authored andcommitted
Added simplification to getting details
1 parent 0d641ce commit b3b000a

File tree

1 file changed

+109
-27
lines changed

1 file changed

+109
-27
lines changed

Runtime/Game/Requests/CatalogRequests.cs

Lines changed: 109 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,32 @@ public class LootLockerCatalogEntryListings
147147
public LootLockerCatalogSteamStoreListing steam_store { get; set; }
148148
}
149149

150+
/// <summary>
151+
/// Class to help simply getting item details
152+
/// </summary>
153+
public class LootLockerItemDetailsKey
154+
{
155+
/// <summary>
156+
/// The id of a catalog listing
157+
/// </summary>
158+
public string catalog_listing_id { get; set; }
159+
/// <summary>
160+
/// The id of the item
161+
/// </summary>
162+
public string item_id { get; set; }
163+
164+
public override int GetHashCode()
165+
{
166+
return catalog_listing_id.GetHashCode() + item_id.GetHashCode();
167+
}
168+
169+
public override bool Equals(object obj)
170+
{
171+
return obj.GetHashCode() == GetHashCode();
172+
}
173+
174+
}
175+
150176
/// <summary>
151177
/// </summary>
152178
public class LootLockerCatalogEntry
@@ -183,6 +209,15 @@ public class LootLockerCatalogEntry
183209
/// Whether this entry is currently purchasable
184210
/// </summary>
185211
public bool purchasable { get; set; }
212+
/// <summary>
213+
/// Function to help identify details simpler
214+
/// </summary>
215+
/// <returns>The identifier for looking up details</returns>
216+
public LootLockerItemDetailsKey GetItemDetailsKey()
217+
{
218+
return new LootLockerItemDetailsKey { catalog_listing_id = catalog_listing_id, item_id = entity_id };
219+
}
220+
186221
}
187222

188223
/// <summary>
@@ -217,7 +252,14 @@ public class LootLockerAssetDetails
217252
/// The catalog listing id for this asset detail
218253
/// </summary>
219254
public string catalog_listing_id { get; set; }
220-
255+
/// <summary>
256+
/// Function to help identify details simpler
257+
/// </summary>
258+
/// <returns>The identifier for looking up details</returns>
259+
public LootLockerItemDetailsKey GetItemDetailsKey()
260+
{
261+
return new LootLockerItemDetailsKey { catalog_listing_id = catalog_listing_id, item_id = id };
262+
}
221263
}
222264

223265
/// <summary>
@@ -244,6 +286,14 @@ public class LootLockerProgressionPointDetails
244286
/// The catalog listing id for this progression point detail
245287
/// </summary>
246288
public string catalog_listing_id { get; set; }
289+
/// <summary>
290+
/// Function to help identify details simpler
291+
/// </summary>
292+
/// <returns>The identifier for looking up details</returns>
293+
public LootLockerItemDetailsKey GetItemDetailsKey()
294+
{
295+
return new LootLockerItemDetailsKey { catalog_listing_id = catalog_listing_id, item_id = id };
296+
}
247297
}
248298

249299
/// <summary>
@@ -266,6 +316,14 @@ public class LootLockerProgressionResetDetails
266316
/// The catalog listing id for this progression reset detail
267317
/// </summary>
268318
public string catalog_listing_id { get; set; }
319+
/// <summary>
320+
/// Function to help identify details simpler
321+
/// </summary>
322+
/// <returns>The identifier for looking up details</returns>
323+
public LootLockerItemDetailsKey GetItemDetailsKey()
324+
{
325+
return new LootLockerItemDetailsKey { catalog_listing_id = catalog_listing_id, item_id = id };
326+
}
269327
}
270328

271329
/// <summary>
@@ -292,9 +350,17 @@ public class LootLockerCurrencyDetails
292350
/// The catalog listing id for this currency detail
293351
/// </summary>
294352
public string catalog_listing_id { get; set; }
353+
/// <summary>
354+
/// Function to help identify details simpler
355+
/// </summary>
356+
/// <returns>The identifier for looking up details</returns>
357+
public LootLockerItemDetailsKey GetItemDetailsKey()
358+
{
359+
return new LootLockerItemDetailsKey { catalog_listing_id = catalog_listing_id, item_id = id };
360+
}
295361
}
296362

297-
public class LootLockerGroupAssociations
363+
public class LootLockerGroupAssociation
298364
{
299365
/// <summary>
300366
/// The kind of reward, (asset / currency / group / progression points / progression reset).
@@ -308,6 +374,14 @@ public class LootLockerGroupAssociations
308374
/// The catalog listing id for this group detail.
309375
/// </summary>
310376
public string catalog_listing_id { get; set; }
377+
/// <summary>
378+
/// Function to help identify details simpler
379+
/// </summary>
380+
/// <returns>The identifier for looking up details</returns>
381+
public LootLockerItemDetailsKey GetItemDetailsKey()
382+
{
383+
return new LootLockerItemDetailsKey { catalog_listing_id = catalog_listing_id, item_id = id };
384+
}
311385
}
312386

313387
public class LootLockerGroupMetadata
@@ -343,7 +417,7 @@ public class LootLockerGroupDetails
343417
/// <summary>
344418
/// Associations for the Group reward.
345419
/// </summary>
346-
public LootLockerGroupAssociations[] associations { get; set; }
420+
public LootLockerGroupAssociation[] associations { get; set; }
347421

348422
}
349423

@@ -378,12 +452,12 @@ public class LootLockerListCatalogPricesResponse : LootLockerResponse
378452
/// <summary>
379453
/// Lookup map for details about entities of entity type assets
380454
/// </summary>
381-
public Dictionary<string /*catalog_listing_id*/, LootLockerAssetDetails> asset_details { get; set; }
455+
public Dictionary<LootLockerItemDetailsKey, LootLockerAssetDetails> asset_details { get; set; }
382456

383457
/// <summary>
384458
/// Lookup map for details about entities of entity type progression_points
385459
/// </summary>
386-
public Dictionary<string /*catalog_listing_id*/, LootLockerProgressionPointDetails> progression_points_details
460+
public Dictionary<LootLockerItemDetailsKey, LootLockerProgressionPointDetails> progression_points_details
387461
{
388462
get;
389463
set;
@@ -392,7 +466,7 @@ public class LootLockerListCatalogPricesResponse : LootLockerResponse
392466
/// <summary>
393467
/// Lookup map for details about entities of entity type progression_reset
394468
/// </summary>
395-
public Dictionary<string /*catalog_listing_id*/, LootLockerProgressionResetDetails> progression_resets_details
469+
public Dictionary<LootLockerItemDetailsKey, LootLockerProgressionResetDetails> progression_resets_details
396470
{
397471
get;
398472
set;
@@ -401,9 +475,9 @@ public class LootLockerListCatalogPricesResponse : LootLockerResponse
401475
/// <summary>
402476
/// Lookup map for details about entities of entity type currency
403477
/// </summary>
404-
public Dictionary<string /*catalog_listing_id*/, LootLockerCurrencyDetails> currency_details { get; set; }
478+
public Dictionary<LootLockerItemDetailsKey, LootLockerCurrencyDetails> currency_details { get; set; }
405479

406-
public Dictionary<string /*catalog_listing_id*/, LootLockerGroupDetails> group_details { get; set; }
480+
public Dictionary<LootLockerItemDetailsKey, LootLockerGroupDetails> group_details { get; set; }
407481

408482
/// <summary>
409483
/// Pagination data to use for subsequent requests
@@ -437,6 +511,12 @@ public void AppendCatalogItems(LootLockerListCatalogPricesResponse catalogPrices
437511
{
438512
currency_details.Add(currencyDetail.Key, currencyDetail.Value);
439513
}
514+
515+
foreach(var groupDetail in catalogPrices.group_details)
516+
{
517+
group_details.Add(groupDetail.Key, groupDetail.Value);
518+
}
519+
440520
}
441521

442522
public LootLockerListCatalogPricesResponse() {}
@@ -471,54 +551,55 @@ public LootLockerListCatalogPricesResponse(LootLockerResponse serverResponse)
471551
entries = parsedResponse.entries;
472552
pagination = parsedResponse.pagination;
473553

474-
475554
if (parsedResponse.assets_details != null && parsedResponse.assets_details.Length > 0)
476555
{
477-
asset_details = new Dictionary<string, LootLockerAssetDetails>();
478-
foreach (var assetDetail in parsedResponse.assets_details)
556+
asset_details = new Dictionary<LootLockerItemDetailsKey, LootLockerAssetDetails>();
557+
foreach (var detail in parsedResponse.assets_details)
479558
{
480-
asset_details[assetDetail.catalog_listing_id] = assetDetail;
559+
asset_details[detail.GetItemDetailsKey()] = detail;
481560
}
482561
}
483562

484563
if (parsedResponse.progression_points_details != null &&
485564
parsedResponse.progression_points_details.Length > 0)
486565
{
487-
progression_points_details = new Dictionary<string, LootLockerProgressionPointDetails>();
566+
progression_points_details = new Dictionary<LootLockerItemDetailsKey, LootLockerProgressionPointDetails>();
488567
foreach (var detail in parsedResponse.progression_points_details)
489568
{
490-
progression_points_details[detail.catalog_listing_id] = detail;
569+
progression_points_details[detail.GetItemDetailsKey()] = detail;
491570
}
492571
}
493572

494573
if (parsedResponse.progression_resets_details != null &&
495574
parsedResponse.progression_resets_details.Length > 0)
496575
{
497-
progression_resets_details = new Dictionary<string, LootLockerProgressionResetDetails>();
576+
progression_resets_details = new Dictionary<LootLockerItemDetailsKey, LootLockerProgressionResetDetails>();
498577
foreach (var detail in parsedResponse.progression_resets_details)
499578
{
500-
progression_resets_details[detail.catalog_listing_id] = detail;
579+
progression_resets_details[detail.GetItemDetailsKey()] = detail;
501580
}
502581
}
503582

504583
if (parsedResponse.currency_details != null && parsedResponse.currency_details.Length > 0)
505584
{
506-
currency_details = new Dictionary<string, LootLockerCurrencyDetails>();
585+
currency_details = new Dictionary<LootLockerItemDetailsKey, LootLockerCurrencyDetails>();
507586
foreach (var detail in parsedResponse.currency_details)
508587
{
509-
currency_details[detail.catalog_listing_id] = detail;
588+
currency_details[detail.GetItemDetailsKey()] = detail;
510589
}
511590
}
512591

513592
if(parsedResponse.group_details != null && parsedResponse.group_details.Length > 0)
514593
{
515-
group_details = new Dictionary<string, LootLockerGroupDetails>();
594+
group_details = new Dictionary<LootLockerItemDetailsKey, LootLockerGroupDetails>();
516595
foreach (var detail in parsedResponse.group_details)
517596
{
518-
group_details[detail.id] = detail;
597+
foreach(var association in detail.associations)
598+
{
599+
group_details[association.GetItemDetailsKey()] = detail;
600+
}
519601
}
520602
}
521-
522603
}
523604

524605
#if UNITY_2020_2_OR_NEWER
@@ -575,15 +656,16 @@ public LootLockerInlinedCatalogEntry[] GetLootLockerInlinedCatalogEntries()
575656
List<LootLockerInlinedCatalogEntry> inlinedEntries = new List<LootLockerInlinedCatalogEntry>();
576657
foreach (var lootLockerCatalogEntry in entries)
577658
{
578-
var catalogListingID = lootLockerCatalogEntry.catalog_listing_id;
659+
660+
var itemDetailKey = lootLockerCatalogEntry.GetItemDetailsKey();
579661
var entityKind = lootLockerCatalogEntry.entity_kind;
580662
inlinedEntries.Add(new LootLockerInlinedCatalogEntry(
581663
lootLockerCatalogEntry,
582-
LootLockerCatalogEntryEntityKind.asset == entityKind && asset_details.ContainsKey(catalogListingID) ? asset_details[catalogListingID] : null,
583-
LootLockerCatalogEntryEntityKind.progression_points == entityKind && progression_points_details.ContainsKey(catalogListingID) ? progression_points_details[catalogListingID] : null,
584-
LootLockerCatalogEntryEntityKind.progression_reset == entityKind && progression_resets_details.ContainsKey(catalogListingID) ? progression_resets_details[catalogListingID] : null,
585-
LootLockerCatalogEntryEntityKind.currency == entityKind && currency_details.ContainsKey(catalogListingID) ? currency_details[catalogListingID] : null,
586-
LootLockerCatalogEntryEntityKind.group == entityKind && group_details.ContainsKey(catalogListingID) ? group_details[catalogListingID] : null
664+
LootLockerCatalogEntryEntityKind.asset == entityKind && asset_details.ContainsKey(itemDetailKey) ? asset_details[itemDetailKey] : null,
665+
LootLockerCatalogEntryEntityKind.progression_points == entityKind && progression_points_details.ContainsKey(itemDetailKey) ? progression_points_details[itemDetailKey] : null,
666+
LootLockerCatalogEntryEntityKind.progression_reset == entityKind && progression_resets_details.ContainsKey(itemDetailKey) ? progression_resets_details[itemDetailKey] : null,
667+
LootLockerCatalogEntryEntityKind.currency == entityKind && currency_details.ContainsKey(itemDetailKey) ? currency_details[itemDetailKey] : null,
668+
LootLockerCatalogEntryEntityKind.group == entityKind && group_details.ContainsKey(itemDetailKey) ? group_details[itemDetailKey] : null
587669
));
588670
}
589671
return inlinedEntries.ToArray();

0 commit comments

Comments
 (0)