Deck list work
This commit is contained in:
@@ -27,6 +27,7 @@ public class GlobalsImporter
|
||||
JsonElement? loadIndex = LoadCapture(capturesDir, "load-index");
|
||||
JsonElement? mypageIndex = LoadCapture(capturesDir, "mypage-index");
|
||||
JsonElement? deckInfo = LoadCapture(capturesDir, "deck-info");
|
||||
JsonElement? paymentItemList = LoadCapture(capturesDir, "payment-item-list");
|
||||
|
||||
int total = 0;
|
||||
|
||||
@@ -54,6 +55,7 @@ public class GlobalsImporter
|
||||
total += await ImportColosseum(context, mypageIndex.Value);
|
||||
total += await ImportSealed(context, mypageIndex.Value);
|
||||
total += await ImportMasterPointRankingPeriod(context, mypageIndex.Value);
|
||||
total += await ImportRoomTypeInSession(context, mypageIndex.Value);
|
||||
}
|
||||
|
||||
if (deckInfo.HasValue)
|
||||
@@ -62,6 +64,11 @@ public class GlobalsImporter
|
||||
total += await ImportDefaultLeaderSkinSettings(context, deckInfo.Value);
|
||||
}
|
||||
|
||||
if (paymentItemList.HasValue)
|
||||
{
|
||||
total += await ImportPaymentItems(context, paymentItemList.Value);
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine($"[GlobalsImporter] Done: {total} total rows changed.");
|
||||
return total;
|
||||
@@ -550,6 +557,34 @@ public class GlobalsImporter
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---------- Mypage: Room Type In Session (special deck formats) ----------
|
||||
|
||||
private async Task<int> ImportRoomTypeInSession(SVSimDbContext context, JsonElement mypage)
|
||||
{
|
||||
if (!mypage.TryGetProperty("room_type_in_session", out var rt) || rt.ValueKind != JsonValueKind.Object) return 0;
|
||||
if (!rt.TryGetProperty("special_deck_format_list", out var arr) || arr.ValueKind != JsonValueKind.Array) return 0;
|
||||
|
||||
// Same shape semantics as Banners — the wire has no stable id, treat the capture as
|
||||
// authoritative and clear-and-rewrite with a synthetic ordinal.
|
||||
var existing = await context.SpecialDeckFormats.ToListAsync();
|
||||
context.SpecialDeckFormats.RemoveRange(existing);
|
||||
|
||||
int created = 0;
|
||||
int idx = 1;
|
||||
foreach (var el in arr.EnumerateArray())
|
||||
{
|
||||
context.SpecialDeckFormats.Add(new SpecialDeckFormatEntry
|
||||
{
|
||||
Id = idx++,
|
||||
DeckFormat = GetString(el, "deck_format"),
|
||||
EndTime = ParseWireDateTime(GetString(el, "end_time"))
|
||||
});
|
||||
created++;
|
||||
}
|
||||
Console.WriteLine($"[GlobalsImporter] SpecialDeckFormats: {(existing.Count > 0 ? $"-{existing.Count}/" : "")}+{created}");
|
||||
return created;
|
||||
}
|
||||
|
||||
// ---------- Deck/info: Default Decks ----------
|
||||
|
||||
private async Task<int> ImportDefaultDecks(SVSimDbContext context, JsonElement deckInfo)
|
||||
@@ -611,6 +646,54 @@ public class GlobalsImporter
|
||||
return created + updated;
|
||||
}
|
||||
|
||||
// ---------- Payment: Item list (Steam/PC storefront, dict-keyed by store_product_id) ----------
|
||||
|
||||
private async Task<int> ImportPaymentItems(SVSimDbContext context, JsonElement payment)
|
||||
{
|
||||
// The payment-item-list capture's `data` IS the product dict (no nested key like banner/colosseum).
|
||||
// LoadCapture already unwrapped `data` for us, so iterate the dict directly.
|
||||
if (payment.ValueKind != JsonValueKind.Object) return 0;
|
||||
|
||||
var existing = await context.PaymentItems.ToDictionaryAsync(e => e.Id);
|
||||
int created = 0, updated = 0;
|
||||
foreach (var kv in payment.EnumerateObject())
|
||||
{
|
||||
var v = kv.Value;
|
||||
if (v.ValueKind != JsonValueKind.Object) continue;
|
||||
|
||||
int recordId = GetInt(v, "record_id");
|
||||
if (recordId == 0) continue;
|
||||
|
||||
var entry = existing.TryGetValue(recordId, out var ex) ? ex : new PaymentItemEntry { Id = recordId };
|
||||
entry.ProductId = GetInt(v, "id");
|
||||
entry.StoreProductId = GetLong(v, "store_product_id");
|
||||
entry.Name = GetString(v, "name");
|
||||
entry.Text = GetString(v, "text");
|
||||
entry.Price = ParseDecimal(GetString(v, "price"));
|
||||
entry.ChargeCrystalNum = GetInt(v, "charge_crystal_num");
|
||||
entry.FreeCrystalNum = GetInt(v, "free_crystal_num");
|
||||
entry.PurchaseLimit = GetInt(v, "purchase_limit");
|
||||
entry.SpecialShopFlag = GetInt(v, "special_shop_flag");
|
||||
entry.ImageName = GetString(v, "image_name");
|
||||
entry.StartTime = ParseWireDateTime(GetString(v, "start_time"));
|
||||
entry.EndTime = ParseWireDateTime(GetString(v, "end_time"));
|
||||
entry.RemainingTime = GetInt(v, "remaining_time");
|
||||
entry.IsResaleProduct = GetInt(v, "is_resale_product");
|
||||
// resale_start_date is "" when unset — store null rather than DateTime.MinValue so the
|
||||
// controller can decide whether to emit "" or a real date string.
|
||||
string resaleRaw = GetString(v, "resale_start_date");
|
||||
entry.ResaleStartDate = string.IsNullOrWhiteSpace(resaleRaw) ? null : ParseWireDateTime(resaleRaw);
|
||||
|
||||
if (ex is null) { context.PaymentItems.Add(entry); created++; }
|
||||
else updated++;
|
||||
}
|
||||
Console.WriteLine($"[GlobalsImporter] PaymentItems: +{created}/~{updated}");
|
||||
return created + updated;
|
||||
}
|
||||
|
||||
private static decimal ParseDecimal(string s) =>
|
||||
decimal.TryParse(s, System.Globalization.NumberStyles.Number, System.Globalization.CultureInfo.InvariantCulture, out var d) ? d : 0m;
|
||||
|
||||
// ---------- Helpers ----------
|
||||
|
||||
private static void WarnOrphans(string label, int count)
|
||||
|
||||
Reference in New Issue
Block a user