Use managed runtime catalog for Eve surfaces
This commit is contained in:
parent
91548a8fc3
commit
73e8111666
7 changed files with 83 additions and 146 deletions
|
|
@ -124,7 +124,8 @@ foreach (var nameFile in parsedNameFiles)
|
|||
await node.PutLegacyNameFileAsync(nameFile);
|
||||
}
|
||||
|
||||
await node.PutCatalogSurfaceAsync(AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), capturedAtUtc));
|
||||
var runtimeCatalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false);
|
||||
await node.PutCatalogSurfaceAsync(AetheriaCatalogSurfaceProjector.Build(runtimeCatalog, capturedAtUtc));
|
||||
|
||||
await node.FlushAsync();
|
||||
|
||||
|
|
|
|||
|
|
@ -89,8 +89,9 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s
|
|||
SampleNames = ["Ada", "Grace"]
|
||||
});
|
||||
|
||||
var runtimeCatalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false);
|
||||
await node.PutCatalogSurfaceAsync(
|
||||
AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), now));
|
||||
AetheriaCatalogSurfaceProjector.Build(runtimeCatalog, now));
|
||||
|
||||
var verseHostSettings = AetheriaVerseHostSettingsNormalizer.Normalize(new AetheriaVerseHostSettings
|
||||
{
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ RequireVerseSettingsShellAndBridge(root);
|
|||
RequireTypedStatRecipeOperations(root);
|
||||
RequireTypedDaemonCommandPayloads(root);
|
||||
RequireUnityPublicRequestVocabulary(root);
|
||||
RequireCatalogSurfaceUsesManagedRuntimeCatalog(root);
|
||||
RequireDaemonVersePublication(root);
|
||||
RequireUnityRuntimeCatalogClientUsesManagedDocument(root);
|
||||
RequireAetheriaRuntimeVerseClientContract(root);
|
||||
|
|
@ -108,12 +109,12 @@ var publishedSurface = await node.GetCatalogSurfaceAsync()
|
|||
var items = node.Cache.GetAll<AetheriaItemDefinition>().ToArray();
|
||||
var corporations = node.Cache.GetAll<AetheriaCorporation>().ToArray();
|
||||
var nameFiles = node.Cache.GetAll<AetheriaNameFile>().ToArray();
|
||||
var catalog = node.ReadCatalogSnapshot();
|
||||
var catalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false);
|
||||
var surface = AetheriaCatalogSurfaceProjector.Build(catalog, DateTimeOffset.UtcNow.ToString("O"));
|
||||
var tradeValuePolicy = await node.GetTradeValuePolicyAsync()
|
||||
?? throw new InvalidOperationException("Missing authored trade value policy document.");
|
||||
await RequireTradeValuePolicyEveCommandPersistsAsync();
|
||||
var runtimeCatalog = AetheriaRuntimeStateReader.OpenRuntimeCatalog(statePath);
|
||||
var runtimeCatalog = catalog;
|
||||
|
||||
RequireCount(ledger, "aetheria.item_definition.v1", items.Length);
|
||||
RequireCount(ledger, "aetheria.corporation.v2", corporations.Length);
|
||||
|
|
@ -458,21 +459,21 @@ if (equipmentItems.Length != hardpointItems)
|
|||
$"Typed catalog equipment item query mismatch: query={equipmentItems.Length}, hardpoint={hardpointItems}.");
|
||||
}
|
||||
|
||||
var behaviorKind = items.SelectMany(item => item.BehaviorKinds).FirstOrDefault()
|
||||
var behaviorKind = catalog.Items.SelectMany(item => item.BehaviorKinds).FirstOrDefault()
|
||||
?? throw new InvalidOperationException("Cannot verify typed catalog behavior query: no behavior kinds.");
|
||||
if (!catalog.FindItemsByBehavior(behaviorKind).Any())
|
||||
{
|
||||
throw new InvalidOperationException($"Typed catalog behavior query failed for {behaviorKind}.");
|
||||
}
|
||||
|
||||
var hardpointType = items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.HardpointType))?.HardpointType
|
||||
var hardpointType = catalog.Items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.HardpointType))?.HardpointType
|
||||
?? throw new InvalidOperationException("Cannot verify typed catalog hardpoint query: no hardpoint types.");
|
||||
if (!catalog.FindItemsByHardpoint(hardpointType).Any())
|
||||
{
|
||||
throw new InvalidOperationException($"Typed catalog hardpoint query failed for {hardpointType}.");
|
||||
}
|
||||
|
||||
var manufacturedItem = items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.ManufacturerLegacyId))
|
||||
var manufacturedItem = catalog.Items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.ManufacturerKey))
|
||||
?? throw new InvalidOperationException("Cannot verify typed catalog manufacturer lookup: no manufactured item.");
|
||||
if (string.IsNullOrWhiteSpace(manufacturedItem.ManufacturerKey) ||
|
||||
catalog.FindCorporation(manufacturedItem.ManufacturerKey) == null ||
|
||||
|
|
@ -482,8 +483,8 @@ if (string.IsNullOrWhiteSpace(manufacturedItem.ManufacturerKey) ||
|
|||
$"Typed catalog manufacturer-key lookup failed for item {manufacturedItem.Name}.");
|
||||
}
|
||||
|
||||
var corporationWithNames = corporations.FirstOrDefault(corporation =>
|
||||
!string.IsNullOrWhiteSpace(corporation.GeonameFileLegacyId))
|
||||
var corporationWithNames = catalog.Corporations.FirstOrDefault(corporation =>
|
||||
!string.IsNullOrWhiteSpace(corporation.GeonameFileKey))
|
||||
?? throw new InvalidOperationException("Cannot verify typed catalog name-file lookup: no linked corporation.");
|
||||
if (string.IsNullOrWhiteSpace(corporationWithNames.GeonameFileKey) ||
|
||||
catalog.FindNameFile(corporationWithNames.GeonameFileKey) == null ||
|
||||
|
|
@ -9272,6 +9273,72 @@ static void RequireUnityRuntimeCatalogClientUsesManagedDocument(string root)
|
|||
Console.WriteLine("Unity runtime catalog client: catalog reads use the managed typed runtime document");
|
||||
}
|
||||
|
||||
static void RequireCatalogSurfaceUsesManagedRuntimeCatalog(string root)
|
||||
{
|
||||
var projectorPath = Path.Combine(root, "Aetheria.State", "AetheriaCatalogSurfaceProjector.cs");
|
||||
var bridgePath = Path.Combine(root, "Aetheria.State", "AetheriaEveCommandBridge.cs");
|
||||
var legacySnapshotPath = Path.Combine(root, "Aetheria.State", "AetheriaCatalogSnapshot.cs");
|
||||
var projector = File.Exists(projectorPath)
|
||||
? File.ReadAllText(projectorPath)
|
||||
: throw new InvalidOperationException("Cannot verify catalog surface projector; AetheriaCatalogSurfaceProjector.cs is missing.");
|
||||
var bridge = File.Exists(bridgePath)
|
||||
? File.ReadAllText(bridgePath)
|
||||
: throw new InvalidOperationException("Cannot verify Eve command bridge catalog refresh; AetheriaEveCommandBridge.cs is missing.");
|
||||
|
||||
var requiredProjectorSymbols = new[]
|
||||
{
|
||||
"Build(AetheriaRuntimeCatalogSnapshot catalog",
|
||||
"item.ItemKey",
|
||||
"corporation.CorporationKey",
|
||||
"catalog.GetManufacturer(item)",
|
||||
"catalog.GetNameFile(corporation)"
|
||||
};
|
||||
var missingProjectorSymbols = requiredProjectorSymbols
|
||||
.Where(symbol => !projector.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingProjectorSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Catalog Eve surface must project from the managed runtime catalog document: " +
|
||||
string.Join(", ", missingProjectorSymbols));
|
||||
}
|
||||
|
||||
if (projector.Contains("Build(AetheriaCatalogSnapshot catalog", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Catalog Eve surface still depends on the legacy authored catalog snapshot instead of the managed runtime catalog document.");
|
||||
}
|
||||
|
||||
if (File.Exists(legacySnapshotPath))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"AetheriaCatalogSnapshot is dead projection chaff; AetheriaRuntimeCatalogSnapshot is the managed typed catalog document.");
|
||||
}
|
||||
|
||||
var requiredBridgeSymbols = new[]
|
||||
{
|
||||
"var catalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false);",
|
||||
"AetheriaCatalogSurfaceProjector.Build(catalog, command.IssuedAtUtc)"
|
||||
};
|
||||
var missingBridgeSymbols = requiredBridgeSymbols
|
||||
.Where(symbol => !bridge.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingBridgeSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Eve catalog refresh must read the managed runtime catalog document: " +
|
||||
string.Join(", ", missingBridgeSymbols));
|
||||
}
|
||||
|
||||
if (bridge.Contains("ReadCatalogSnapshot()", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Eve catalog refresh still rebuilds the legacy catalog snapshot instead of using AetheriaStateNode.RuntimeCatalog().");
|
||||
}
|
||||
|
||||
Console.WriteLine("Catalog Eve surface: refresh path uses the managed runtime catalog document");
|
||||
}
|
||||
|
||||
static void RequireAetheriaRuntimeVerseClientContract(string root)
|
||||
{
|
||||
var clientPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeVerseClient.cs");
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Aetheria.State.Documents;
|
||||
|
||||
namespace Aetheria.State;
|
||||
|
||||
public sealed class AetheriaCatalogSnapshot
|
||||
{
|
||||
private readonly Dictionary<string, AetheriaItemDefinition> _itemsByLegacyId;
|
||||
private readonly Dictionary<string, AetheriaCorporation> _corporationsByLegacyId;
|
||||
private readonly Dictionary<string, AetheriaCorporation> _corporationsByKey;
|
||||
private readonly Dictionary<string, AetheriaNameFile> _nameFilesByLegacyId;
|
||||
private readonly Dictionary<string, AetheriaNameFile> _nameFilesByKey;
|
||||
|
||||
public AetheriaCatalogSnapshot(
|
||||
IEnumerable<AetheriaItemDefinition> items,
|
||||
IEnumerable<AetheriaCorporation> corporations,
|
||||
IEnumerable<AetheriaNameFile> nameFiles,
|
||||
AetheriaTradeValuePolicy? tradeValuePolicy = null)
|
||||
{
|
||||
Items = items.OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
Corporations = corporations.OrderBy(corporation => corporation.Name, StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
NameFiles = nameFiles.OrderBy(nameFile => nameFile.Name, StringComparer.OrdinalIgnoreCase).ToArray();
|
||||
TradeValuePolicy = tradeValuePolicy;
|
||||
|
||||
_itemsByLegacyId = Items
|
||||
.Where(item => !string.IsNullOrWhiteSpace(item.LegacyId))
|
||||
.ToDictionary(item => item.LegacyId, StringComparer.OrdinalIgnoreCase);
|
||||
_corporationsByLegacyId = Corporations
|
||||
.Where(corporation => !string.IsNullOrWhiteSpace(corporation.LegacyId))
|
||||
.ToDictionary(corporation => corporation.LegacyId, StringComparer.OrdinalIgnoreCase);
|
||||
_corporationsByKey = Corporations
|
||||
.Where(corporation => !string.IsNullOrWhiteSpace(corporation.CorporationKey))
|
||||
.ToDictionary(corporation => corporation.CorporationKey, StringComparer.OrdinalIgnoreCase);
|
||||
_nameFilesByLegacyId = NameFiles
|
||||
.Where(nameFile => !string.IsNullOrWhiteSpace(nameFile.LegacyId))
|
||||
.ToDictionary(nameFile => nameFile.LegacyId, StringComparer.OrdinalIgnoreCase);
|
||||
_nameFilesByKey = NameFiles
|
||||
.Where(nameFile => !string.IsNullOrWhiteSpace(nameFile.NameFileKey))
|
||||
.ToDictionary(nameFile => nameFile.NameFileKey, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public IReadOnlyList<AetheriaItemDefinition> Items { get; }
|
||||
|
||||
public IReadOnlyList<AetheriaCorporation> Corporations { get; }
|
||||
|
||||
public IReadOnlyList<AetheriaNameFile> NameFiles { get; }
|
||||
|
||||
public AetheriaTradeValuePolicy? TradeValuePolicy { get; }
|
||||
|
||||
public IEnumerable<AetheriaItemDefinition> TradeItems =>
|
||||
Items.Where(item => item.Price > 0).OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public IEnumerable<AetheriaItemDefinition> EquipmentItems =>
|
||||
Items.Where(item => !string.IsNullOrWhiteSpace(item.HardpointType))
|
||||
.OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public IEnumerable<AetheriaItemDefinition> FindItemsByBehavior(string behaviorKind)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(behaviorKind)
|
||||
? []
|
||||
: Items
|
||||
.Where(item => item.BehaviorKinds.Contains(behaviorKind, StringComparer.OrdinalIgnoreCase))
|
||||
.OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public IEnumerable<AetheriaItemDefinition> FindItemsByHardpoint(string hardpointType)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(hardpointType)
|
||||
? []
|
||||
: Items
|
||||
.Where(item => string.Equals(item.HardpointType, hardpointType, StringComparison.OrdinalIgnoreCase))
|
||||
.OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public AetheriaItemDefinition? FindItemByLegacyId(string legacyId)
|
||||
{
|
||||
return TryGet(_itemsByLegacyId, legacyId);
|
||||
}
|
||||
|
||||
public AetheriaCorporation? FindCorporationByLegacyId(string legacyId)
|
||||
{
|
||||
return TryGet(_corporationsByLegacyId, legacyId);
|
||||
}
|
||||
|
||||
public AetheriaCorporation? FindCorporation(string corporationKey)
|
||||
{
|
||||
return TryGet(_corporationsByKey, corporationKey);
|
||||
}
|
||||
|
||||
public AetheriaNameFile? FindNameFileByLegacyId(string legacyId)
|
||||
{
|
||||
return TryGet(_nameFilesByLegacyId, legacyId);
|
||||
}
|
||||
|
||||
public AetheriaNameFile? FindNameFile(string nameFileKey)
|
||||
{
|
||||
return TryGet(_nameFilesByKey, nameFileKey);
|
||||
}
|
||||
|
||||
public AetheriaCorporation? FindCorporationByNamePrefix(string namePrefix)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(namePrefix)
|
||||
? null
|
||||
: Corporations.FirstOrDefault(corporation =>
|
||||
corporation.Name.StartsWith(namePrefix, StringComparison.InvariantCultureIgnoreCase));
|
||||
}
|
||||
|
||||
public AetheriaCorporation? GetManufacturer(AetheriaItemDefinition item)
|
||||
{
|
||||
return FindCorporation(item.ManufacturerKey);
|
||||
}
|
||||
|
||||
public AetheriaNameFile? GetNameFile(AetheriaCorporation corporation)
|
||||
{
|
||||
return FindNameFile(corporation.GeonameFileKey);
|
||||
}
|
||||
|
||||
private static T? TryGet<T>(IReadOnlyDictionary<string, T> dictionary, string key) where T : class
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(key) ? null : dictionary.TryGetValue(key, out var value) ? value : null;
|
||||
}
|
||||
}
|
||||
|
|
@ -10,11 +10,11 @@ public static class AetheriaCatalogSurfaceProjector
|
|||
public const string SurfaceKey = "eve:surface:aetheria.catalog.operator";
|
||||
public const string SurfaceId = AetheriaRuntimeCatalogCommands.SurfaceId;
|
||||
|
||||
public static EveSurfaceState Build(AetheriaCatalogSnapshot catalog, string updatedAtUtc, long version = 1)
|
||||
public static EveSurfaceState Build(AetheriaRuntimeCatalogSnapshot catalog, string updatedAtUtc, long version = 1)
|
||||
{
|
||||
var tradeItems = catalog.TradeItems.Take(12).Select(item =>
|
||||
Row(
|
||||
$"item.{SafeId(item.LegacyId)}",
|
||||
$"item.{SafeId(item.ItemKey)}",
|
||||
("name", item.Name),
|
||||
("manufacturer", catalog.GetManufacturer(item)?.Name ?? "GameCult"),
|
||||
("price", item.Price.ToString("N0")),
|
||||
|
|
@ -23,7 +23,7 @@ public static class AetheriaCatalogSurfaceProjector
|
|||
|
||||
var corporations = catalog.Corporations.Take(12).Select(corporation =>
|
||||
Row(
|
||||
$"corporation.{SafeId(corporation.LegacyId)}",
|
||||
$"corporation.{SafeId(corporation.CorporationKey)}",
|
||||
("name", corporation.Name),
|
||||
("short", corporation.ShortName),
|
||||
("names", catalog.GetNameFile(corporation)?.Name ?? ""),
|
||||
|
|
|
|||
|
|
@ -48,8 +48,9 @@ public static class AetheriaEveCommandBridge
|
|||
switch (command.Kind)
|
||||
{
|
||||
case AetheriaRuntimeEveCommandKind.CatalogRefresh:
|
||||
var catalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false);
|
||||
await node.PutCatalogSurfaceAsync(
|
||||
AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), command.IssuedAtUtc)).ConfigureAwait(false);
|
||||
AetheriaCatalogSurfaceProjector.Build(catalog, command.IssuedAtUtc)).ConfigureAwait(false);
|
||||
report.AcceptedCatalogRefreshes++;
|
||||
break;
|
||||
case AetheriaRuntimeEveCommandKind.OperationsRefresh:
|
||||
|
|
|
|||
|
|
@ -204,15 +204,6 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable
|
|||
return GetNameFileAsync(AetheriaCatalogKeys.NameFileFromLegacyId(legacyId));
|
||||
}
|
||||
|
||||
public AetheriaCatalogSnapshot ReadCatalogSnapshot()
|
||||
{
|
||||
return new AetheriaCatalogSnapshot(
|
||||
Cache.GetAll<AetheriaItemDefinition>(),
|
||||
Cache.GetAll<AetheriaCorporation>(),
|
||||
Cache.GetAll<AetheriaNameFile>(),
|
||||
Cache.GetAll<AetheriaTradeValuePolicy>().FirstOrDefault());
|
||||
}
|
||||
|
||||
public Task<CultRecordHandle<AetheriaTradeValuePolicy>> PutTradeValuePolicyAsync(
|
||||
AetheriaTradeValuePolicy policy)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue