From 88629e0c45a0b3340b1abfaa90ca96fe3d0c08c1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 12 Jul 2026 23:29:14 +0100 Subject: [PATCH] Publish portable Eve entity and input state --- Aetheria.State.Daemon/Program.cs | 4 +- Aetheria.State/Aetheria.State.csproj | 12 ++-- Aetheria.State/AetheriaDocumentRegistry.cs | 2 +- .../Runtime/AetheriaRuntimeAssets.cs | 11 +++ ...AetheriaRuntimeDaemonGameSurfaceBuilder.cs | 17 +---- .../AetheriaRuntimeDaemonSoaDocuments.cs | 23 ++++++- .../AetheriaRuntimeDaemonSoaFramePublisher.cs | 13 +++- .../AetheriaRuntimeEveEntitySoaProjection.cs | 12 ++++ ...AetheriaRuntimeInputCapabilityDocuments.cs | 69 +++++++++++++++++-- 9 files changed, 131 insertions(+), 32 deletions(-) diff --git a/Aetheria.State.Daemon/Program.cs b/Aetheria.State.Daemon/Program.cs index 7956846cb..8932668d4 100644 --- a/Aetheria.State.Daemon/Program.cs +++ b/Aetheria.State.Daemon/Program.cs @@ -1390,8 +1390,8 @@ static async Task PublishDaemonApiDocumentsAsync( await node.MutableDocument(AetheriaRuntimeVerseRecordKeys.StarbridgeSessionSummary) .ReplaceAsync(result.StarbridgeSessionSummary) .ConfigureAwait(false); - await node.MutableDocument(AetheriaRuntimeVerseRecordKeys.PilotInputCapability) - .ReplaceAsync(AetheriaRuntimeInputCapabilityDocument.FromFrame(result.Frame)) + await node.MutableDocument(AetheriaRuntimeVerseRecordKeys.PilotInputCapability) + .ReplaceAsync(AetheriaRuntimeInputCapabilityDocument.FromFrame(result.Frame).ToEveDocument()) .ConfigureAwait(false); var mainMenuState = await node.MutableDocument(AetheriaStateNode.MainMenuStateKey) .ReadAsync() diff --git a/Aetheria.State/Aetheria.State.csproj b/Aetheria.State/Aetheria.State.csproj index 8de9bb1e7..b1e0aa94d 100644 --- a/Aetheria.State/Aetheria.State.csproj +++ b/Aetheria.State/Aetheria.State.csproj @@ -5,16 +5,18 @@ latest enable Typed CultCache and CultMesh state spine for Aetheria. + $(MSBuildThisFileDirectory)..\..\EveUnity + $(MSBuildThisFileDirectory)..\..\CultLib - - - - + + + + - + diff --git a/Aetheria.State/AetheriaDocumentRegistry.cs b/Aetheria.State/AetheriaDocumentRegistry.cs index ecf320eaa..0417fc0c4 100644 --- a/Aetheria.State/AetheriaDocumentRegistry.cs +++ b/Aetheria.State/AetheriaDocumentRegistry.cs @@ -60,7 +60,7 @@ public static class AetheriaDocumentRegistry typeof(AetheriaRuntimeStarbridgeScenarioDocument), typeof(AetheriaRuntimeStarbridgeSessionDocument), typeof(AetheriaRuntimeStarbridgeSessionSummaryDocument), - typeof(AetheriaRuntimeInputCapabilityDocument), + typeof(EveInputCapabilityDocument), typeof(AetheriaRuntimeDaemonSoaViewDocument), typeof(AetheriaRuntimeVerseAuthorityPolicyDocument), typeof(AetheriaRuntimeAuthorityLeaseDocument), diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs index 75e923fd0..7c4509ee5 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeAssets.cs @@ -8,6 +8,17 @@ namespace GameCult.Aetheria.State.Verse { public static class AetheriaRuntimeAssets { + public static string ResolveEntityPrefabAssetRef(AetheriaRuntimeEntitySnapshotCommit entity) + { + if (entity == null) return ""; + var kind = (entity.Kind ?? "").Trim().ToLowerInvariant(); + if (kind.Contains("station")) return "prefab.entity.station"; + if (kind.Contains("projectile")) return "prefab.entity.projectile"; + if (kind.Contains("orbital")) return "prefab.entity.orbital"; + return string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase) + ? "prefab.entity.player" + : "prefab.entity.ship"; + } public static AetheriaRuntimeAssetManifestDocument ProjectManifest( AetheriaRuntimeCatalogSnapshot? catalog, string runId = "", diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs index 0860ae824..55b089645 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonGameSurfaceBuilder.cs @@ -576,6 +576,7 @@ namespace GameCult.Aetheria.State.Verse ["zoneRenderPointerId"] = AetheriaRuntimeVerseRecordKeys.ZoneRenderLatest.ToString(), ["zoneRenderSchema"] = AetheriaRuntimeDaemonSchemas.ZoneRender, ["assetManifest"] = AetheriaRuntimeVerseRecordKeys.EveAssetCatalog.ToString(), + ["inputCapability"] = AetheriaRuntimeVerseRecordKeys.PilotInputCapability.ToString(), ["inputProfile"] = "arpg.pointer-keyboard.v1", ["cameraRig"] = "arpg.orbital-follow.v1", ["viewId"] = "pilot", @@ -878,21 +879,7 @@ namespace GameCult.Aetheria.State.Verse } private static string PlayableWorldAssetRef(AetheriaRuntimeEntitySnapshotCommit entity) - { - if (entity == null) - return ""; - - var kind = (entity.Kind ?? "").Trim().ToLowerInvariant(); - if (kind.Contains("station")) - return "prefab.entity.station"; - if (kind.Contains("projectile")) - return "prefab.entity.projectile"; - if (kind.Contains("orbital")) - return "prefab.entity.orbital"; - if (string.Equals(entity.FactionKey, "player", StringComparison.OrdinalIgnoreCase)) - return "prefab.entity.player"; - return "prefab.entity.ship"; - } + => AetheriaRuntimeAssets.ResolveEntityPrefabAssetRef(entity); private static double PlayableWorldRadius(AetheriaRuntimeEntitySnapshotCommit entity) { diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaDocuments.cs index 8ee64d80c..ea32e91a3 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaDocuments.cs @@ -97,6 +97,10 @@ namespace GameCult.Aetheria.State.Verse public IReadOnlyList RenderGroups { get; set; } = Array.Empty(); + [Key(13)] + public IReadOnlyList Identities { get; set; } = + Array.Empty(); + public static AetheriaRuntimeDaemonSoaViewDocument Create( string daemonId, string sessionId, @@ -108,7 +112,8 @@ namespace GameCult.Aetheria.State.Verse string backend = AetheriaRuntimeDaemonSoaBackends.CultCache, string synchronizationMode = AetheriaRuntimeDaemonSoaSynchronizationModes.ImmutableFrame, bool isAuthoritative = true, - IReadOnlyList? renderGroups = null) + IReadOnlyList? renderGroups = null, + IReadOnlyList? identities = null) { return new AetheriaRuntimeDaemonSoaViewDocument { @@ -125,11 +130,25 @@ namespace GameCult.Aetheria.State.Verse Buffers = buffers ?? Array.Empty(), Columns = columns ?? Array.Empty(), DirtyRanges = dirtyRanges ?? Array.Empty(), - RenderGroups = renderGroups ?? Array.Empty() + RenderGroups = renderGroups ?? Array.Empty(), + Identities = identities ?? Array.Empty() }; } } + [MessagePackObject] + public sealed class AetheriaRuntimeDaemonSoaIdentityDocument + { + [Key(0)] public int EntityIndex { get; set; } = -1; + [Key(1)] public string EntityId { get; set; } = ""; + [Key(2)] public string Kind { get; set; } = ""; + [Key(3)] public string Label { get; set; } = ""; + [Key(4)] public string Faction { get; set; } = ""; + [Key(5)] public bool Selectable { get; set; } = true; + [Key(6)] public bool Controllable { get; set; } + [Key(7)] public string AssetRef { get; set; } = ""; + } + [MessagePackObject] public sealed class AetheriaRuntimeDaemonRenderGroupDocument { diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaFramePublisher.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaFramePublisher.cs index a030ee620..fba86ef5c 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaFramePublisher.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonSoaFramePublisher.cs @@ -76,7 +76,18 @@ namespace GameCult.Aetheria.State.Verse layout.CreateDirtyRanges(count, generation), backend: AetheriaRuntimeDaemonSoaBackends.MemoryMappedFile, synchronizationMode: AetheriaRuntimeDaemonSoaSynchronizationModes.ImmutableFrame, - renderGroups: CreateRenderGroups(entities)); + renderGroups: CreateRenderGroups(entities), + identities: entities.Select(entity => new AetheriaRuntimeDaemonSoaIdentityDocument + { + EntityIndex = entity.EntityIndex, + EntityId = entity.EntityId, + Kind = entity.Kind, + Label = entity.Name, + Faction = entity.FactionKey, + Selectable = true, + Controllable = string.Equals(entity.EntityId, run.CurrentEntityKey, StringComparison.Ordinal), + AssetRef = AetheriaRuntimeAssets.ResolveEntityPrefabAssetRef(entity) + }).ToArray()); return view; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveEntitySoaProjection.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveEntitySoaProjection.cs index 977881d5e..66e4ae9d0 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveEntitySoaProjection.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeEveEntitySoaProjection.cs @@ -70,6 +70,18 @@ namespace GameCult.Aetheria.State.Verse ShadowMode = group.ShadowMode, ReceiveShadows = group.ReceiveShadows, Lod = group.Lod + }).ToArray(), + Identities = (source.Identities ?? Array.Empty()) + .Select(identity => new EveEntitySoaIdentity + { + EntityIndex = identity.EntityIndex, + EntityId = identity.EntityId, + Kind = identity.Kind, + Label = identity.Label, + Faction = identity.Faction, + Selectable = identity.Selectable, + Controllable = identity.Controllable, + AssetRef = identity.AssetRef }).ToArray() }; } diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs index 4666c19b6..a359c2031 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeInputCapabilityDocuments.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using GameCult.Caching; +using GameCult.Eve.Surface; using MessagePack; namespace GameCult.Aetheria.State.Verse @@ -45,7 +46,6 @@ namespace GameCult.Aetheria.State.Verse [Key(2)] public AetheriaRuntimeInputBindingDocument[] Bindings { get; set; } = Array.Empty(); } - [CultDocument("gamecult.eve.input_capability", "gamecult.eve.input_capability.v1")] [MessagePackObject] public sealed class AetheriaRuntimeInputCapabilityDocument { @@ -69,12 +69,11 @@ namespace GameCult.Aetheria.State.Verse actions.AddRange((entity.Equipment ?? Array.Empty()).Where(slot => slot?.Item != null).Select((slot, index) => Action($"equipment.{index}.activate", $"Activate {slot.Item.ItemKey}", "SetBehaviorActive", "equipment", $"{run.CurrentEntityKey}#equipment/{index}", ("equipmentIndex", index.ToString()), ("behaviorIndex", "0"), ("active", "true")))); actions.AddRange((entity.CargoContents ?? Array.Empty()).SelectMany(bay => bay.Items).Where(slot => slot?.Item != null).Select((slot, index) => Action($"cargo.{slot.Item.ItemKey}.{index}.use", $"Use {slot.Item.ItemKey}", "ActivateConsumable", "consumable", $"{run.CurrentEntityKey}#cargo/{index}", ("itemKey", slot.Item.ItemKey)))); } - return new AetheriaRuntimeInputCapabilityDocument { Version = frame?.FrameId ?? 0, Actions = actions.ToArray(), DefaultProfiles = BuildDefaultProfiles() }; + return new AetheriaRuntimeInputCapabilityDocument { Version = frame?.FrameId ?? 0, Actions = actions.ToArray(), DefaultProfiles = BuildDefaultProfiles(actions) }; } private static IEnumerable CoreActions() { - yield return Action("pilot.fire", "Fire", "FireWeaponGroup", "combat", "pilot", ("weaponGroup", "0")); yield return Action("pilot.scoop", "Scoop", "SetTractorPower", "ship", "pilot", ("scalarValue", "1")); yield return Action("pilot.dock", "Dock", "DockNearest", "ship", "pilot"); yield return Action("pilot.undock", "Undock", "Undock", "ship", "pilot"); @@ -84,10 +83,68 @@ namespace GameCult.Aetheria.State.Verse private static AetheriaRuntimeInputActionDocument Action(string id, string label, string operation, string category, string source, params (string Key, string Value)[] payload) => new AetheriaRuntimeInputActionDocument { ActionId = id, Label = label, Operation = "aetheria.daemon.commands." + operation, Category = category, SourceRef = source, Payload = payload.ToDictionary(entry => entry.Key, entry => entry.Value, StringComparer.Ordinal) }; - private static AetheriaRuntimeInputProfileDocument[] BuildDefaultProfiles() => new[] + private static AetheriaRuntimeInputProfileDocument[] BuildDefaultProfiles(IReadOnlyCollection actions) { - Profile("keyboard-mouse", "keyboard-mouse", Binding("fire.mouse", "pilot.fire", "direct", "mouse.primary"), Binding("scoop.shift", "pilot.scoop", "direct", "keyboard.leftShift"), Binding("dock.r", "pilot.dock", "direct", "keyboard.r")), - Profile("gamepad", "gamepad", Binding("fire.trigger", "pilot.fire", "direct", "gamepad.rightTrigger"), Binding("scoop.sequence", "pilot.scoop", "sequence", "gamepad.dpad.down", "gamepad.dpad.right"), Binding("dock.sequence", "pilot.dock", "sequence", "gamepad.dpad.down", "gamepad.dpad.up")) + return new[] + { + Profile("keyboard-mouse", "keyboard-mouse", DefaultBindings(actions, "mouse.primary", "gamepad.rightTrigger", keyboard: true)), + Profile("gamepad", "gamepad", DefaultBindings(actions, "mouse.primary", "gamepad.rightTrigger", keyboard: false)) + }; + } + + private static AetheriaRuntimeInputBindingDocument[] DefaultBindings( + IReadOnlyCollection actions, + string keyboardFireControl, + string gamepadFireControl, + bool keyboard) + { + var bindings = new List(); + var fire = actions.FirstOrDefault(action => string.Equals(action.Category, "weapon-group", StringComparison.Ordinal)); + if (fire != null) + bindings.Add(Binding("fire.default", fire.ActionId, "direct", keyboard ? keyboardFireControl : gamepadFireControl)); + bindings.Add(keyboard + ? Binding("scoop.shift", "pilot.scoop", "direct", "keyboard.leftShift") + : Binding("scoop.sequence", "pilot.scoop", "sequence", "gamepad.dpad.down", "gamepad.dpad.right")); + bindings.Add(keyboard + ? Binding("dock.r", "pilot.dock", "direct", "keyboard.r") + : Binding("dock.sequence", "pilot.dock", "sequence", "gamepad.dpad.down", "gamepad.dpad.up")); + return bindings.ToArray(); + } + + public EveInputCapabilityDocument ToEveDocument() => new EveInputCapabilityDocument + { + ProviderId = ProviderId, + CapabilityId = CapabilityId, + Version = Version, + Actions = Actions.Select(action => new EveInputActionDocument + { + ActionId = action.ActionId, + Label = action.Label, + Operation = action.Operation, + Context = action.Context, + Category = action.Category, + Availability = action.Availability, + SourceRef = action.SourceRef, + Payload = new Dictionary(action.Payload, StringComparer.Ordinal) + }).ToArray(), + DefaultProfiles = DefaultProfiles.Select(profile => new EveInputProfileDocument + { + ProfileId = profile.ProfileId, + DeviceClass = profile.DeviceClass, + Bindings = profile.Bindings.Select(binding => new EveInputBindingDocument + { + BindingId = binding.BindingId, + ActionId = binding.ActionId, + ActionBar = binding.ActionBar, + Gesture = new EveInputGestureDocument + { + Kind = binding.Gesture.Kind, + Controls = binding.Gesture.Controls, + MaxStepIntervalMs = binding.Gesture.MaxStepIntervalMs, + CompletionControl = binding.Gesture.CompletionControl + } + }).ToArray() + }).ToArray() }; private static AetheriaRuntimeInputProfileDocument Profile(string id, string device, params AetheriaRuntimeInputBindingDocument[] bindings) => new AetheriaRuntimeInputProfileDocument { ProfileId = id, DeviceClass = device, Bindings = bindings };