feat(import): import consumable item inventory

This commit is contained in:
gamer147
2026-05-29 18:33:11 -04:00
parent 71b3c3e19f
commit d7e5557d61
3 changed files with 55 additions and 0 deletions

View File

@@ -163,6 +163,25 @@ public class AdminController : SVSimController
}
}
if (request.Items is not null)
{
var wanted = request.Items
.GroupBy(i => i.ItemId)
.Select(g => g.First())
.ToList();
var ids = wanted.Select(i => i.ItemId).ToList();
var itemMaster = await _dbContext.Items
.Where(i => ids.Contains(i.Id))
.ToDictionaryAsync(i => i.Id);
viewer.Items.Clear();
foreach (var i in wanted)
{
if (!itemMaster.TryGetValue(i.ItemId, out var item)) continue; // unknown master id
viewer.Items.Add(new OwnedItemEntry { Item = item, Count = i.Count, Viewer = viewer });
}
}
// Clone the 8 starter decks into the viewer when freshly created — workaround for a
// client-side NRE in the deck-edit menu (DeckListUI.IsVisibleCreateNewButton at
// decompile Wizard/DeckListUI.cs:316 unconditionally reads `_deckGroup.DeckFormat`, but

View File

@@ -28,6 +28,8 @@ public class ImportViewerRequest
[JsonPropertyName("classes")] public List<ImportClassData>? Classes { get; set; }
[JsonPropertyName("owned_cards")] public List<ImportCard>? OwnedCards { get; set; }
[JsonPropertyName("items")] public List<ImportItem>? Items { get; set; }
}
public class ImportCurrency
@@ -50,3 +52,9 @@ public class ImportCard
[JsonPropertyName("count")] public int Count { get; set; }
[JsonPropertyName("is_protected")] public bool IsProtected { get; set; }
}
public class ImportItem
{
[JsonPropertyName("item_id")] public int ItemId { get; set; }
[JsonPropertyName("count")] public int Count { get; set; }
}