Mirror of the outer-repo data_dumps/ reorganization (commit e1e595d in the SVSim outer repo): updates all data_dumps/extract/ → data_dumps/scripts/, data_dumps/client_master_csv → data_dumps/client-assets, data_dumps/traffic → data_dumps/captures/traffic in XML doc-comments and inline comments across importers, controllers, middlewares, DTOs, and tests. Doc-only; no logic changes; build green. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
61 lines
2.5 KiB
C#
61 lines
2.5 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 achievement-catalog rows from <c>seeds/achievement-catalog.json</c>.
|
|
/// Keyed by (AchievementType, Level) so re-running with new captures grows the ladder.
|
|
/// Rows missing from the seed are LEFT INTACT.
|
|
/// </summary>
|
|
public class AchievementCatalogImporter
|
|
{
|
|
public async Task<int> ImportAsync(SVSimDbContext context, string seedDir)
|
|
{
|
|
var seed = SeedLoader.LoadList<AchievementCatalogSeed>(Path.Combine(seedDir, "achievement-catalog.json"));
|
|
if (seed.Count == 0)
|
|
{
|
|
Console.WriteLine("[AchievementCatalogImporter] No seed rows; skipping.");
|
|
return 0;
|
|
}
|
|
|
|
var existing = await context.AchievementCatalog
|
|
.ToDictionaryAsync(e => (e.AchievementType, e.Level));
|
|
int created = 0, updated = 0;
|
|
var unmappedTypes = new HashSet<int>();
|
|
foreach (var s in seed)
|
|
{
|
|
if (s.AchievementType == 0 || s.Level == 0) continue;
|
|
var key = (s.AchievementType, s.Level);
|
|
var entry = existing.TryGetValue(key, out var ex) ? ex : new AchievementCatalogEntry
|
|
{
|
|
AchievementType = s.AchievementType,
|
|
Level = s.Level,
|
|
};
|
|
entry.Name = s.Name;
|
|
entry.RequireNumber = s.RequireNumber;
|
|
entry.RewardType = s.RewardType;
|
|
entry.RewardDetailId = s.RewardDetailId;
|
|
entry.RewardNumber = s.RewardNumber;
|
|
entry.OrderNum = s.OrderNum;
|
|
entry.EventType = s.EventType;
|
|
entry.EventArg = s.EventArg;
|
|
if (ex is null) { context.AchievementCatalog.Add(entry); existing[key] = entry; created++; }
|
|
else updated++;
|
|
if (s.EventType is null) unmappedTypes.Add(s.AchievementType);
|
|
}
|
|
|
|
await context.SaveChangesAsync();
|
|
Console.WriteLine($"[AchievementCatalogImporter] +{created}/~{updated}");
|
|
if (unmappedTypes.Count > 0)
|
|
{
|
|
Console.WriteLine($"[AchievementCatalogImporter] WARN: {unmappedTypes.Count} types " +
|
|
$"with no event_type: [{string.Join(", ", unmappedTypes.OrderBy(x => x))}] — " +
|
|
"add to ACHIEVEMENT_EVENT_MAP in data_dumps/scripts/extract-achievements.py");
|
|
}
|
|
return created + updated;
|
|
}
|
|
}
|