Resolve CultUI state refs while lowering
This commit is contained in:
parent
c89f8ea480
commit
20bfa05447
5 changed files with 232 additions and 15 deletions
|
|
@ -4089,19 +4089,33 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
|
|||
"org.gamecult.aetheria.state",
|
||||
"Runtime",
|
||||
"AetheriaRuntimeDaemonItemStatQueries.cs");
|
||||
var eveUnitySurfaceHostPath = Path.Combine(
|
||||
root,
|
||||
"Packages",
|
||||
"org.gamecult.aetheria.eve-runtime",
|
||||
"Runtime",
|
||||
"AetheriaEveUnitySurfaceHost.cs");
|
||||
var cargoItemSurfaceBuilderPath = Path.Combine(
|
||||
root,
|
||||
"Packages",
|
||||
"org.gamecult.aetheria.state",
|
||||
"Runtime",
|
||||
"AetheriaRuntimeCargoItemDetailsSurfaceBuilder.cs");
|
||||
var equippedItemSurfaceBuilderPath = Path.Combine(
|
||||
root,
|
||||
"Packages",
|
||||
"org.gamecult.aetheria.state",
|
||||
"Runtime",
|
||||
"AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.cs");
|
||||
var requiredFiles = new[]
|
||||
{
|
||||
inventoryMenuPath,
|
||||
actionGameManagerPath,
|
||||
surfaceDocumentPath,
|
||||
daemonItemStatQueriesPath,
|
||||
cargoItemSurfaceBuilderPath
|
||||
eveUnitySurfaceHostPath,
|
||||
cargoItemSurfaceBuilderPath,
|
||||
equippedItemSurfaceBuilderPath
|
||||
};
|
||||
var missingFiles = requiredFiles
|
||||
.Where(path => !File.Exists(path))
|
||||
|
|
@ -4118,7 +4132,9 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
|
|||
var actionGameManager = File.ReadAllText(actionGameManagerPath);
|
||||
var surfaceDocument = File.ReadAllText(surfaceDocumentPath);
|
||||
var daemonItemStatQueries = File.ReadAllText(daemonItemStatQueriesPath);
|
||||
var eveUnitySurfaceHost = File.ReadAllText(eveUnitySurfaceHostPath);
|
||||
var cargoItemSurfaceBuilder = File.ReadAllText(cargoItemSurfaceBuilderPath);
|
||||
var equippedItemSurfaceBuilder = File.ReadAllText(equippedItemSurfaceBuilderPath);
|
||||
var requiredSymbols = new[]
|
||||
{
|
||||
"RenderCargoItemDetailsSurface(",
|
||||
|
|
@ -4149,7 +4165,10 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
|
|||
throw new InvalidOperationException("InventoryMenu cargo click path no longer routes item inspection through the Eve surface.");
|
||||
}
|
||||
|
||||
if (!source.Contains("AetheriaRuntimeDaemonItemStatQueries.EvaluatePerformanceStat(", StringComparison.Ordinal) ||
|
||||
if (!source.Contains("ResolveInventorySurfaceStateRef", StringComparison.Ordinal) ||
|
||||
!source.Contains("TryReadItemStatRef(", StringComparison.Ordinal) ||
|
||||
!source.Contains("AetheriaRuntimeDaemonItemStatQueries.ItemStatRef(", StringComparison.Ordinal) ||
|
||||
!source.Contains("AetheriaRuntimeDaemonItemStatQueries.EvaluatePerformanceStat(", StringComparison.Ordinal) ||
|
||||
source.Contains("GameManager.ItemManager.GetTier", StringComparison.Ordinal) ||
|
||||
source.Contains("GameManager.ItemManager.Evaluate", StringComparison.Ordinal) ||
|
||||
actionGameManager.Contains("ObservedItemStat(", StringComparison.Ordinal) ||
|
||||
|
|
@ -4163,7 +4182,14 @@ static void RequireInventoryCargoItemDetailsUseEveSurface(string root)
|
|||
!surfaceDocument.Contains("public const string Value = \"valueRef\"", StringComparison.Ordinal) ||
|
||||
!daemonItemStatQueries.Contains("public const string StateRefPrefix = \"aetheria.state/items\"", StringComparison.Ordinal) ||
|
||||
!daemonItemStatQueries.Contains("public static string ItemStatRef(", StringComparison.Ordinal) ||
|
||||
!daemonItemStatQueries.Contains("public string ValueRef =>", StringComparison.Ordinal))
|
||||
!daemonItemStatQueries.Contains("public string ValueRef =>", StringComparison.Ordinal) ||
|
||||
!eveUnitySurfaceHost.Contains("Func<string, string> stateRefResolver", StringComparison.Ordinal) ||
|
||||
!eveUnitySurfaceHost.Contains("surface = ResolveStateRefs(surface, stateRefResolver)", StringComparison.Ordinal) ||
|
||||
!eveUnitySurfaceHost.Contains("ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, \"value\", stateRefResolver)", StringComparison.Ordinal) ||
|
||||
!cargoItemSurfaceBuilder.Contains("public string ValueRef { get; }", StringComparison.Ordinal) ||
|
||||
!cargoItemSurfaceBuilder.Contains("props.Add(AetheriaRuntimeSurfaceStateRefs.ValueRef(valueRef))", StringComparison.Ordinal) ||
|
||||
!equippedItemSurfaceBuilder.Contains("public string ValueRef { get; }", StringComparison.Ordinal) ||
|
||||
!equippedItemSurfaceBuilder.Contains("props.Add(AetheriaRuntimeSurfaceStateRefs.ValueRef(valueRef))", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Eve/CultUI item stat surfaces must expose typed daemon state refs that the UI runtime can resolve.");
|
||||
|
|
|
|||
|
|
@ -263,6 +263,7 @@ public class InventoryMenu : MonoBehaviour
|
|||
AetheriaRuntimeCargoItemDetailsSurfaceBuilder.Build(ProjectCargoItemDetailsSurfaceState(item, typedItem)),
|
||||
HandleCargoItemDetailsSurfaceCommand,
|
||||
_cargoItemDetailsSurfaceChrome,
|
||||
ResolveInventorySurfaceStateRef,
|
||||
sortingOrder: 1001);
|
||||
}
|
||||
|
||||
|
|
@ -305,6 +306,7 @@ public class InventoryMenu : MonoBehaviour
|
|||
AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.Build(ProjectEquippedItemDetailsSurfaceState(item, typedItem)),
|
||||
HandleEquippedItemDetailsSurfaceCommand,
|
||||
_equippedItemDetailsSurfaceChrome,
|
||||
ResolveInventorySurfaceStateRef,
|
||||
sortingOrder: 1002);
|
||||
}
|
||||
|
||||
|
|
@ -548,7 +550,12 @@ public class InventoryMenu : MonoBehaviour
|
|||
new AetheriaRuntimeCargoItemMetric(
|
||||
$"{AetheriaRuntimeCargoItemDetailsSurfaceBuilder.SurfaceId}.behavior.{behavior.Kind}.target",
|
||||
$"{statReference.Target.SplitCamelCase()}:{statReference.Stat.SplitCamelCase()}",
|
||||
$"{(modifierType == StatModifierType.Constant ? "+" : "x")}{FormatCurrentItemStat(modifier, equippableItem)}")
|
||||
$"{(modifierType == StatModifierType.Constant ? "+" : "x")}{FormatCurrentItemStat(modifier, equippableItem)}",
|
||||
AetheriaRuntimeDaemonItemStatQueries.ItemStatRef(
|
||||
equippableItem.ItemKey,
|
||||
behavior.Kind,
|
||||
behavior.Group,
|
||||
2))
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
|
@ -603,7 +610,14 @@ public class InventoryMenu : MonoBehaviour
|
|||
return new AetheriaRuntimeCargoItemMetric(
|
||||
$"{AetheriaRuntimeCargoItemDetailsSurfaceBuilder.SurfaceId}.behavior.{behavior.Kind}.{field.Key}",
|
||||
field.Name.SplitCamelCase(),
|
||||
value);
|
||||
value,
|
||||
field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat
|
||||
? AetheriaRuntimeDaemonItemStatQueries.ItemStatRef(
|
||||
equippableItem.ItemKey,
|
||||
behavior.Kind,
|
||||
behavior.Group,
|
||||
field.Key)
|
||||
: "");
|
||||
}
|
||||
|
||||
private IEnumerable<AetheriaRuntimeEquippedItemSection> ProjectEquippedItemBehaviorSections(
|
||||
|
|
@ -627,7 +641,12 @@ public class InventoryMenu : MonoBehaviour
|
|||
new AetheriaRuntimeEquippedItemMetric(
|
||||
$"{AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.SurfaceId}.behavior.{behavior.Kind}.target",
|
||||
$"{statReference.Target.SplitCamelCase()}:{statReference.Stat.SplitCamelCase()}",
|
||||
$"{(modifierType == StatModifierType.Constant ? "+" : "x")}{FormatCurrentItemStat(modifier, equippableItem)}")
|
||||
$"{(modifierType == StatModifierType.Constant ? "+" : "x")}{FormatCurrentItemStat(modifier, equippableItem)}",
|
||||
AetheriaRuntimeDaemonItemStatQueries.ItemStatRef(
|
||||
equippableItem.ItemKey,
|
||||
behavior.Kind,
|
||||
behavior.Group,
|
||||
2))
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
|
@ -682,7 +701,14 @@ public class InventoryMenu : MonoBehaviour
|
|||
return new AetheriaRuntimeEquippedItemMetric(
|
||||
$"{AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.SurfaceId}.behavior.{behavior.Kind}.{field.Key}",
|
||||
field.Name.SplitCamelCase(),
|
||||
value);
|
||||
value,
|
||||
field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat
|
||||
? AetheriaRuntimeDaemonItemStatQueries.ItemStatRef(
|
||||
equippableItem.ItemKey,
|
||||
behavior.Kind,
|
||||
behavior.Group,
|
||||
field.Key)
|
||||
: "");
|
||||
}
|
||||
|
||||
private string BuildEquippedItemTitle(EquippedItem item, AetheriaRuntimeCatalogItem typedItem)
|
||||
|
|
@ -715,6 +741,80 @@ private string BuildEquippedItemTitle(EquippedItem item, AetheriaRuntimeCatalogI
|
|||
overrideShutdown: item != null && item.OverrideShutdown);
|
||||
}
|
||||
|
||||
private string ResolveInventorySurfaceStateRef(string stateRef)
|
||||
{
|
||||
return TryResolveInventorySurfaceStateRef(stateRef, out var value) ? value : "";
|
||||
}
|
||||
|
||||
private bool TryResolveInventorySurfaceStateRef(string stateRef, out string value)
|
||||
{
|
||||
value = "";
|
||||
if (!TryReadItemStatRef(stateRef, out var itemKey, out var behaviorKind, out var behaviorGroup, out var fieldKey))
|
||||
return false;
|
||||
|
||||
var item = ResolveSelectedEquippableItem(itemKey);
|
||||
var typedItem = FindTypedInventoryItem(item);
|
||||
var behavior = typedItem?.BehaviorPayloads?.FirstOrDefault(candidate =>
|
||||
string.Equals(candidate.Kind, behaviorKind, StringComparison.Ordinal) &&
|
||||
candidate.Group == behaviorGroup);
|
||||
var field = behavior?.Fields?.FirstOrDefault(candidate => candidate.Key == fieldKey);
|
||||
if (item == null || field == null)
|
||||
return false;
|
||||
|
||||
value = FormatCurrentItemStat(field.Value, item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private EquippableItem ResolveSelectedEquippableItem(string itemKey)
|
||||
{
|
||||
var equipped = _selectedEquippedItem?.EquippableItem;
|
||||
if (ItemKeyMatches(equipped, itemKey))
|
||||
return equipped;
|
||||
|
||||
var cargo = _selectedItem as EquippableItem;
|
||||
return ItemKeyMatches(cargo, itemKey) ? cargo : null;
|
||||
}
|
||||
|
||||
private static bool TryReadItemStatRef(
|
||||
string stateRef,
|
||||
out string itemKey,
|
||||
out string behaviorKind,
|
||||
out int behaviorGroup,
|
||||
out int fieldKey)
|
||||
{
|
||||
itemKey = "";
|
||||
behaviorKind = "";
|
||||
behaviorGroup = -1;
|
||||
fieldKey = -1;
|
||||
|
||||
var parts = (stateRef ?? "").Split('/');
|
||||
if (parts.Length != 8 ||
|
||||
!string.Equals(parts[0], "aetheria.state", StringComparison.Ordinal) ||
|
||||
!string.Equals(parts[1], "items", StringComparison.Ordinal) ||
|
||||
!string.Equals(parts[3], "behaviors", StringComparison.Ordinal) ||
|
||||
!string.Equals(parts[6], "stats", StringComparison.Ordinal) ||
|
||||
!int.TryParse(parts[5], NumberStyles.Integer, CultureInfo.InvariantCulture, out behaviorGroup) ||
|
||||
!int.TryParse(parts[7], NumberStyles.Integer, CultureInfo.InvariantCulture, out fieldKey))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
itemKey = DecodeRefToken(parts[2]);
|
||||
behaviorKind = DecodeRefToken(parts[4]);
|
||||
return !string.IsNullOrWhiteSpace(itemKey) && !string.IsNullOrWhiteSpace(behaviorKind);
|
||||
}
|
||||
|
||||
private static bool ItemKeyMatches(EquippableItem item, string itemKey)
|
||||
{
|
||||
return item != null &&
|
||||
string.Equals(item.ItemKey ?? "", itemKey ?? "", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static string DecodeRefToken(string token)
|
||||
{
|
||||
return (token ?? "").Replace("%2F", "/", StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue ToRuntimeBehaviorValue(PerformanceStat stat)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameCult.Aetheria.State.Verse;
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Eve.UnityUIToolkit;
|
||||
|
|
@ -45,6 +46,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
EveSurfaceDocument surface,
|
||||
Action<EveSurfaceCommandRequest> commandHandler,
|
||||
AetheriaEveUnitySurfaceChrome chrome,
|
||||
Func<string, string> stateRefResolver = null,
|
||||
int sortingOrder = 1000)
|
||||
{
|
||||
if (owner == null)
|
||||
|
|
@ -60,6 +62,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
var root = document.rootVisualElement;
|
||||
ConfigureRoot(root, chrome);
|
||||
|
||||
surface = ResolveStateRefs(surface, stateRefResolver);
|
||||
var lowerer = new EveUiToolkitSurfaceLowerer();
|
||||
if (chrome.UseShell)
|
||||
{
|
||||
|
|
@ -82,6 +85,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
AetheriaRuntimeSurfaceDocument surface,
|
||||
Action<EveSurfaceCommandRequest> commandHandler,
|
||||
AetheriaEveUnitySurfaceChrome chrome,
|
||||
Func<string, string> stateRefResolver = null,
|
||||
int sortingOrder = 1000)
|
||||
{
|
||||
if (surface == null)
|
||||
|
|
@ -94,6 +98,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface),
|
||||
commandHandler,
|
||||
chrome,
|
||||
stateRefResolver,
|
||||
sortingOrder);
|
||||
}
|
||||
|
||||
|
|
@ -183,5 +188,69 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
shell.pickingMode = chrome.ShellPickingMode;
|
||||
return shell;
|
||||
}
|
||||
|
||||
private static EveSurfaceDocument ResolveStateRefs(
|
||||
EveSurfaceDocument surface,
|
||||
Func<string, string> stateRefResolver)
|
||||
{
|
||||
if (surface == null || stateRefResolver == null)
|
||||
return surface;
|
||||
|
||||
return new EveSurfaceDocument(
|
||||
surface.Type,
|
||||
surface.Schema,
|
||||
surface.ProviderId,
|
||||
surface.ProviderKind,
|
||||
surface.Title,
|
||||
surface.Version,
|
||||
surface.UpdatedAtUtc,
|
||||
new EveSurfaceTree(
|
||||
surface.Surface.Id,
|
||||
ResolveStateRefs(surface.Surface.Root, stateRefResolver),
|
||||
surface.Surface.Styles),
|
||||
surface.Commands);
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent ResolveStateRefs(
|
||||
EveSurfaceComponent component,
|
||||
Func<string, string> stateRefResolver)
|
||||
{
|
||||
var props = new Dictionary<string, string>(component.Props, StringComparer.Ordinal);
|
||||
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Value, "value", stateRefResolver);
|
||||
ResolvePropRef(props, AetheriaRuntimeSurfaceStateRefs.Label, "label", stateRefResolver);
|
||||
|
||||
return new EveSurfaceComponent(
|
||||
component.Id,
|
||||
component.Kind,
|
||||
props,
|
||||
ResolveStateRefs(component.Children, stateRefResolver));
|
||||
}
|
||||
|
||||
private static IReadOnlyList<EveSurfaceComponent> ResolveStateRefs(
|
||||
IReadOnlyList<EveSurfaceComponent> children,
|
||||
Func<string, string> stateRefResolver)
|
||||
{
|
||||
if (children == null || children.Count == 0)
|
||||
return Array.Empty<EveSurfaceComponent>();
|
||||
|
||||
var resolved = new EveSurfaceComponent[children.Count];
|
||||
for (var index = 0; index < children.Count; index++)
|
||||
resolved[index] = ResolveStateRefs(children[index], stateRefResolver);
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private static void ResolvePropRef(
|
||||
Dictionary<string, string> props,
|
||||
string refKey,
|
||||
string valueKey,
|
||||
Func<string, string> stateRefResolver)
|
||||
{
|
||||
if (!props.TryGetValue(refKey, out var stateRef) || string.IsNullOrWhiteSpace(stateRef))
|
||||
return;
|
||||
|
||||
var resolved = stateRefResolver(stateRef);
|
||||
if (!string.IsNullOrWhiteSpace(resolved))
|
||||
props[valueKey] = resolved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,16 +7,18 @@ namespace GameCult.Aetheria.State.Verse
|
|||
{
|
||||
public sealed class AetheriaRuntimeCargoItemMetric
|
||||
{
|
||||
public AetheriaRuntimeCargoItemMetric(string id, string label, string value)
|
||||
public AetheriaRuntimeCargoItemMetric(string id, string label, string value, string valueRef = "")
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Value = value ?? "";
|
||||
ValueRef = valueRef ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Value { get; }
|
||||
public string ValueRef { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeCargoItemSection
|
||||
|
|
@ -157,7 +159,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
: section.Id,
|
||||
section.Title,
|
||||
section.Metrics
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value))
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value, metric.ValueRef))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -203,9 +205,18 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value, string valueRef = "")
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("value", value ?? "")
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(valueRef))
|
||||
props.Add(AetheriaRuntimeSurfaceStateRefs.ValueRef(valueRef));
|
||||
|
||||
return Node(id, "metric", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
|
|
|
|||
|
|
@ -8,16 +8,18 @@ namespace GameCult.Aetheria.State.Verse
|
|||
{
|
||||
public sealed class AetheriaRuntimeEquippedItemMetric
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemMetric(string id, string label, string value)
|
||||
public AetheriaRuntimeEquippedItemMetric(string id, string label, string value, string valueRef = "")
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Value = value ?? "";
|
||||
ValueRef = valueRef ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Value { get; }
|
||||
public string ValueRef { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEquippedItemSection
|
||||
|
|
@ -218,7 +220,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
: section.Id,
|
||||
section.Title,
|
||||
section.Metrics
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value))
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value, metric.ValueRef))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
|
|
@ -335,9 +337,18 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value, string valueRef = "")
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("value", value ?? "")
|
||||
};
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(valueRef))
|
||||
props.Add(AetheriaRuntimeSurfaceStateRefs.ValueRef(valueRef));
|
||||
|
||||
return Node(id, "metric", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
|
|
|
|||
Loading…
Reference in a new issue