Stage 9B of the bootstrap-seed-refactor: add per-domain importer classes that consume the load-index seed split produced in Stage 9A. New importers (each in its own file under SVSim.Bootstrap/Importers/): - RotationConfigImporter: writes Rotation/Challenge/MyRotationSchedule GameConfig sections (atomic UpsertSection<T> pattern, copied private-static from GlobalsImporter so this importer stands alone post-9C). - MyRotationImporter: settings + abilities (extractor pre-joins on rotation_id). - AvatarAbilityImporter: per-leader_skin_id ability rows. - ArenaSeasonImporter: singleton (Id=1) Take Two arena season. - BattlePassImporter: per-level reward blobs. - DailyLoginBonusImporter: per-bonus-id campaign blobs. - PreReleaseInfoImporter: singleton (Id=1) pre-release window. Seed DTOs under SVSim.Bootstrap/Models/Seed/ mirror the seed JSON via [JsonPropertyName] snake_case. Raw-JSON columns (reward_data, format_info, etc.) use JsonElement on the seed and JsonSerializer.Serialize in the importer. Tests: 7 new happy-path tests in LoadIndexImporterTests.cs (idempotency covered by BattlePass spot-check). Full suite: 382/382 passing (375 + 7). NOT modifying in this stage: GlobalsImporter.cs (Stage 9C strips the old methods), Program.cs (Stage 9C wires up all 9 importers), SVSimTestFactory (Stage 9C). Double-writing on bootstrap is expected and OK during 9B.
42 lines
1.7 KiB
C#
42 lines
1.7 KiB
C#
using Microsoft.EntityFrameworkCore;
|
|
using SVSim.Bootstrap.Models.Seed;
|
|
using SVSim.Database;
|
|
using SVSim.Database.Models;
|
|
|
|
namespace SVSim.Bootstrap.Importers;
|
|
|
|
/// <summary>
|
|
/// Idempotent upsert of Avatar (Hero) ability rows from <c>seeds/avatar-abilities.json</c>.
|
|
/// Keyed by leader_skin_id. Ability / passive-ability DSL strings are preserved verbatim.
|
|
/// </summary>
|
|
public class AvatarAbilityImporter
|
|
{
|
|
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
|
|
{
|
|
var seed = SeedLoader.LoadList<AvatarAbilitySeed>(Path.Combine(seedDir, "avatar-abilities.json"));
|
|
if (seed.Count == 0) return 0;
|
|
|
|
var existing = await context.AvatarAbilities.ToDictionaryAsync(e => e.Id);
|
|
int created = 0, updated = 0;
|
|
foreach (var s in seed)
|
|
{
|
|
if (s.Id == 0) continue;
|
|
var entry = existing.TryGetValue(s.Id, out var ex) ? ex : new AvatarAbilityEntry { Id = s.Id };
|
|
entry.BattleStartFirstPlayerTurnBp = s.BattleStartFirstPlayerTurnBp;
|
|
entry.BattleStartSecondPlayerTurnBp = s.BattleStartSecondPlayerTurnBp;
|
|
entry.BattleStartMaxLife = s.BattleStartMaxLife;
|
|
entry.AbilityCost = s.AbilityCost;
|
|
entry.Ability = s.Ability;
|
|
entry.PassiveAbility = s.PassiveAbility;
|
|
entry.AbilityDesc = s.AbilityDesc;
|
|
entry.PassiveAbilityDesc = s.PassiveAbilityDesc;
|
|
if (ex is null) { context.AvatarAbilities.Add(entry); existing[s.Id] = entry; created++; }
|
|
else updated++;
|
|
}
|
|
|
|
await context.SaveChangesAsync();
|
|
Console.WriteLine($"[AvatarAbilityImporter] +{created}/~{updated}");
|
|
return created + updated;
|
|
}
|
|
}
|