diff --git a/SVSim.Bootstrap/Data/test-fixtures/seeds/pack-stubs.json b/SVSim.Bootstrap/Data/test-fixtures/seeds/pack-stubs.json new file mode 100644 index 0000000..89ee244 --- /dev/null +++ b/SVSim.Bootstrap/Data/test-fixtures/seeds/pack-stubs.json @@ -0,0 +1,54 @@ +[ + { + "parent_gacha_id": 10001, + "base_pack_id": 10001, + "gacha_type": 1, + "pack_category": 0, + "poster_type": 0, + "commence_date": "2016-06-17 00:00:00", + "complete_date": "2026-06-30 23:59:59", + "sleeve_id": 0, + "special_sleeve_id": 0, + "override_draw_effect_pack_id": 0, + "override_ui_effect_pack_id": 0, + "gacha_detail": "STUB CLC", + "is_hide": false, + "is_new": false, + "is_pre_release": false, + "open_count_limit": 0, + "sales_period_time": null, + "gacha_point": null, + "child_gachas": [ + { "gacha_id": 100011, "type_detail": 2, "cost": 200, "card_count": 1 }, + { "gacha_id": 100012, "type_detail": 2, "cost": 1800, "card_count": 10 } + ], + "banners": [], + "is_enabled": false + }, + { + "parent_gacha_id": 95001, + "base_pack_id": 95001, + "gacha_type": 1, + "pack_category": 2, + "poster_type": 0, + "commence_date": "2016-06-17 00:00:00", + "complete_date": "2026-06-30 23:59:59", + "sleeve_id": 0, + "special_sleeve_id": 0, + "override_draw_effect_pack_id": 0, + "override_ui_effect_pack_id": 0, + "gacha_detail": "7th Anniv stub", + "is_hide": false, + "is_new": false, + "is_pre_release": false, + "open_count_limit": 0, + "sales_period_time": null, + "gacha_point": null, + "child_gachas": [ + { "gacha_id": 950011, "type_detail": 2, "cost": 200, "card_count": 1 }, + { "gacha_id": 950012, "type_detail": 2, "cost": 1800, "card_count": 10 } + ], + "banners": [], + "is_enabled": false + } +] diff --git a/SVSim.Bootstrap/Importers/PackImporter.cs b/SVSim.Bootstrap/Importers/PackImporter.cs index df5418f..7d5bc55 100644 --- a/SVSim.Bootstrap/Importers/PackImporter.cs +++ b/SVSim.Bootstrap/Importers/PackImporter.cs @@ -61,6 +61,7 @@ public class PackImporter ExchangeablePoint = s.GachaPoint.ExchangeablePoint, IncreaseGachaPoint = s.GachaPoint.IncreaseGachaPoint, }; + pack.IsEnabled = s.IsEnabled; // Owned collections -- clear and rehydrate (matches the previous wholesale-replace semantics). pack.ChildGachas.Clear(); @@ -101,7 +102,75 @@ public class PackImporter } await context.SaveChangesAsync(); - Console.WriteLine($"[PackImporter] +{created}/~{updated}"); - return created + updated; + Console.WriteLine($"[PackImporter] capture: +{created}/~{updated}"); + + // Second pass: synthesized stubs from pack-stubs.json. Skip any pack_id that already + // exists from the live-capture pass (capture wins on conflict). + var stubs = SeedLoader.LoadList(Path.Combine(seedDir, "pack-stubs.json")); + int stubsAdded = 0; + foreach (var s in stubs) + { + if (s.ParentGachaId == 0) continue; + if (existing.ContainsKey(s.ParentGachaId)) continue; + + var pack = new PackConfigEntry + { + Id = s.ParentGachaId, + BasePackId = s.BasePackId, + GachaType = s.GachaType, + PackCategory = (PackCategory)s.PackCategory, + PosterType = s.PosterType, + CommenceDate = ParseWireDateTime(s.CommenceDate), + CompleteDate = ParseWireDateTime(s.CompleteDate), + SleeveId = s.SleeveId, + SpecialSleeveId = s.SpecialSleeveId, + OverrideDrawEffectPackId = s.OverrideDrawEffectPackId, + OverrideUiEffectPackId = s.OverrideUiEffectPackId, + GachaDetail = s.GachaDetail, + IsHide = s.IsHide, + IsNew = s.IsNew, + IsPreRelease = s.IsPreRelease, + OpenCountLimit = s.OpenCountLimit, + SalesPeriodTime = string.IsNullOrEmpty(s.SalesPeriodTime) ? null : ParseWireDateTime(s.SalesPeriodTime), + GachaPointConfig = s.GachaPoint is null ? null : new PackGachaPointConfig + { + ExchangeablePoint = s.GachaPoint.ExchangeablePoint, + IncreaseGachaPoint = s.GachaPoint.IncreaseGachaPoint, + }, + IsEnabled = s.IsEnabled, + }; + foreach (var c in s.ChildGachas) + { + pack.ChildGachas.Add(new PackChildGachaEntry + { + GachaId = c.GachaId, + TypeDetail = c.TypeDetail, + Cost = c.Cost, + CardCount = c.CardCount, + ItemId = c.ItemId, + IsDailySingle = c.IsDailySingle, + OverrideIncreaseGachaPoint = c.OverrideIncreaseGachaPoint, + PurchaseLimitCount = c.PurchaseLimitCount, + FreeGachaCampaignId = c.FreeGachaCampaignId, + CampaignName = c.CampaignName, + }); + } + foreach (var b in s.Banners) + { + pack.Banners.Add(new PackBannerEntry + { + BannerName = b.BannerName, + DialogTitle = b.DialogTitle, + }); + } + context.Packs.Add(pack); + existing[s.ParentGachaId] = pack; + stubsAdded++; + } + + await context.SaveChangesAsync(); + Console.WriteLine($"[PackImporter] stubs: +{stubsAdded}"); + + return created + updated + stubsAdded; } } diff --git a/SVSim.Database/Repositories/Pack/PackRepository.cs b/SVSim.Database/Repositories/Pack/PackRepository.cs index 111510f..417fe94 100644 --- a/SVSim.Database/Repositories/Pack/PackRepository.cs +++ b/SVSim.Database/Repositories/Pack/PackRepository.cs @@ -12,7 +12,7 @@ public class PackRepository : IPackRepository await _db.Packs .Include(p => p.ChildGachas) .Include(p => p.Banners) - .Where(p => p.CommenceDate <= now && p.CompleteDate >= now) + .Where(p => p.IsEnabled && p.CommenceDate <= now && p.CompleteDate >= now) // parent_gacha_id DESC matches the prod /pack/info wire order. The tutorial pack // UI runs with controls locked and auto-selects the FIRST entry in // pack_config_list, so the legendary starter pack (99047) MUST be index 0 for the diff --git a/SVSim.UnitTests/Importers/PackImporterStubsTests.cs b/SVSim.UnitTests/Importers/PackImporterStubsTests.cs new file mode 100644 index 0000000..bcae282 --- /dev/null +++ b/SVSim.UnitTests/Importers/PackImporterStubsTests.cs @@ -0,0 +1,44 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using SVSim.Bootstrap.Importers; +using SVSim.Database; +using SVSim.UnitTests.Infrastructure; + +namespace SVSim.UnitTests.Importers; + +public class PackImporterStubsTests +{ + private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds"); + + [Test] + public async Task Live_capture_overrides_stub_on_conflict() + { + using var factory = new SVSimTestFactory(); + using var scope = factory.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + await new PackImporter().ImportAsync(db, SeedDir); + + // 10001 is in both packs.json (no is_enabled -> defaults true) and pack-stubs.json + // (is_enabled=false). Live capture wins -> IsEnabled stays true and gacha_detail + // is the packs.json value, not "STUB CLC". + var live = await db.Packs.FirstAsync(p => p.Id == 10001); + Assert.That(live.IsEnabled, Is.True); + Assert.That(live.GachaDetail, Does.Not.Contain("STUB")); + } + + [Test] + public async Task Stub_only_packs_are_inserted_with_IsEnabled_false() + { + using var factory = new SVSimTestFactory(); + using var scope = factory.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + await new PackImporter().ImportAsync(db, SeedDir); + + // 95001 is stub-only -> inserted with IsEnabled=false and the stub's gacha_detail. + var stub = await db.Packs.FirstAsync(p => p.Id == 95001); + Assert.That(stub.IsEnabled, Is.False); + Assert.That(stub.GachaDetail, Is.EqualTo("7th Anniv stub")); + } +} diff --git a/SVSim.UnitTests/Repositories/PackRepositoryTests.cs b/SVSim.UnitTests/Repositories/PackRepositoryTests.cs index 83d823b..9166e8c 100644 --- a/SVSim.UnitTests/Repositories/PackRepositoryTests.cs +++ b/SVSim.UnitTests/Repositories/PackRepositoryTests.cs @@ -41,6 +41,33 @@ public class PackRepositoryTests Assert.That(packs.Select(p => p.Id), Is.EquivalentTo(new[] { 10001 })); } + [Test] + public async Task GetActivePacks_excludes_IsEnabled_false_rows() + { + using var factory = new SVSimTestFactory(); + var now = new DateTime(2026, 5, 24, 12, 0, 0, DateTimeKind.Utc); + await SeedPack(factory, 10001, 10001, PackCategory.None, now.AddDays(-1), now.AddDays(1)); + + using (var scope = factory.Services.CreateScope()) + { + var db = scope.ServiceProvider.GetRequiredService(); + db.Packs.Add(new PackConfigEntry + { + Id = 10002, BasePackId = 10002, PackCategory = PackCategory.None, + CommenceDate = now.AddDays(-1), CompleteDate = now.AddDays(1), + GachaType = 1, GachaDetail = "disabled", + IsEnabled = false, + }); + await db.SaveChangesAsync(); + } + + using var scopeRepo = factory.Services.CreateScope(); + var repo = scopeRepo.ServiceProvider.GetRequiredService(); + var packs = await repo.GetActivePacks(now); + + Assert.That(packs.Select(p => p.Id), Is.EquivalentTo(new[] { 10001 })); + } + [Test] public async Task GetPack_includes_child_gachas_and_banners() {