refactor(bootstrap): migrate mypage-index globals to seed files
This commit is contained in:
@@ -27,7 +27,6 @@ public class GlobalsImporter
|
||||
Console.WriteLine($"[GlobalsImporter] Loading captures from {capturesDir}...");
|
||||
|
||||
JsonElement? loadIndex = LoadCapture(capturesDir, "load-index");
|
||||
JsonElement? mypageIndex = LoadCapture(capturesDir, "mypage-index");
|
||||
JsonElement? deckInfo = LoadCapture(capturesDir, "deck-info");
|
||||
JsonElement? packInfo = LoadCapture(capturesDir, "pack-info");
|
||||
|
||||
@@ -51,15 +50,6 @@ public class GlobalsImporter
|
||||
total += await UpdateRotationCardSetFlags(context, loadIndex.Value);
|
||||
}
|
||||
|
||||
if (mypageIndex.HasValue)
|
||||
{
|
||||
total += await ImportBanners(context, mypageIndex.Value);
|
||||
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)
|
||||
{
|
||||
total += await ImportDefaultDecks(context, deckInfo.Value);
|
||||
@@ -521,135 +511,6 @@ public class GlobalsImporter
|
||||
return updated;
|
||||
}
|
||||
|
||||
// ---------- Mypage: Banners ----------
|
||||
|
||||
private async Task<int> ImportBanners(SVSimDbContext context, JsonElement mypage)
|
||||
{
|
||||
if (!mypage.TryGetProperty("banner", out var arr) || arr.ValueKind != JsonValueKind.Array) return 0;
|
||||
|
||||
// Banners have no wire ID; we treat the capture as authoritative — clear and rewrite.
|
||||
var existing = await context.Banners.ToListAsync();
|
||||
context.Banners.RemoveRange(existing);
|
||||
|
||||
int created = 0;
|
||||
int idx = 1;
|
||||
foreach (var el in arr.EnumerateArray())
|
||||
{
|
||||
context.Banners.Add(new BannerEntry
|
||||
{
|
||||
Id = idx++,
|
||||
ImageName = GetString(el, "image_name"),
|
||||
Click = GetString(el, "click"),
|
||||
Status = GetString(el, "status"),
|
||||
ChangeTime = GetInt(el, "change_time"),
|
||||
RemainingTime = GetInt(el, "remaining_time"),
|
||||
ImagePaths = el.TryGetProperty("image_paths", out var ip) ? Serialize(ip) : "[]"
|
||||
});
|
||||
created++;
|
||||
}
|
||||
Console.WriteLine($"[GlobalsImporter] Banners: {(existing.Count > 0 ? $"-{existing.Count}/" : "")}+{created}");
|
||||
return created;
|
||||
}
|
||||
|
||||
// ---------- Mypage: Colosseum (singleton) ----------
|
||||
|
||||
private async Task<int> ImportColosseum(SVSimDbContext context, JsonElement mypage)
|
||||
{
|
||||
if (!mypage.TryGetProperty("colosseum_info", out var info) || info.ValueKind != JsonValueKind.Object) return 0;
|
||||
|
||||
var existing = await context.Colosseums.FirstOrDefaultAsync(e => e.Id == 1);
|
||||
var entry = existing ?? new ColosseumConfig { Id = 1 };
|
||||
entry.ColosseumId = GetString(info, "colosseum_id");
|
||||
entry.ColosseumName = GetString(info, "colosseum_name");
|
||||
entry.CardPoolName = GetString(info, "card_pool_name");
|
||||
entry.DeckFormat = GetString(info, "deck_format");
|
||||
entry.StartTime = ParseWireDateTime(GetString(info, "start_time"));
|
||||
entry.EndTime = ParseWireDateTime(GetString(info, "end_time"));
|
||||
entry.NowRound = GetString(info, "now_round");
|
||||
entry.IsDisplayTips = GetString(info, "is_display_tips");
|
||||
entry.TipsId = GetString(info, "tips_id");
|
||||
entry.IsColosseumPeriod = GetBool(info, "is_colosseum_period");
|
||||
entry.IsRoundPeriod = GetBool(info, "is_round_period");
|
||||
entry.IsNormalTwoPick = GetString(info, "is_normal_two_pick");
|
||||
entry.IsSpecialMode = GetString(info, "is_special_mode");
|
||||
entry.IsAllCardEnabled = GetInt(info, "is_all_card_enabled");
|
||||
entry.SalesPeriodInfo = info.TryGetProperty("sales_period_info", out var sp) ? Serialize(sp) : "{}";
|
||||
if (existing is null) context.Colosseums.Add(entry);
|
||||
Console.WriteLine($"[GlobalsImporter] Colosseum: {(existing is null ? "+1" : "~1")}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---------- Mypage: Sealed (singleton) ----------
|
||||
|
||||
private async Task<int> ImportSealed(SVSimDbContext context, JsonElement mypage)
|
||||
{
|
||||
if (!mypage.TryGetProperty("sealed_info", out var info) || info.ValueKind != JsonValueKind.Object) return 0;
|
||||
|
||||
var existing = await context.SealedSeasons.FirstOrDefaultAsync(e => e.Id == 1);
|
||||
var entry = existing ?? new SealedConfig { Id = 1 };
|
||||
entry.Enable = GetInt(info, "enable");
|
||||
entry.CrystalCost = GetInt(info, "crystal_cost");
|
||||
entry.RupyCost = GetInt(info, "rupy_cost");
|
||||
entry.TicketCost = GetInt(info, "ticket_cost");
|
||||
entry.DeckUsingNumMin = GetInt(info, "deck_using_num_min");
|
||||
entry.ScheduleId = GetInt(info, "schedule_id");
|
||||
entry.IsJoin = GetBool(info, "is_join");
|
||||
entry.IsDeckCodeMaintenance = GetBool(info, "is_deck_code_maintenance");
|
||||
entry.PackInfo = info.TryGetProperty("pack_info", out var pi) ? Serialize(pi) : "[]";
|
||||
entry.SalesPeriodInfo = info.TryGetProperty("sales_period_info", out var sp) ? Serialize(sp) : "{}";
|
||||
if (existing is null) context.SealedSeasons.Add(entry);
|
||||
Console.WriteLine($"[GlobalsImporter] Sealed: {(existing is null ? "+1" : "~1")}");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ---------- Mypage: Master Point Ranking Period ----------
|
||||
|
||||
private async Task<int> ImportMasterPointRankingPeriod(SVSimDbContext context, JsonElement mypage)
|
||||
{
|
||||
if (!mypage.TryGetProperty("master_point_ranking_period", out var info) || info.ValueKind != JsonValueKind.Object) return 0;
|
||||
|
||||
int id = GetInt(info, "id");
|
||||
if (id == 0) return 0;
|
||||
|
||||
var existing = await context.MasterPointRankingPeriods.FirstOrDefaultAsync(e => e.Id == id);
|
||||
var entry = existing ?? new MasterPointRankingPeriodEntry { Id = id };
|
||||
entry.PeriodNum = GetInt(info, "period_num");
|
||||
entry.NecessaryScore = GetLong(info, "necessary_score");
|
||||
entry.BeginTime = ParseWireDateTime(GetString(info, "begin_time"));
|
||||
entry.EndTime = ParseWireDateTime(GetString(info, "end_time"));
|
||||
if (existing is null) context.MasterPointRankingPeriods.Add(entry);
|
||||
Console.WriteLine($"[GlobalsImporter] MasterPointRankingPeriod (id={id}): {(existing is null ? "+1" : "~1")}");
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user