Use typed metadata for trade behavior filters
This commit is contained in:
parent
3e616ae988
commit
77b2c74375
4 changed files with 58 additions and 60 deletions
Binary file not shown.
|
|
@ -2,8 +2,6 @@ using System;
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
|
@ -150,16 +148,18 @@ public class TradeMenu : MonoBehaviour
|
|||
_compoundCommodityFilter.type = x;
|
||||
Populate();
|
||||
}, true)));
|
||||
ContextMenu.AddDropdown("Item Behavior", TypedBehaviorFilterOptions
|
||||
.Where(option => _behaviorFilters.All(filter => filter.Kind != option.Name))
|
||||
.Select<Type, (string, Action, bool)>(x=> (x.Name.FormatTypeName(), () =>
|
||||
ContextMenu.AddDropdown("Item Behavior", AetheriaRuntimeBehaviorMetadataCatalog.All
|
||||
.Where(option => _behaviorFilters.All(filter => filter.Kind != option.Kind))
|
||||
.OrderBy(option => option.Kind, StringComparer.Ordinal)
|
||||
.Select<AetheriaRuntimeBehaviorMetadata, (string, Action, bool)>(x=> (x.Kind.FormatTypeName(), () =>
|
||||
{
|
||||
var matchingType = _behaviorFilters.FirstOrDefault(y =>
|
||||
y.MetadataType.IsAssignableFrom(x) || x.IsAssignableFrom(y.MetadataType));
|
||||
AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(y.Kind, x.Kind) ||
|
||||
AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(x.Kind, y.Kind));
|
||||
if (matchingType?.Filter != null) matchingType.Filter.DisableButton.onClick.Invoke();
|
||||
var filter = FilterPrototype.Instantiate<ItemFilter>();
|
||||
filter.Label.text = x.Name.FormatTypeName();
|
||||
var behaviorFilter = new BehaviorFilter(filter, x.Name, x);
|
||||
filter.Label.text = x.Kind.FormatTypeName();
|
||||
var behaviorFilter = new BehaviorFilter(filter, x);
|
||||
filter.OnDisable += () =>
|
||||
{
|
||||
_behaviorFilters.Remove(behaviorFilter);
|
||||
|
|
@ -255,10 +255,9 @@ public class TradeMenu : MonoBehaviour
|
|||
{
|
||||
items = items.Where(i => HasTypedBehavior(i.TypedItem, behaviorFilter));
|
||||
|
||||
foreach (var field in behaviorFilter.MetadataType.GetFields().Where(f => f.GetCustomAttribute<RuntimeInspectable>() != null))
|
||||
foreach (var field in behaviorFilter.Metadata.DisplayFields)
|
||||
{
|
||||
var fieldType = field.FieldType;
|
||||
if (fieldType == typeof(float))
|
||||
if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.Number)
|
||||
columns.Add((field.Name, 1, x =>
|
||||
{
|
||||
var value = GetTypedBehaviorNumber(x, behaviorFilter, field);
|
||||
|
|
@ -267,7 +266,7 @@ public class TradeMenu : MonoBehaviour
|
|||
{
|
||||
return (float)GetTypedBehaviorNumber(x, behaviorFilter, field);
|
||||
}));
|
||||
else if (fieldType == typeof(int))
|
||||
else if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.Integer)
|
||||
columns.Add((field.Name, 1, x =>
|
||||
{
|
||||
var value = GetTypedBehaviorNumber(x, behaviorFilter, field);
|
||||
|
|
@ -276,7 +275,7 @@ public class TradeMenu : MonoBehaviour
|
|||
{
|
||||
return (int)GetTypedBehaviorNumber(x, behaviorFilter, field);
|
||||
}));
|
||||
else if (fieldType == typeof(PerformanceStat))
|
||||
else if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat)
|
||||
{
|
||||
columns.Add((field.Name, 1, x =>
|
||||
{
|
||||
|
|
@ -402,22 +401,16 @@ public class TradeMenu : MonoBehaviour
|
|||
return ActionGameManager.RuntimeCatalog?.FindItemByLegacyId(item.Data.ItemId.ToString("D"));
|
||||
}
|
||||
|
||||
private static double GetTypedBehaviorNumber(TradeRow row, BehaviorFilter behaviorFilter, FieldInfo field)
|
||||
private static double GetTypedBehaviorNumber(TradeRow row, BehaviorFilter behaviorFilter, AetheriaRuntimeBehaviorFieldMetadata field)
|
||||
{
|
||||
var key = field.GetCustomAttribute<LegacyPayloadKeyAttribute>()?.Key;
|
||||
if (key == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
var payload = FindTypedBehaviorPayload(row.TypedItem, behaviorFilter);
|
||||
var payloadField = payload?.Fields.FirstOrDefault(candidate => candidate.Key == key.Value);
|
||||
var payloadField = payload?.Fields.FirstOrDefault(candidate => candidate.Key == field.Key);
|
||||
if (payloadField == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (field.FieldType == typeof(PerformanceStat))
|
||||
if (field.ValueKind == AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat)
|
||||
{
|
||||
return payloadField.Value.Children.Count > 1
|
||||
? payloadField.Value.Children[1].NumberValue
|
||||
|
|
@ -444,47 +437,20 @@ public class TradeMenu : MonoBehaviour
|
|||
|
||||
private static bool TypedBehaviorMatches(AetheriaRuntimeBehaviorPayload payload, BehaviorFilter behaviorFilter)
|
||||
{
|
||||
if (string.Equals(payload.Kind, behaviorFilter.Kind, StringComparison.Ordinal))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var payloadType = ResolveBehaviorType(payload.Kind);
|
||||
return payloadType != null && behaviorFilter.MetadataType.IsAssignableFrom(payloadType);
|
||||
return AetheriaRuntimeBehaviorMetadataCatalog.IsKindOrDescendant(payload.Kind, behaviorFilter.Kind);
|
||||
}
|
||||
|
||||
private static Type ResolveBehaviorType(string kind)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(kind)
|
||||
? null
|
||||
: BehaviorTypesByName.TryGetValue(kind, out var type)
|
||||
? type
|
||||
: null;
|
||||
}
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, Type> BehaviorTypesByName = typeof(BehaviorData)
|
||||
.GetAllChildClasses()
|
||||
.Where(type => !string.IsNullOrWhiteSpace(type.Name))
|
||||
.GroupBy(type => type.Name)
|
||||
.ToDictionary(group => group.Key, group => group.First(), StringComparer.Ordinal);
|
||||
|
||||
private static readonly IReadOnlyList<Type> TypedBehaviorFilterOptions = BehaviorTypesByName.Values
|
||||
.Where(type => type.GetCustomAttribute<RuntimeInspectable>() != null)
|
||||
.OrderBy(type => type.Name, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
private sealed class BehaviorFilter
|
||||
{
|
||||
public BehaviorFilter(ItemFilter filter, string kind, Type metadataType)
|
||||
public BehaviorFilter(ItemFilter filter, AetheriaRuntimeBehaviorMetadata metadata)
|
||||
{
|
||||
Filter = filter ?? throw new ArgumentNullException(nameof(filter));
|
||||
Kind = string.IsNullOrWhiteSpace(kind) ? "" : kind;
|
||||
MetadataType = metadataType ?? throw new ArgumentNullException(nameof(metadataType));
|
||||
Metadata = metadata ?? throw new ArgumentNullException(nameof(metadata));
|
||||
}
|
||||
|
||||
public ItemFilter Filter { get; }
|
||||
public string Kind { get; }
|
||||
public Type MetadataType { get; }
|
||||
public AetheriaRuntimeBehaviorMetadata Metadata { get; }
|
||||
public string Kind => Metadata.Kind;
|
||||
}
|
||||
|
||||
private sealed class TradeRow
|
||||
|
|
|
|||
|
|
@ -65,6 +65,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
Behavior("AetherDrive", "", Stat("MaximumRpm", 3), Stat("CouplingEfficiency", 6), Stat("Torque", 7), Stat("EnergyDraw", 9), Stat("PassiveCoupling", 10)),
|
||||
Behavior("Capacitor", "", Stat("Capacity", 1), Stat("Efficiency", 2)),
|
||||
Behavior("ChargedWeapon", AetheriaRuntimeBehaviorKinds.InstantWeapon, With(InstantWeaponFields, Stat("ChargeTime", 21), Stat("ChargeEnergy", 22), Stat("ChargeHeat", 23))),
|
||||
Behavior("Cockpit", ""),
|
||||
Behavior("ConstantWeapon", "Weapon", WeaponFields),
|
||||
Behavior(AetheriaRuntimeBehaviorKinds.GuidedWeapon, AetheriaRuntimeBehaviorKinds.InstantWeapon, With(InstantWeaponFields, Stat("MissileVelocity", 26))),
|
||||
Behavior(AetheriaRuntimeBehaviorKinds.Launcher, "LockWeapon", With(LockWeaponFields, Stat("MissileVelocity", 31))),
|
||||
|
|
@ -73,6 +74,8 @@ namespace GameCult.Aetheria.State.Unity
|
|||
Behavior(AetheriaRuntimeBehaviorKinds.AutoWeapon, AetheriaRuntimeBehaviorKinds.InstantWeapon, InstantWeaponFields),
|
||||
Behavior("Cooldown", "", Stat("Cooldown", 1)),
|
||||
Behavior("EnergyDraw", "", Stat("EnergyDraw", 1)),
|
||||
Behavior("HeatStorage", ""),
|
||||
Behavior("ItemUsage", ""),
|
||||
Behavior("Radiator", "", Stat("Emissivity", 1), Stat("PumpedHeat", 2), Number("TemperatureFloor", 3), Stat("WasteHeat", 4), Stat("EnergyUsage", 5), Stat("ThermalMass", 6)),
|
||||
Behavior("Reactor", "", Stat("Charge", 1), Stat("Efficiency", 2), Stat("OverloadEfficiency", 3), Stat("ThrottlingFactor", 4)),
|
||||
Behavior("Reflector", "", Stat("CrossSection", 1)),
|
||||
|
|
@ -80,9 +83,12 @@ namespace GameCult.Aetheria.State.Unity
|
|||
Behavior("Sensor", "", Stat("Sensitivity", 3), Stat("PingBoost", 5), Stat("PingEnergy", 6), Stat("PingVisibility", 7), Stat("PingRange", 8), Stat("PingCooldown", 9)),
|
||||
Behavior("Shield", "", Stat("Efficiency", 1), Stat("EnergyUsage", 2)),
|
||||
Behavior("Thruster", "", Stat("Thrust", 1), Stat("Visibility", 2), Stat("Heat", 3), Stat("EnergyUsage", 4)),
|
||||
Behavior("TurretController", ""),
|
||||
Behavior("VelocityConversion", "", Stat("Lambda", 1)),
|
||||
Behavior("VelocityLimit", "", Stat("TopSpeed", 1)),
|
||||
Behavior("Visibility", "", Stat("Visibility", 1))
|
||||
Behavior("Visibility", "", Stat("Visibility", 1)),
|
||||
Behavior("Weapon", "", WeaponFields),
|
||||
Behavior("Wear", "")
|
||||
}
|
||||
.ToDictionary(metadata => metadata.Kind, StringComparer.Ordinal);
|
||||
|
||||
|
|
@ -95,6 +101,29 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
public static IReadOnlyList<AetheriaRuntimeBehaviorMetadata> All => ByKind.Values.ToArray();
|
||||
|
||||
public static bool IsKindOrDescendant(string candidateKind, string expectedKind)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(candidateKind) || string.IsNullOrWhiteSpace(expectedKind))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var currentKind = candidateKind;
|
||||
while (!string.IsNullOrWhiteSpace(currentKind))
|
||||
{
|
||||
if (string.Equals(currentKind, expectedKind, StringComparison.Ordinal))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
currentKind = ByKind.TryGetValue(currentKind, out var metadata)
|
||||
? metadata.ParentKind
|
||||
: "";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorMetadata Behavior(
|
||||
string kind,
|
||||
string parentKind,
|
||||
|
|
|
|||
|
|
@ -166,9 +166,10 @@ legacy catalog cache, and legacy UI paths should be migration-only or deleted.
|
|||
wraps rows in a typed `TradeRow`: name, mass, price, size, hardpoint type,
|
||||
commodity subtype, hull ownership, and behavior-kind filters read typed
|
||||
catalog rows before any legacy projection is hydrated. Active behavior
|
||||
filters store typed behavior kind keys and match typed behavior payloads;
|
||||
`BehaviorData` reflection is only temporary TradeMenu option/column metadata.
|
||||
PropertiesPanel display metadata is now package-owned typed behavior metadata.
|
||||
filters store typed behavior kind keys and match typed behavior payloads
|
||||
through package-owned typed behavior metadata, including parent-kind matching
|
||||
for behavior families. PropertiesPanel and TradeMenu display metadata are now
|
||||
package-owned typed behavior metadata.
|
||||
Dynamic behavior columns read typed behavior payload fields by legacy payload key
|
||||
instead of hydrating `BehaviorData` DTOs. Trade buy decisions for crafted price,
|
||||
ship-hull classification, simple commodity base price, and simple commodity
|
||||
|
|
@ -770,8 +771,10 @@ First Aetheria surfaces to publish:
|
|||
metadata.
|
||||
- Done: move PropertiesPanel generic behavior stat display off
|
||||
`BehaviorData` reflection and onto package-owned typed behavior display
|
||||
metadata keyed by behavior kind and payload field key. TradeMenu still has
|
||||
the remaining temporary `BehaviorData` display/filter metadata bridge.
|
||||
metadata keyed by behavior kind and payload field key.
|
||||
- Done: move TradeMenu behavior filter options, behavior family matching,
|
||||
and dynamic behavior columns off `BehaviorData` reflection and onto
|
||||
package-owned typed behavior metadata.
|
||||
- Done: remove the loot pickup presentation fallback to legacy `ItemData`;
|
||||
typed category/name rows now decide pickup visuals and scan labels, and
|
||||
missing typed rows render generic unknown gear pickup presentation.
|
||||
|
|
|
|||
Loading…
Reference in a new issue