Sync daemon authority migration
This commit is contained in:
parent
030b4b5d74
commit
39a0dc8737
295 changed files with 25121 additions and 7360 deletions
|
|
@ -1,26 +1,31 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.ai.navigation": "2.0.12",
|
||||
"com.unity.burst": "1.8.29",
|
||||
"com.unity.cinemachine": "2.10.7",
|
||||
"com.gamecult.brokkr": "file:../../Brokkr/surfaces/unity/Packages/com.gamecult.brokkr/",
|
||||
"com.unity.ide.rider": "3.0.39",
|
||||
"com.unity.ide.visualstudio": "2.0.27",
|
||||
"com.unity.inputsystem": "1.19.0",
|
||||
"com.unity.entities.graphics": "1.4.20",
|
||||
"org.gamecult.cultmath": "file:../../CultMath",
|
||||
"com.unity.mathematics": "1.3.3",
|
||||
"com.unity.multiplayer.center": "1.0.1",
|
||||
"com.unity.postprocessing": "3.5.4",
|
||||
"com.unity.recorder": "5.1.5",
|
||||
"com.unity.render-pipelines.universal": "17.2.0",
|
||||
"com.unity.test-framework": "1.6.0",
|
||||
"com.unity.timeline": "1.8.12",
|
||||
"com.unity.ugui": "2.0.0",
|
||||
"com.unity.xr.legacyinputhelpers": "3.0.1",
|
||||
"org.gamecult.aetheria.eve-runtime": "file:org.gamecult.aetheria.eve-runtime",
|
||||
"org.gamecult.aetheria.state": "file:org.gamecult.aetheria.state",
|
||||
"org.gamecult.eve.surface": "file:../../Eve/packages/org.gamecult.eve.surface",
|
||||
"org.gamecult.eve.unity-uitoolkit": "file:../../Eve/packages/org.gamecult.eve.unity-uitoolkit",
|
||||
"com.unity.2d.sprite": "1.0.0",
|
||||
"com.unity.2d.tilemap": "1.0.0",
|
||||
"com.unity.ai.navigation": "2.0.8",
|
||||
"com.unity.burst": "1.8.23",
|
||||
"com.unity.cinemachine": "2.10.4",
|
||||
"com.unity.ide.rider": "3.0.36",
|
||||
"com.unity.ide.visualstudio": "2.0.23",
|
||||
"com.unity.inputsystem": "1.14.0",
|
||||
"com.unity.mathematics": "1.3.2",
|
||||
"com.unity.multiplayer.center": "1.0.0",
|
||||
"com.unity.postprocessing": "3.5.0",
|
||||
"com.unity.recorder": "5.1.2",
|
||||
"com.unity.test-framework": "1.5.1",
|
||||
"com.unity.timeline": "1.8.7",
|
||||
"com.unity.ugui": "2.0.0",
|
||||
"com.unity.xr.legacyinputhelpers": "2.1.12",
|
||||
"com.unity.modules.accessibility": "1.0.0",
|
||||
"com.unity.modules.adaptiveperformance": "1.0.0",
|
||||
"com.unity.modules.ai": "1.0.0",
|
||||
"com.unity.modules.androidjni": "1.0.0",
|
||||
"com.unity.modules.animation": "1.0.0",
|
||||
|
|
@ -47,6 +52,7 @@
|
|||
"com.unity.modules.unitywebrequestaudio": "1.0.0",
|
||||
"com.unity.modules.unitywebrequesttexture": "1.0.0",
|
||||
"com.unity.modules.unitywebrequestwww": "1.0.0",
|
||||
"com.unity.modules.vectorgraphics": "1.0.0",
|
||||
"com.unity.modules.vehicles": "1.0.0",
|
||||
"com.unity.modules.video": "1.0.0",
|
||||
"com.unity.modules.vr": "1.0.0",
|
||||
|
|
|
|||
|
|
@ -9,13 +9,15 @@ CultCache state into Unity UI Toolkit.
|
|||
- it reads `gamecult.eve.surface.v1` from the selected typed state source, which
|
||||
is currently still a local `.cc` file transport;
|
||||
- it lowers the retained tree through `org.gamecult.eve.unity-uitoolkit`;
|
||||
- it queues renderer-emitted commands as typed `.cc.eve.pending` command
|
||||
envelopes for Aetheria's provider-owned command bridge.
|
||||
- it submits renderer-emitted commands as typed `gamecult.eve.command.v1` state
|
||||
records for Aetheria's provider-owned command bridge.
|
||||
|
||||
`AetheriaEveRuntimeBootstrap` mounts the first runtime surface after scene load.
|
||||
By default it creates a `UIDocument` host for `aetheria.operations`, so the
|
||||
provider-owned operations surface is present at runtime without a hand-wired
|
||||
scene object. Set `AETHERIA_EVE_SURFACE_ID` to mount a different surface, set
|
||||
By default it creates a `UIDocument` host for `aetheria.game`, the daemon-owned
|
||||
game surface, so Unity starts as a lowering surface for the daemon Verse member
|
||||
without a hand-wired scene object. Set `AETHERIA_EVE_SURFACE_ID` to mount a
|
||||
different daemon or provider surface such as `aetheria.game.tui`,
|
||||
`aetheria.daemon.editor`, or `aetheria.daemon.editor.tui`; set
|
||||
`AETHERIA_STATE_PATH` to override the selected local `.cc` state file (`AETHERIA_EVE_STATE_PATH`
|
||||
still works as a legacy fallback), or disable the automatic mount with
|
||||
`AETHERIA_DISABLE_EVE_RUNTIME_BOOTSTRAP=true` or
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e1c93ed85db7ef24abd1a24ca16abe4e
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/org.gamecult.aetheria.eve-runtime/Runtime.meta
Normal file
8
Packages/org.gamecult.aetheria.eve-runtime/Runtime.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2860def02295c5045af9ba820ea8e696
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
|
@ -9,7 +10,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
{
|
||||
public static class AetheriaEveRuntimeBootstrap
|
||||
{
|
||||
public const string DefaultSurfaceId = "aetheria.operations";
|
||||
public const string DefaultSurfaceId = AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId;
|
||||
public const string DisableEnvironmentVariable = "AETHERIA_DISABLE_EVE_RUNTIME_BOOTSTRAP";
|
||||
public const string SurfaceEnvironmentVariable = "AETHERIA_EVE_SURFACE_ID";
|
||||
public const string DisableCommandLineSwitch = "--aetheria-disable-eve-runtime-bootstrap";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dfb126623705ee04c9747f63b945c5f1
|
||||
|
|
@ -2,7 +2,6 @@ using System;
|
|||
using System.IO;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Eve.UnityUIToolkit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
|
|
@ -15,7 +14,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
public sealed class AetheriaEveSurfacePresenter : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private string surfaceId = "aetheria.catalog.operator";
|
||||
private string surfaceId = AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId;
|
||||
|
||||
[SerializeField]
|
||||
private string stateFilePathOverride = "";
|
||||
|
|
@ -23,7 +22,26 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
[SerializeField]
|
||||
private bool mountOnEnable = true;
|
||||
|
||||
[SerializeField]
|
||||
private bool refreshInUpdate = true;
|
||||
|
||||
[SerializeField]
|
||||
private float refreshIntervalSeconds = 0.1f;
|
||||
|
||||
private UIDocument? _document;
|
||||
private float _nextRefreshTime;
|
||||
private string _mountedStatePath = "";
|
||||
private string _mountedSurfaceId = "";
|
||||
private long _mountedSurfaceVersion = -1;
|
||||
private string _mountedSurfaceUpdatedAtUtc = "";
|
||||
private static readonly AetheriaEveUnitySurfaceChrome RootOnlyChrome = new AetheriaEveUnitySurfaceChrome
|
||||
{
|
||||
UseShell = false,
|
||||
RootPaddingTop = 0f,
|
||||
RootAlignItems = Align.Stretch,
|
||||
RootJustifyContent = Justify.FlexStart,
|
||||
RootPickingMode = PickingMode.Position
|
||||
};
|
||||
|
||||
public string SurfaceId
|
||||
{
|
||||
|
|
@ -37,6 +55,12 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
set => stateFilePathOverride = value ?? "";
|
||||
}
|
||||
|
||||
public bool RefreshInUpdate
|
||||
{
|
||||
get => refreshInUpdate;
|
||||
set => refreshInUpdate = value;
|
||||
}
|
||||
|
||||
public void Mount()
|
||||
{
|
||||
var document = ResolveDocument();
|
||||
|
|
@ -64,8 +88,7 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
return;
|
||||
}
|
||||
|
||||
var lowerer = new EveUiToolkitSurfaceLowerer();
|
||||
root.Add(lowerer.Lower(surface, request => EmitCommand(statePath, request)));
|
||||
MountSurface(statePath, surface);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
|
|
@ -74,6 +97,28 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
Mount();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!refreshInUpdate || Time.unscaledTime < _nextRefreshTime)
|
||||
return;
|
||||
|
||||
_nextRefreshTime = Time.unscaledTime + Mathf.Max(0.01f, refreshIntervalSeconds);
|
||||
RefreshIfChanged();
|
||||
}
|
||||
|
||||
private void RefreshIfChanged()
|
||||
{
|
||||
var stateBoot = ResolveStateBoot();
|
||||
if (!stateBoot.SupportsLocalStateFileRead || !stateBoot.StateFileExists)
|
||||
return;
|
||||
|
||||
var surface = AetheriaRuntimeStateReader.ReadEveSurface(stateBoot.StateFilePath, surfaceId);
|
||||
if (surface == null || !ShouldMountSurface(stateBoot.StateFilePath, surface))
|
||||
return;
|
||||
|
||||
MountSurface(stateBoot.StateFilePath, surface);
|
||||
}
|
||||
|
||||
private UIDocument ResolveDocument()
|
||||
{
|
||||
if (_document == null)
|
||||
|
|
@ -97,11 +142,52 @@ namespace GameCult.Aetheria.EveRuntime
|
|||
return container;
|
||||
}
|
||||
|
||||
private bool ShouldMountSurface(string statePath, EveSurfaceDocument surface)
|
||||
{
|
||||
return !string.Equals(_mountedStatePath, statePath, StringComparison.Ordinal) ||
|
||||
!string.Equals(_mountedSurfaceId, surface.Surface.Id, StringComparison.Ordinal) ||
|
||||
_mountedSurfaceVersion != surface.Version ||
|
||||
!string.Equals(_mountedSurfaceUpdatedAtUtc, surface.UpdatedAtUtc, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private void MountSurface(string statePath, EveSurfaceDocument surface)
|
||||
{
|
||||
AetheriaEveUnitySurfaceHost.Render(
|
||||
transform,
|
||||
ResolveDocument(),
|
||||
"Aetheria Eve Surface",
|
||||
surface,
|
||||
request => EmitCommand(statePath, request),
|
||||
RootOnlyChrome);
|
||||
_mountedStatePath = statePath;
|
||||
_mountedSurfaceId = surface.Surface.Id;
|
||||
_mountedSurfaceVersion = surface.Version;
|
||||
_mountedSurfaceUpdatedAtUtc = surface.UpdatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
private static void EmitCommand(string statePath, EveSurfaceCommandRequest request)
|
||||
{
|
||||
var envelope = AetheriaRuntimeEveCommandLog.QueueCommand(statePath, request);
|
||||
if (AetheriaRuntimeDaemonSurfaceCommands.TrySubmit(statePath, request, out var daemonEnvelope))
|
||||
{
|
||||
Debug.Log(
|
||||
$"Submitted Aetheria daemon operation from Eve surface: {daemonEnvelope!.Kind} {daemonEnvelope.CommandId}");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!AetheriaRuntimeEveCommands.TrySendKnownSurfaceCommand(
|
||||
statePath,
|
||||
request,
|
||||
string.IsNullOrWhiteSpace(request.ClientId) ? "unity-uitoolkit" : request.ClientId,
|
||||
out var envelope,
|
||||
out var error))
|
||||
{
|
||||
Debug.LogWarning(
|
||||
$"Ignored or failed Aetheria Eve command: {request.ProviderId}/{request.SurfaceId}/{request.Command}: {error}");
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log(
|
||||
$"Queued Eve command for CultMesh bridge: {envelope.ProviderId}/{envelope.SurfaceId}/{envelope.Command} {envelope.CommandId}");
|
||||
$"Submitted Eve command for CultMesh bridge: {envelope!.ProviderId}/{envelope.SurfaceId}/{envelope.Command} {envelope.CommandId}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f538568d3b6341c43adeb7e023573756
|
||||
|
|
@ -0,0 +1,187 @@
|
|||
using System;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
using GameCult.Eve.Surface;
|
||||
using GameCult.Eve.UnityUIToolkit;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace GameCult.Aetheria.EveRuntime
|
||||
{
|
||||
public sealed class AetheriaEveUnitySurfaceChrome
|
||||
{
|
||||
public float RootPaddingTop = 16f;
|
||||
public Align RootAlignItems = Align.Center;
|
||||
public Justify RootJustifyContent = Justify.FlexStart;
|
||||
public PickingMode RootPickingMode = PickingMode.Ignore;
|
||||
public float RootPaddingLeft = 0f;
|
||||
public float RootPaddingRight = 0f;
|
||||
public float RootPaddingBottom = 0f;
|
||||
public Color RootBackgroundColor = new Color(0f, 0f, 0f, 0f);
|
||||
|
||||
public float Width = 0f;
|
||||
public float MinWidth = 420f;
|
||||
public float MaxWidth = 760f;
|
||||
public float MaxHeight = 0f;
|
||||
public float FlexGrow = 0f;
|
||||
public FlexDirection FlexDirection = FlexDirection.Column;
|
||||
public float PaddingLeft = 16f;
|
||||
public float PaddingRight = 16f;
|
||||
public float PaddingTop = 12f;
|
||||
public float PaddingBottom = 12f;
|
||||
public float BorderRadius = 8f;
|
||||
public float BorderWidth = 1f;
|
||||
public Color BackgroundColor = new Color(0.08f, 0.1f, 0.14f, 0.94f);
|
||||
public Color BorderColor = new Color(0.3f, 0.47f, 0.71f, 0.8f);
|
||||
public PickingMode ShellPickingMode = PickingMode.Position;
|
||||
public bool UseShell = true;
|
||||
}
|
||||
|
||||
public static class AetheriaEveUnitySurfaceHost
|
||||
{
|
||||
public static UIDocument Render(
|
||||
Transform owner,
|
||||
UIDocument document,
|
||||
string hostName,
|
||||
EveSurfaceDocument surface,
|
||||
Action<EveSurfaceCommandRequest> commandHandler,
|
||||
AetheriaEveUnitySurfaceChrome chrome,
|
||||
int sortingOrder = 1000)
|
||||
{
|
||||
if (owner == null)
|
||||
throw new ArgumentNullException(nameof(owner));
|
||||
if (surface == null)
|
||||
throw new ArgumentNullException(nameof(surface));
|
||||
if (commandHandler == null)
|
||||
throw new ArgumentNullException(nameof(commandHandler));
|
||||
|
||||
document = ResolveDocument(owner, document, hostName, sortingOrder);
|
||||
document.gameObject.SetActive(true);
|
||||
|
||||
var root = document.rootVisualElement;
|
||||
ConfigureRoot(root, chrome);
|
||||
|
||||
var lowerer = new EveUiToolkitSurfaceLowerer();
|
||||
if (chrome.UseShell)
|
||||
{
|
||||
var shell = CreateShell(chrome);
|
||||
root.Add(shell);
|
||||
shell.Add(lowerer.Lower(surface, commandHandler));
|
||||
}
|
||||
else
|
||||
{
|
||||
root.Add(lowerer.Lower(surface, commandHandler));
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
public static UIDocument RenderRuntime(
|
||||
Transform owner,
|
||||
UIDocument document,
|
||||
string hostName,
|
||||
AetheriaRuntimeSurfaceDocument surface,
|
||||
Action<EveSurfaceCommandRequest> commandHandler,
|
||||
AetheriaEveUnitySurfaceChrome chrome,
|
||||
int sortingOrder = 1000)
|
||||
{
|
||||
if (surface == null)
|
||||
throw new ArgumentNullException(nameof(surface));
|
||||
|
||||
return Render(
|
||||
owner,
|
||||
document,
|
||||
hostName,
|
||||
AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface),
|
||||
commandHandler,
|
||||
chrome,
|
||||
sortingOrder);
|
||||
}
|
||||
|
||||
public static void Hide(UIDocument document)
|
||||
{
|
||||
if (document == null)
|
||||
return;
|
||||
|
||||
document.rootVisualElement.Clear();
|
||||
document.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public static void DestroyDocument(UIDocument document)
|
||||
{
|
||||
if (document == null)
|
||||
return;
|
||||
|
||||
UnityEngine.Object.Destroy(document.gameObject);
|
||||
}
|
||||
|
||||
private static UIDocument ResolveDocument(
|
||||
Transform owner,
|
||||
UIDocument document,
|
||||
string hostName,
|
||||
int sortingOrder)
|
||||
{
|
||||
if (document != null)
|
||||
return document;
|
||||
|
||||
var host = new GameObject(string.IsNullOrWhiteSpace(hostName) ? "Aetheria Eve Surface" : hostName);
|
||||
host.transform.SetParent(owner, false);
|
||||
host.layer = owner.gameObject.layer;
|
||||
document = host.AddComponent<UIDocument>();
|
||||
document.sortingOrder = sortingOrder;
|
||||
host.SetActive(false);
|
||||
return document;
|
||||
}
|
||||
|
||||
private static void ConfigureRoot(VisualElement root, AetheriaEveUnitySurfaceChrome chrome)
|
||||
{
|
||||
root.Clear();
|
||||
root.style.flexGrow = 1;
|
||||
root.style.position = Position.Absolute;
|
||||
root.style.left = 0;
|
||||
root.style.top = 0;
|
||||
root.style.right = 0;
|
||||
root.style.bottom = 0;
|
||||
root.style.alignItems = chrome.RootAlignItems;
|
||||
root.style.justifyContent = chrome.RootJustifyContent;
|
||||
root.style.paddingLeft = chrome.RootPaddingLeft;
|
||||
root.style.paddingTop = chrome.RootPaddingTop;
|
||||
root.style.paddingRight = chrome.RootPaddingRight;
|
||||
root.style.paddingBottom = chrome.RootPaddingBottom;
|
||||
if (chrome.RootBackgroundColor.a > 0f)
|
||||
root.style.backgroundColor = chrome.RootBackgroundColor;
|
||||
root.pickingMode = chrome.RootPickingMode;
|
||||
}
|
||||
|
||||
private static VisualElement CreateShell(AetheriaEveUnitySurfaceChrome chrome)
|
||||
{
|
||||
var shell = new VisualElement();
|
||||
shell.style.flexDirection = chrome.FlexDirection;
|
||||
shell.style.flexGrow = chrome.FlexGrow;
|
||||
if (chrome.Width > 0f)
|
||||
shell.style.width = chrome.Width;
|
||||
shell.style.minWidth = chrome.MinWidth;
|
||||
shell.style.maxWidth = chrome.MaxWidth;
|
||||
if (chrome.MaxHeight > 0f)
|
||||
shell.style.maxHeight = chrome.MaxHeight;
|
||||
shell.style.backgroundColor = chrome.BackgroundColor;
|
||||
shell.style.borderTopLeftRadius = chrome.BorderRadius;
|
||||
shell.style.borderTopRightRadius = chrome.BorderRadius;
|
||||
shell.style.borderBottomLeftRadius = chrome.BorderRadius;
|
||||
shell.style.borderBottomRightRadius = chrome.BorderRadius;
|
||||
shell.style.paddingLeft = chrome.PaddingLeft;
|
||||
shell.style.paddingRight = chrome.PaddingRight;
|
||||
shell.style.paddingTop = chrome.PaddingTop;
|
||||
shell.style.paddingBottom = chrome.PaddingBottom;
|
||||
shell.style.borderLeftWidth = chrome.BorderWidth;
|
||||
shell.style.borderRightWidth = chrome.BorderWidth;
|
||||
shell.style.borderTopWidth = chrome.BorderWidth;
|
||||
shell.style.borderBottomWidth = chrome.BorderWidth;
|
||||
shell.style.borderLeftColor = chrome.BorderColor;
|
||||
shell.style.borderRightColor = chrome.BorderColor;
|
||||
shell.style.borderTopColor = chrome.BorderColor;
|
||||
shell.style.borderBottomColor = chrome.BorderColor;
|
||||
shell.pickingMode = chrome.ShellPickingMode;
|
||||
return shell;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: eb0db70846a048e7b15232a70d9f5f8e
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 71b47dbc13067094fb870e349a6cbd14
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bb8d7a317e284914da0dfaccc300c17c
|
||||
PackageManifestImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
8
Packages/org.gamecult.aetheria.state/Runtime.meta
Normal file
8
Packages/org.gamecult.aetheria.state/Runtime.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd2e1c0bcf53796468d8246c0a4bdf72
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Aetheria.State.Unity.Smoke")]
|
||||
[assembly: InternalsVisibleTo("Tests")]
|
||||
|
|
@ -0,0 +1,278 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeCargoItemMetric
|
||||
{
|
||||
public AetheriaRuntimeCargoItemMetric(string id, string label, string value)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Value = value ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Value { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeCargoItemSection
|
||||
{
|
||||
public AetheriaRuntimeCargoItemSection(
|
||||
string id,
|
||||
string title,
|
||||
IReadOnlyList<AetheriaRuntimeCargoItemMetric> metrics)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Title = title ?? "";
|
||||
Metrics = metrics ?? Array.Empty<AetheriaRuntimeCargoItemMetric>();
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Title { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeCargoItemMetric> Metrics { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeCargoItemDetailsSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeCargoItemDetailsSurfaceState(
|
||||
string itemName,
|
||||
string description,
|
||||
string manufacturer,
|
||||
string mass,
|
||||
int price,
|
||||
int quantity,
|
||||
string tier,
|
||||
string durability,
|
||||
string thermalRange,
|
||||
IReadOnlyList<AetheriaRuntimeCargoItemSection> behaviorSections,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
ItemName = itemName ?? "";
|
||||
Description = description ?? "";
|
||||
Manufacturer = manufacturer ?? "";
|
||||
Mass = mass ?? "";
|
||||
Price = price;
|
||||
Quantity = quantity;
|
||||
Tier = tier ?? "";
|
||||
Durability = durability ?? "";
|
||||
ThermalRange = thermalRange ?? "";
|
||||
BehaviorSections = behaviorSections ?? Array.Empty<AetheriaRuntimeCargoItemSection>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string ItemName { get; }
|
||||
public string Description { get; }
|
||||
public string Manufacturer { get; }
|
||||
public string Mass { get; }
|
||||
public int Price { get; }
|
||||
public int Quantity { get; }
|
||||
public string Tier { get; }
|
||||
public string Durability { get; }
|
||||
public string ThermalRange { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeCargoItemSection> BehaviorSections { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
public bool HasQuantity => Quantity > 0;
|
||||
public bool HasEquipmentStatus => !string.IsNullOrWhiteSpace(Tier) ||
|
||||
!string.IsNullOrWhiteSpace(Durability) ||
|
||||
!string.IsNullOrWhiteSpace(ThermalRange);
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeCargoItemDetailsSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.inventory.cargo_item_details";
|
||||
public const string Close = "aetheria.inventory.cargo_item_details.close";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeCargoItemDetailsSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeCargoItemDetailsSurfaceState(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeCargoItemSection>(),
|
||||
"");
|
||||
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{SurfaceId}.summary",
|
||||
state.ItemName,
|
||||
Text(
|
||||
$"{SurfaceId}.description",
|
||||
string.IsNullOrWhiteSpace(state.Description)
|
||||
? "No typed item description is available."
|
||||
: state.Description),
|
||||
Text(
|
||||
$"{SurfaceId}.note",
|
||||
"Unity supplies the selected item; the shared runtime surface owns cargo-item inspection layout."),
|
||||
Metric($"{SurfaceId}.manufacturer", "Manufacturer", state.Manufacturer),
|
||||
Metric($"{SurfaceId}.mass", "Mass", state.Mass))
|
||||
};
|
||||
|
||||
if (state.Price > 0)
|
||||
{
|
||||
children.Add(Card(
|
||||
$"{SurfaceId}.market.card",
|
||||
"Market",
|
||||
Metric($"{SurfaceId}.price", "Price", state.Price.ToString("N0"))));
|
||||
}
|
||||
|
||||
if (state.HasQuantity)
|
||||
{
|
||||
children.Add(Card(
|
||||
$"{SurfaceId}.quantity.card",
|
||||
"Quantity",
|
||||
Metric($"{SurfaceId}.quantity", "Units", state.Quantity.ToString())));
|
||||
}
|
||||
|
||||
if (state.HasEquipmentStatus)
|
||||
{
|
||||
children.Add(Card(
|
||||
$"{SurfaceId}.status.card",
|
||||
"Status",
|
||||
Metric($"{SurfaceId}.tier", "Tier", state.Tier),
|
||||
Metric($"{SurfaceId}.durability", "Durability", state.Durability),
|
||||
Metric($"{SurfaceId}.temperature_range", "Thermal Range", state.ThermalRange)));
|
||||
}
|
||||
|
||||
foreach (var section in state.BehaviorSections)
|
||||
{
|
||||
if (section?.Metrics == null || section.Metrics.Count == 0)
|
||||
continue;
|
||||
|
||||
children.Add(Card(
|
||||
string.IsNullOrWhiteSpace(section.Id)
|
||||
? $"{SurfaceId}.behavior.{SafeId(section.Title)}"
|
||||
: section.Id,
|
||||
section.Title,
|
||||
section.Metrics
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{SurfaceId}.actions",
|
||||
Button($"{SurfaceId}.close", "Close", Close)));
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "inventory.menu",
|
||||
title: "Inventory Cargo Item Details",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit")
|
||||
});
|
||||
}
|
||||
|
||||
private static string SafeId(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
return new string(value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? char.ToLowerInvariant(character) : '-')
|
||||
.ToArray()).Trim('-');
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeCargoItemDetailsCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeCargoItemDetailsCommand
|
||||
{
|
||||
public AetheriaRuntimeCargoItemDetailsCommand(AetheriaRuntimeCargoItemDetailsCommandKind kind)
|
||||
{
|
||||
Kind = kind;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeCargoItemDetailsCommandKind Kind { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeCargoItemDetailsSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeCargoItemDetailsCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeCargoItemDetailsSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
if (string.Equals(request.Command, AetheriaRuntimeCargoItemDetailsSurfaceBuilder.Close, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeCargoItemDetailsCommand(AetheriaRuntimeCargoItemDetailsCommandKind.Close);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeCatalogCommands
|
||||
{
|
||||
public const string SurfaceId = "aetheria.catalog.operator";
|
||||
public const string Refresh = "aetheria.catalog.refresh";
|
||||
|
||||
public static bool IsKnown(string command)
|
||||
{
|
||||
return command == Refresh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -260,13 +260,15 @@ namespace GameCult.Aetheria.State.Unity
|
|||
double max,
|
||||
double heatExponentMultiplier,
|
||||
double durabilityExponentMultiplier,
|
||||
double qualityExponent)
|
||||
double qualityExponent,
|
||||
AetheriaRuntimeStatRecipe? recipe)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
HeatExponentMultiplier = heatExponentMultiplier;
|
||||
DurabilityExponentMultiplier = durabilityExponentMultiplier;
|
||||
QualityExponent = qualityExponent;
|
||||
Recipe = recipe;
|
||||
}
|
||||
|
||||
public double Min { get; }
|
||||
|
|
@ -274,6 +276,42 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public double HeatExponentMultiplier { get; }
|
||||
public double DurabilityExponentMultiplier { get; }
|
||||
public double QualityExponent { get; }
|
||||
public AetheriaRuntimeStatRecipe? Recipe { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeStatRecipe
|
||||
{
|
||||
public AetheriaRuntimeStatRecipe(double baseValue, IReadOnlyList<AetheriaRuntimeStatRecipeModifier> modifiers)
|
||||
{
|
||||
BaseValue = baseValue;
|
||||
Modifiers = modifiers ?? Array.Empty<AetheriaRuntimeStatRecipeModifier>();
|
||||
}
|
||||
|
||||
public double BaseValue { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeStatRecipeModifier> Modifiers { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeStatRecipeModifier
|
||||
{
|
||||
public AetheriaRuntimeStatRecipeModifier(
|
||||
string condition,
|
||||
string operation,
|
||||
double amount,
|
||||
IReadOnlyList<AetheriaRuntimeCurveKey> curveKeys,
|
||||
bool enabled)
|
||||
{
|
||||
Condition = condition ?? "";
|
||||
Operation = operation ?? "";
|
||||
Amount = amount;
|
||||
CurveKeys = curveKeys ?? Array.Empty<AetheriaRuntimeCurveKey>();
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
public string Condition { get; }
|
||||
public string Operation { get; }
|
||||
public double Amount { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeCurveKey> CurveKeys { get; }
|
||||
public bool Enabled { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeCurveKey
|
||||
|
|
@ -871,7 +909,8 @@ namespace GameCult.Aetheria.State.Unity
|
|||
IReadOnlyList<int> dockingBayAssignments,
|
||||
double visibility,
|
||||
int visibilitySourceCount,
|
||||
IReadOnlyList<AetheriaRuntimeEntityContactSnapshot> contacts)
|
||||
IReadOnlyList<AetheriaRuntimeEntityContactSnapshot> contacts,
|
||||
double shutdownPerformance)
|
||||
{
|
||||
RecordKey = recordKey;
|
||||
Name = name;
|
||||
|
|
@ -908,6 +947,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
Visibility = visibility;
|
||||
VisibilitySourceCount = visibilitySourceCount;
|
||||
Contacts = contacts;
|
||||
ShutdownPerformance = shutdownPerformance;
|
||||
}
|
||||
|
||||
public string RecordKey { get; }
|
||||
|
|
@ -945,6 +985,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public double Visibility { get; }
|
||||
public int VisibilitySourceCount { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEntityContactSnapshot> Contacts { get; }
|
||||
public double ShutdownPerformance { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEntityContactSnapshot
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 521f121b64367a548837968dda720594
|
||||
|
|
@ -69,9 +69,195 @@ namespace GameCult.Aetheria.State.Unity
|
|||
surfaces.Add(ReadEveSurface(record.Payload));
|
||||
}
|
||||
|
||||
surfaces.Add(ProjectStatRecipeSurface(stateFilePath));
|
||||
return surfaces;
|
||||
}
|
||||
|
||||
private static EveSurfaceDocument ProjectStatRecipeSurface(string stateFilePath)
|
||||
{
|
||||
var state = ProjectStatRecipeSurfaceState(stateFilePath);
|
||||
var document = AetheriaRuntimeStatRecipeSurfaceBuilder.Build(
|
||||
state);
|
||||
return AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(document);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeSurfaceState ProjectStatRecipeSurfaceState(string stateFilePath)
|
||||
{
|
||||
var catalog = OpenReadOnly(stateFilePath);
|
||||
var recipes = catalog.Items
|
||||
.SelectMany(ProjectStatRecipeRows)
|
||||
.OrderBy(recipe => recipe.StatName, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
var state = new AetheriaRuntimeStatRecipeSurfaceState(
|
||||
recipes,
|
||||
recipes.FirstOrDefault()?.StatName ?? "",
|
||||
AetheriaRuntimeStatRecipePreviewState.Default,
|
||||
DateTime.UtcNow.ToString("O"));
|
||||
|
||||
return state;
|
||||
}
|
||||
|
||||
private static IEnumerable<AetheriaRuntimeStatRecipeState> ProjectStatRecipeRows(AetheriaRuntimeCatalogItem item)
|
||||
{
|
||||
foreach (var behavior in item.BehaviorPayloads ?? Array.Empty<AetheriaRuntimeBehaviorPayload>())
|
||||
{
|
||||
var metadata = AetheriaRuntimeBehaviorMetadataCatalog.Get(behavior.Kind);
|
||||
foreach (var field in behavior.Fields ?? Array.Empty<AetheriaRuntimeBehaviorField>())
|
||||
{
|
||||
var fieldMetadata = metadata?.DisplayFields.FirstOrDefault(candidate => candidate.Key == field.Key);
|
||||
if (fieldMetadata?.ValueKind != AetheriaRuntimeBehaviorFieldValueKind.PerformanceStat)
|
||||
continue;
|
||||
|
||||
yield return ProjectStatRecipeRow(item, behavior, field, fieldMetadata.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeState ProjectStatRecipeRow(
|
||||
AetheriaRuntimeCatalogItem item,
|
||||
AetheriaRuntimeBehaviorPayload behavior,
|
||||
AetheriaRuntimeBehaviorField field,
|
||||
string fieldName)
|
||||
{
|
||||
var value = field.Value;
|
||||
var recipe = ReadBehaviorStatRecipe(value);
|
||||
var statName = string.Join(
|
||||
" / ",
|
||||
new[] { item.Name, behavior.Kind, fieldName }
|
||||
.Where(part => !string.IsNullOrWhiteSpace(part)));
|
||||
var recipeKey = $"{item.ItemKey}|{behavior.Kind}|{behavior.Group}|{field.Key}";
|
||||
var baseValue = recipe?.BaseValue ?? ReadBehaviorStatBaseValue(value);
|
||||
return new AetheriaRuntimeStatRecipeState(
|
||||
recipeKey,
|
||||
statName,
|
||||
baseValue,
|
||||
(recipe?.Modifiers ?? Array.Empty<AetheriaRuntimeStatRecipeModifier>())
|
||||
.Select(ProjectStatInfluence)
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static double ReadBehaviorStatBaseValue(AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count < 2)
|
||||
return 0;
|
||||
|
||||
return value.Children[1].NumberValue;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipe? ReadBehaviorStatRecipe(AetheriaRuntimeBehaviorValue? value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count <= 5)
|
||||
return null;
|
||||
|
||||
var recipeValue = value.Children[5];
|
||||
if (recipeValue?.Children == null || recipeValue.Children.Count == 0)
|
||||
return null;
|
||||
|
||||
var baseValue = recipeValue.Children[0].NumberValue;
|
||||
var modifierValues = recipeValue.Children.Count > 1
|
||||
? recipeValue.Children[1].Children ?? Array.Empty<AetheriaRuntimeBehaviorValue>()
|
||||
: Array.Empty<AetheriaRuntimeBehaviorValue>();
|
||||
var modifiers = modifierValues
|
||||
.Select(ReadBehaviorStatRecipeModifier)
|
||||
.OfType<AetheriaRuntimeStatRecipeModifier>()
|
||||
.ToArray();
|
||||
return new AetheriaRuntimeStatRecipe(baseValue, modifiers);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeModifier? ReadBehaviorStatRecipeModifier(AetheriaRuntimeBehaviorValue? value)
|
||||
{
|
||||
if (value?.Children == null)
|
||||
return null;
|
||||
|
||||
return new AetheriaRuntimeStatRecipeModifier(
|
||||
ReadChildString(value, 0),
|
||||
ReadChildString(value, 1),
|
||||
ReadChildNumber(value, 2),
|
||||
ReadBehaviorCurveKeys(ReadChildValue(value, 3)),
|
||||
value.Children.Count <= 4 || ReadChildValue(value, 4)?.BoolValue != false);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeCurveKey> ReadBehaviorCurveKeys(AetheriaRuntimeBehaviorValue? value)
|
||||
{
|
||||
if (value?.Children == null || value.Children.Count == 0)
|
||||
return Array.Empty<AetheriaRuntimeCurveKey>();
|
||||
|
||||
return value.Children
|
||||
.Where(key => key.Children != null && key.Children.Count >= 4)
|
||||
.Select(key => new AetheriaRuntimeCurveKey(
|
||||
ReadChildNumber(key, 0),
|
||||
ReadChildNumber(key, 1),
|
||||
ReadChildNumber(key, 2),
|
||||
ReadChildNumber(key, 3)))
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatInfluenceState ProjectStatInfluence(AetheriaRuntimeStatRecipeModifier modifier)
|
||||
{
|
||||
return new AetheriaRuntimeStatInfluenceState(
|
||||
modifier.Condition,
|
||||
string.IsNullOrWhiteSpace(modifier.Operation) ? AetheriaRuntimeStatRecipeOperations.Add : modifier.Operation,
|
||||
modifier.Amount,
|
||||
CurveLabel(modifier.CurveKeys),
|
||||
SampleCurve(modifier.CurveKeys, AetheriaRuntimeStatRecipePreviewState.Default.GetConditionValue(modifier.Condition)),
|
||||
modifier.Enabled);
|
||||
}
|
||||
|
||||
private static string CurveLabel(IReadOnlyList<AetheriaRuntimeCurveKey> keys)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return "linear";
|
||||
|
||||
var preset = CurvePresetLabel(keys);
|
||||
return string.IsNullOrWhiteSpace(preset) ? $"{keys.Count} keys" : preset;
|
||||
}
|
||||
|
||||
private static double SampleCurve(IReadOnlyList<AetheriaRuntimeCurveKey> keys, double value)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return Clamp01(value);
|
||||
|
||||
var ordered = keys.OrderBy(key => key.Time).ToArray();
|
||||
if (value <= ordered[0].Time)
|
||||
return Clamp01(ordered[0].Value);
|
||||
for (var index = 1; index < ordered.Length; index++)
|
||||
{
|
||||
var next = ordered[index];
|
||||
var previous = ordered[index - 1];
|
||||
if (value > next.Time)
|
||||
continue;
|
||||
|
||||
var span = next.Time - previous.Time;
|
||||
var t = span <= double.Epsilon ? 1 : Clamp01((value - previous.Time) / span);
|
||||
return Clamp01(previous.Value + ((next.Value - previous.Value) * t));
|
||||
}
|
||||
|
||||
return Clamp01(ordered[ordered.Length - 1].Value);
|
||||
}
|
||||
|
||||
private static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0)
|
||||
return 0;
|
||||
return value > 1 ? 1 : value;
|
||||
}
|
||||
|
||||
private static string ReadChildString(AetheriaRuntimeBehaviorValue? value, int index)
|
||||
{
|
||||
return ReadChildValue(value, index)?.StringValue ?? "";
|
||||
}
|
||||
|
||||
private static double ReadChildNumber(AetheriaRuntimeBehaviorValue? value, int index)
|
||||
{
|
||||
return ReadChildValue(value, index)?.NumberValue ?? 0;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue? ReadChildValue(AetheriaRuntimeBehaviorValue? value, int index)
|
||||
{
|
||||
return value?.Children != null && value.Children.Count > index ? value.Children[index] : null;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimePlayerSettingsSnapshot? ReadPlayerSettings(string stateFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stateFilePath))
|
||||
|
|
@ -263,6 +449,422 @@ namespace GameCult.Aetheria.State.Unity
|
|||
return new PersistedRecord(key, schemaId, payload);
|
||||
}
|
||||
|
||||
private static int PatchEmbeddedItemRecords(
|
||||
string stateFilePath,
|
||||
IReadOnlyDictionary<string, string> schemaCatalog,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeStatRecipeState> recipes)
|
||||
{
|
||||
var snapshotFields = ReadArrayFields(File.ReadAllBytes(stateFilePath));
|
||||
if (snapshotFields.Count <= 2)
|
||||
return 0;
|
||||
|
||||
var recordReader = new MessagePackReader(snapshotFields[2]);
|
||||
var recordCount = recordReader.ReadArrayHeader();
|
||||
var changed = 0;
|
||||
var patchedRecords = new byte[recordCount][];
|
||||
for (var index = 0; index < recordCount; index++)
|
||||
{
|
||||
var recordRaw = recordReader.ReadRaw().ToArray();
|
||||
var patched = PatchPersistedItemRecord(recordRaw, schemaCatalog, recipes);
|
||||
if (!ReferenceEquals(patched, recordRaw))
|
||||
changed++;
|
||||
patchedRecords[index] = patched;
|
||||
}
|
||||
|
||||
if (changed == 0)
|
||||
return 0;
|
||||
|
||||
snapshotFields[2] = WriteRawArray(patchedRecords);
|
||||
WriteFileAtomically(stateFilePath, WriteRawArray(snapshotFields));
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static int PatchSplitItemRecords(
|
||||
string stateFilePath,
|
||||
IReadOnlyDictionary<string, string> schemaCatalog,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeStatRecipeState> recipes)
|
||||
{
|
||||
var recordDirectory = stateFilePath + ".records";
|
||||
if (!Directory.Exists(recordDirectory))
|
||||
return 0;
|
||||
|
||||
var changed = 0;
|
||||
foreach (var recordFile in Directory.EnumerateFiles(recordDirectory, "*.msgpack").OrderBy(path => path, StringComparer.Ordinal))
|
||||
{
|
||||
var original = File.ReadAllBytes(recordFile);
|
||||
var patched = PatchPersistedItemRecord(original, schemaCatalog, recipes);
|
||||
if (ReferenceEquals(patched, original))
|
||||
continue;
|
||||
|
||||
WriteFileAtomically(recordFile, patched);
|
||||
changed++;
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static byte[] PatchPersistedItemRecord(
|
||||
byte[] recordRaw,
|
||||
IReadOnlyDictionary<string, string> schemaCatalog,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeStatRecipeState> recipes)
|
||||
{
|
||||
var record = ReadPersistedRecord(recordRaw);
|
||||
if (!schemaCatalog.TryGetValue(record.SchemaId, out var schemaName) ||
|
||||
!string.Equals(schemaName, ItemDefinitionSchema, StringComparison.Ordinal))
|
||||
{
|
||||
return recordRaw;
|
||||
}
|
||||
|
||||
var patchedPayload = PatchItemDefinitionPayload(record.Payload, recipes);
|
||||
if (ReferenceEquals(patchedPayload, record.Payload))
|
||||
return recordRaw;
|
||||
|
||||
var fields = ReadArrayFields(recordRaw);
|
||||
if (fields.Count <= 3)
|
||||
return recordRaw;
|
||||
|
||||
fields[3] = WriteBinary(patchedPayload);
|
||||
return WriteRawArray(fields);
|
||||
}
|
||||
|
||||
private static PersistedRecord ReadPersistedRecord(byte[] recordRaw)
|
||||
{
|
||||
var reader = new MessagePackReader(recordRaw);
|
||||
return ReadPersistedRecord(ref reader);
|
||||
}
|
||||
|
||||
private static byte[] PatchItemDefinitionPayload(
|
||||
byte[] payload,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeStatRecipeState> recipes)
|
||||
{
|
||||
var item = ReadItem(payload);
|
||||
if (item?.BehaviorPayloads == null ||
|
||||
item.BehaviorPayloads.Count == 0 ||
|
||||
string.IsNullOrWhiteSpace(item.ItemKey) ||
|
||||
!recipes.Keys.Any(key => key.StartsWith(item.ItemKey + "|", StringComparison.Ordinal)))
|
||||
{
|
||||
return payload;
|
||||
}
|
||||
|
||||
var itemFields = ReadArrayFields(payload);
|
||||
if (itemFields.Count <= 31)
|
||||
return payload;
|
||||
|
||||
var patchedBehaviorPayloads = WriteBehaviorPayloads(item, recipes);
|
||||
if (RawEquals(itemFields[31], patchedBehaviorPayloads))
|
||||
return payload;
|
||||
|
||||
itemFields[31] = patchedBehaviorPayloads;
|
||||
return WriteRawArray(itemFields);
|
||||
}
|
||||
|
||||
private static byte[] WriteBehaviorPayloads(
|
||||
AetheriaRuntimeCatalogItem item,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeStatRecipeState> recipes)
|
||||
{
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
var writer = new MessagePackWriter(buffer);
|
||||
var payloads = item.BehaviorPayloads ?? Array.Empty<AetheriaRuntimeBehaviorPayload>();
|
||||
writer.WriteArrayHeader(payloads.Count);
|
||||
foreach (var payload in payloads)
|
||||
WriteBehaviorPayload(ref writer, item.ItemKey, payload, recipes);
|
||||
writer.Flush();
|
||||
return buffer.WrittenSpan.ToArray();
|
||||
}
|
||||
|
||||
private static void WriteBehaviorPayload(
|
||||
ref MessagePackWriter writer,
|
||||
string itemKey,
|
||||
AetheriaRuntimeBehaviorPayload payload,
|
||||
IReadOnlyDictionary<string, AetheriaRuntimeStatRecipeState> recipes)
|
||||
{
|
||||
writer.WriteArrayHeader(4);
|
||||
writer.Write(payload.UnionKey);
|
||||
writer.Write(payload.Kind ?? "");
|
||||
writer.Write(payload.Group);
|
||||
var fields = payload.Fields ?? Array.Empty<AetheriaRuntimeBehaviorField>();
|
||||
writer.WriteArrayHeader(fields.Count);
|
||||
foreach (var field in fields)
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.Write(field.Key);
|
||||
var recipeKey = $"{itemKey}|{payload.Kind}|{payload.Group}|{field.Key}";
|
||||
WriteBehaviorValue(
|
||||
ref writer,
|
||||
recipes.TryGetValue(recipeKey, out var recipe) ? WithStatRecipe(field.Value, recipe) : field.Value);
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue WithStatRecipe(
|
||||
AetheriaRuntimeBehaviorValue value,
|
||||
AetheriaRuntimeStatRecipeState recipe)
|
||||
{
|
||||
var children = (value?.Children ?? Array.Empty<AetheriaRuntimeBehaviorValue>()).ToList();
|
||||
while (children.Count <= 5)
|
||||
children.Add(EmptyBehaviorValue());
|
||||
|
||||
children[5] = ToBehaviorValue(recipe, ReadBehaviorStatRecipe(value));
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
value?.Kind ?? "",
|
||||
value?.StringValue ?? "",
|
||||
value?.NumberValue ?? 0,
|
||||
value?.BoolValue ?? false,
|
||||
value?.LegacyIdValue ?? "",
|
||||
value?.ItemKeyValue ?? "",
|
||||
children,
|
||||
value?.MapEntries ?? Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue ToBehaviorValue(
|
||||
AetheriaRuntimeStatRecipeState recipe,
|
||||
AetheriaRuntimeStatRecipe? originalRecipe)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"statRecipe",
|
||||
"",
|
||||
0,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
new[]
|
||||
{
|
||||
NumberBehaviorValue(recipe.BaseValue),
|
||||
new AetheriaRuntimeBehaviorValue(
|
||||
"array",
|
||||
"",
|
||||
0,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
(recipe.Influences ?? Array.Empty<AetheriaRuntimeStatInfluenceState>())
|
||||
.Select(influence => ToBehaviorValue(influence, originalRecipe))
|
||||
.ToArray(),
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>())
|
||||
},
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue ToBehaviorValue(
|
||||
AetheriaRuntimeStatInfluenceState influence,
|
||||
AetheriaRuntimeStatRecipe? originalRecipe)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"statRecipeModifier",
|
||||
"",
|
||||
0,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
new[]
|
||||
{
|
||||
StringBehaviorValue(influence.Condition),
|
||||
StringBehaviorValue(influence.Operation),
|
||||
NumberBehaviorValue(influence.Amount),
|
||||
ToCurveBehaviorValue(ResolveCurveKeys(influence, originalRecipe)),
|
||||
BoolBehaviorValue(influence.Enabled)
|
||||
},
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeCurveKey>? ResolveCurveKeys(
|
||||
AetheriaRuntimeStatInfluenceState influence,
|
||||
AetheriaRuntimeStatRecipe? originalRecipe)
|
||||
{
|
||||
var originalKeys = originalRecipe?.Modifiers?.FirstOrDefault(modifier =>
|
||||
string.Equals(modifier.Condition, influence.Condition, StringComparison.Ordinal))?.CurveKeys;
|
||||
return TryCreateCurvePreset(influence.CurveLabel, out var presetKeys)
|
||||
? presetKeys
|
||||
: originalKeys;
|
||||
}
|
||||
|
||||
private static bool TryCreateCurvePreset(string label, out IReadOnlyList<AetheriaRuntimeCurveKey>? keys)
|
||||
{
|
||||
switch (NormalizeCurveLabel(label))
|
||||
{
|
||||
case "linear":
|
||||
keys = Array.Empty<AetheriaRuntimeCurveKey>();
|
||||
return true;
|
||||
case "inverse":
|
||||
keys = new[]
|
||||
{
|
||||
new AetheriaRuntimeCurveKey(0, 1, 0, -1),
|
||||
new AetheriaRuntimeCurveKey(1, 0, -1, 0)
|
||||
};
|
||||
return true;
|
||||
case "easein":
|
||||
keys = new[]
|
||||
{
|
||||
new AetheriaRuntimeCurveKey(0, 0, 0, 0),
|
||||
new AetheriaRuntimeCurveKey(1, 1, 2, 0)
|
||||
};
|
||||
return true;
|
||||
case "easeout":
|
||||
keys = new[]
|
||||
{
|
||||
new AetheriaRuntimeCurveKey(0, 0, 0, 2),
|
||||
new AetheriaRuntimeCurveKey(1, 1, 0, 0)
|
||||
};
|
||||
return true;
|
||||
case "easeinout":
|
||||
keys = new[]
|
||||
{
|
||||
new AetheriaRuntimeCurveKey(0, 0, 0, 0),
|
||||
new AetheriaRuntimeCurveKey(1, 1, 0, 0)
|
||||
};
|
||||
return true;
|
||||
case "constant":
|
||||
keys = new[]
|
||||
{
|
||||
new AetheriaRuntimeCurveKey(0, 1, 0, 0),
|
||||
new AetheriaRuntimeCurveKey(1, 1, 0, 0)
|
||||
};
|
||||
return true;
|
||||
default:
|
||||
keys = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string CurvePresetLabel(IReadOnlyList<AetheriaRuntimeCurveKey> keys)
|
||||
{
|
||||
if (keys == null || keys.Count == 0)
|
||||
return "linear";
|
||||
|
||||
return MatchesCurvePreset(keys, "inverse") ? "inverse" :
|
||||
MatchesCurvePreset(keys, "easein") ? "easeIn" :
|
||||
MatchesCurvePreset(keys, "easeout") ? "easeOut" :
|
||||
MatchesCurvePreset(keys, "easeinout") ? "easeInOut" :
|
||||
MatchesCurvePreset(keys, "constant") ? "constant" :
|
||||
"";
|
||||
}
|
||||
|
||||
private static bool MatchesCurvePreset(IReadOnlyList<AetheriaRuntimeCurveKey> keys, string preset)
|
||||
{
|
||||
if (!TryCreateCurvePreset(preset, out var presetKeys) || presetKeys == null || keys.Count != presetKeys.Count)
|
||||
return false;
|
||||
|
||||
for (var index = 0; index < keys.Count; index++)
|
||||
{
|
||||
if (!AlmostEqual(keys[index].Time, presetKeys[index].Time) ||
|
||||
!AlmostEqual(keys[index].Value, presetKeys[index].Value) ||
|
||||
!AlmostEqual(keys[index].InTangent, presetKeys[index].InTangent) ||
|
||||
!AlmostEqual(keys[index].OutTangent, presetKeys[index].OutTangent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static string NormalizeCurveLabel(string label)
|
||||
{
|
||||
return new string((label ?? "")
|
||||
.Where(char.IsLetterOrDigit)
|
||||
.Select(char.ToLowerInvariant)
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static bool AlmostEqual(double left, double right)
|
||||
{
|
||||
return Math.Abs(left - right) <= 0.00001;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue ToCurveBehaviorValue(IReadOnlyList<AetheriaRuntimeCurveKey>? keys)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"curve",
|
||||
"",
|
||||
0,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
(keys ?? Array.Empty<AetheriaRuntimeCurveKey>())
|
||||
.Select(ToCurveKeyBehaviorValue)
|
||||
.ToArray(),
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue ToCurveKeyBehaviorValue(AetheriaRuntimeCurveKey key)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"curveKey",
|
||||
"",
|
||||
0,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
new[]
|
||||
{
|
||||
NumberBehaviorValue(key.Time),
|
||||
NumberBehaviorValue(key.Value),
|
||||
NumberBehaviorValue(key.InTangent),
|
||||
NumberBehaviorValue(key.OutTangent)
|
||||
},
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static void WriteBehaviorValue(ref MessagePackWriter writer, AetheriaRuntimeBehaviorValue value)
|
||||
{
|
||||
value ??= EmptyBehaviorValue();
|
||||
writer.WriteArrayHeader(8);
|
||||
writer.Write(value.Kind ?? "");
|
||||
writer.Write(value.StringValue ?? "");
|
||||
writer.Write(value.NumberValue);
|
||||
writer.Write(value.BoolValue);
|
||||
writer.Write(value.LegacyIdValue ?? "");
|
||||
writer.WriteArrayHeader((value.Children ?? Array.Empty<AetheriaRuntimeBehaviorValue>()).Count);
|
||||
foreach (var child in value.Children ?? Array.Empty<AetheriaRuntimeBehaviorValue>())
|
||||
WriteBehaviorValue(ref writer, child);
|
||||
writer.WriteArrayHeader((value.MapEntries ?? Array.Empty<AetheriaRuntimeBehaviorMapEntry>()).Count);
|
||||
foreach (var entry in value.MapEntries ?? Array.Empty<AetheriaRuntimeBehaviorMapEntry>())
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.Write(entry.Key ?? "");
|
||||
WriteBehaviorValue(ref writer, entry.Value);
|
||||
}
|
||||
writer.Write(value.ItemKeyValue ?? "");
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue StringBehaviorValue(string value)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"string",
|
||||
value ?? "",
|
||||
0,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeBehaviorValue>(),
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue NumberBehaviorValue(double value)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"number",
|
||||
"",
|
||||
value,
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeBehaviorValue>(),
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeBehaviorValue BoolBehaviorValue(bool value)
|
||||
{
|
||||
return new AetheriaRuntimeBehaviorValue(
|
||||
"bool",
|
||||
"",
|
||||
0,
|
||||
value,
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeBehaviorValue>(),
|
||||
Array.Empty<AetheriaRuntimeBehaviorMapEntry>());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCatalogItem ReadItem(byte[] payload)
|
||||
{
|
||||
var reader = new MessagePackReader(payload);
|
||||
|
|
@ -623,7 +1225,8 @@ namespace GameCult.Aetheria.State.Unity
|
|||
var visibility = ReadFieldDouble(ref reader, fields, 27);
|
||||
var visibilitySourceCount = ReadFieldInt32(ref reader, fields, 28);
|
||||
var contacts = ReadFieldEntityContacts(ref reader, fields, 29);
|
||||
SkipRemaining(ref reader, fields, 30);
|
||||
var shutdownPerformance = ReadFieldDouble(ref reader, fields, 30);
|
||||
SkipRemaining(ref reader, fields, 31);
|
||||
return new AetheriaRuntimeEntitySnapshot(
|
||||
recordKey,
|
||||
name,
|
||||
|
|
@ -659,7 +1262,8 @@ namespace GameCult.Aetheria.State.Unity
|
|||
dockingBayAssignments,
|
||||
visibility,
|
||||
visibilitySourceCount,
|
||||
contacts);
|
||||
contacts,
|
||||
shutdownPerformance);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeEntityContactSnapshot> ReadFieldEntityContacts(ref MessagePackReader reader, int fields, int index)
|
||||
|
|
@ -1660,18 +2264,65 @@ namespace GameCult.Aetheria.State.Unity
|
|||
var heatExponentMultiplier = ReadFieldDouble(ref reader, statFields, 2);
|
||||
var durabilityExponentMultiplier = ReadFieldDouble(ref reader, statFields, 3);
|
||||
var qualityExponent = ReadFieldDouble(ref reader, statFields, 4);
|
||||
SkipRemaining(ref reader, statFields, 5);
|
||||
var recipe = ReadFieldStatRecipe(ref reader, statFields, 5);
|
||||
SkipRemaining(ref reader, statFields, 6);
|
||||
return new AetheriaRuntimePerformanceStat(
|
||||
min,
|
||||
max,
|
||||
heatExponentMultiplier,
|
||||
durabilityExponentMultiplier,
|
||||
qualityExponent);
|
||||
qualityExponent,
|
||||
recipe);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimePerformanceStat EmptyPerformanceStat()
|
||||
{
|
||||
return new AetheriaRuntimePerformanceStat(0, 0, 0, 0, 0);
|
||||
return new AetheriaRuntimePerformanceStat(0, 0, 0, 0, 0, null);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipe? ReadFieldStatRecipe(ref MessagePackReader reader, int fields, int index)
|
||||
{
|
||||
if (index >= fields)
|
||||
return null;
|
||||
|
||||
var recipeFields = reader.ReadArrayHeader();
|
||||
if (recipeFields == 0)
|
||||
return null;
|
||||
|
||||
var baseValue = ReadFieldDouble(ref reader, recipeFields, 0);
|
||||
var modifiers = ReadFieldStatRecipeModifiers(ref reader, recipeFields, 1);
|
||||
SkipRemaining(ref reader, recipeFields, 2);
|
||||
return new AetheriaRuntimeStatRecipe(baseValue, modifiers);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeStatRecipeModifier> ReadFieldStatRecipeModifiers(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
if (index >= fields)
|
||||
return Array.Empty<AetheriaRuntimeStatRecipeModifier>();
|
||||
|
||||
var count = reader.ReadArrayHeader();
|
||||
var modifiers = new AetheriaRuntimeStatRecipeModifier[count];
|
||||
for (var modifier = 0; modifier < count; modifier++)
|
||||
{
|
||||
var modifierFields = reader.ReadArrayHeader();
|
||||
var condition = ReadFieldString(ref reader, modifierFields, 0);
|
||||
var operation = ReadFieldString(ref reader, modifierFields, 1);
|
||||
var amount = ReadFieldDouble(ref reader, modifierFields, 2);
|
||||
var curveKeys = ReadFieldCurveKeys(ref reader, modifierFields, 3);
|
||||
var enabled = modifierFields <= 4 || ReadFieldBool(ref reader, modifierFields, 4, true);
|
||||
SkipRemaining(ref reader, modifierFields, 5);
|
||||
modifiers[modifier] = new AetheriaRuntimeStatRecipeModifier(
|
||||
condition,
|
||||
operation,
|
||||
amount,
|
||||
curveKeys,
|
||||
enabled);
|
||||
}
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeBehaviorField> ReadFieldBehaviorFields(ref MessagePackReader reader, int fields, int index)
|
||||
|
|
@ -1814,6 +2465,65 @@ namespace GameCult.Aetheria.State.Unity
|
|||
reader.Skip();
|
||||
}
|
||||
|
||||
private static List<byte[]> ReadArrayFields(byte[] rawArray)
|
||||
{
|
||||
var reader = new MessagePackReader(rawArray);
|
||||
var count = reader.ReadArrayHeader();
|
||||
var fields = new List<byte[]>(count);
|
||||
for (var index = 0; index < count; index++)
|
||||
fields.Add(reader.ReadRaw().ToArray());
|
||||
return fields;
|
||||
}
|
||||
|
||||
private static byte[] WriteRawArray(IReadOnlyList<byte[]> fields)
|
||||
{
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
var writer = new MessagePackWriter(buffer);
|
||||
writer.WriteArrayHeader(fields?.Count ?? 0);
|
||||
foreach (var field in fields ?? Array.Empty<byte[]>())
|
||||
writer.WriteRaw(field);
|
||||
writer.Flush();
|
||||
return buffer.WrittenSpan.ToArray();
|
||||
}
|
||||
|
||||
private static byte[] WriteBinary(byte[] payload)
|
||||
{
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
var writer = new MessagePackWriter(buffer);
|
||||
writer.Write(payload ?? Array.Empty<byte>());
|
||||
writer.Flush();
|
||||
return buffer.WrittenSpan.ToArray();
|
||||
}
|
||||
|
||||
private static bool RawEquals(byte[] left, byte[] right)
|
||||
{
|
||||
if (ReferenceEquals(left, right))
|
||||
return true;
|
||||
if (left == null || right == null || left.Length != right.Length)
|
||||
return false;
|
||||
|
||||
for (var index = 0; index < left.Length; index++)
|
||||
{
|
||||
if (left[index] != right[index])
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void WriteFileAtomically(string path, byte[] payload)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
Directory.CreateDirectory(directory);
|
||||
|
||||
var tempPath = path + ".tmp";
|
||||
File.WriteAllBytes(tempPath, payload);
|
||||
if (File.Exists(path))
|
||||
File.Delete(path);
|
||||
File.Move(tempPath, path);
|
||||
}
|
||||
|
||||
private readonly struct PersistedRecord
|
||||
{
|
||||
public PersistedRecord(string key, string schemaId, byte[] payload)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ae4a16968aa48e4a9244a3bfec4bd16
|
||||
|
|
@ -1,3 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeClientTargetCommands
|
||||
|
|
@ -28,4 +33,178 @@ namespace GameCult.Aetheria.State.Unity
|
|||
command == SyncReplica;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
public static class AetheriaRuntimeClientTargetSurfaceCommands
|
||||
{
|
||||
public static bool TryRequest(
|
||||
AetheriaClientTarget target,
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeClientTargetDocument? document)
|
||||
{
|
||||
document = null;
|
||||
if (!TryRead(request, out var operation))
|
||||
return false;
|
||||
|
||||
document = Request(target, operation);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaClientTargetOperation operation)
|
||||
{
|
||||
operation = default;
|
||||
if (request == null)
|
||||
return false;
|
||||
|
||||
var command = request.Command ?? "";
|
||||
switch (command)
|
||||
{
|
||||
case AetheriaRuntimeClientTargetCommands.Refresh:
|
||||
operation = new AetheriaClientTargetOperation(AetheriaClientTargetOperationKind.Refresh);
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.CycleTargetKind:
|
||||
operation = new AetheriaClientTargetOperation(AetheriaClientTargetOperationKind.CycleTransport);
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SetTitle:
|
||||
operation = new AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind.SetTitle,
|
||||
value: ReadPayloadValue(request, "value"));
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SetVerseId:
|
||||
operation = new AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind.SetVerseId,
|
||||
value: ReadPayloadValue(request, "value"));
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SetCultMeshAddress:
|
||||
operation = new AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind.SetCultMeshAddress,
|
||||
value: ReadPayloadValue(request, "value"));
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SetStateFilePath:
|
||||
operation = new AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind.SetStateFilePath,
|
||||
value: ReadPayloadValue(request, "value"));
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SetDiscoveryEndpoints:
|
||||
operation = new AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind.SetDiscoveryEndpoints,
|
||||
discoveryEndpoints: ParseDiscoveryEndpoints(ReadPayloadValue(request, "value")));
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.DiscoverVerses:
|
||||
operation = new AetheriaClientTargetOperation(AetheriaClientTargetOperationKind.DiscoverVerses);
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SelectDiscoveredVerse:
|
||||
operation = new AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind.SelectDiscoveredVerse,
|
||||
verseId: ReadPayloadValue(request, "verseId"),
|
||||
title: ReadPayloadValue(request, "title"),
|
||||
cultMeshAddress: ReadPayloadValue(request, "cultMeshAddress"),
|
||||
discoveryEndpoints: ParseDiscoveryEndpoints(ReadPayloadValue(request, "discoveryEndpoints")));
|
||||
return true;
|
||||
case AetheriaRuntimeClientTargetCommands.SyncReplica:
|
||||
operation = new AetheriaClientTargetOperation(AetheriaClientTargetOperationKind.SyncReplica);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeClientTargetDocument Request(
|
||||
AetheriaClientTarget target,
|
||||
AetheriaClientTargetOperation operation)
|
||||
{
|
||||
switch (operation.Kind)
|
||||
{
|
||||
case AetheriaClientTargetOperationKind.Refresh:
|
||||
return target.Refresh();
|
||||
case AetheriaClientTargetOperationKind.CycleTransport:
|
||||
return target.CycleTransport();
|
||||
case AetheriaClientTargetOperationKind.SetTitle:
|
||||
return target.RequestTitle(operation.Value);
|
||||
case AetheriaClientTargetOperationKind.SetVerseId:
|
||||
return target.RequestVerseId(operation.Value);
|
||||
case AetheriaClientTargetOperationKind.SetCultMeshAddress:
|
||||
return target.RequestCultMeshAddress(operation.Value);
|
||||
case AetheriaClientTargetOperationKind.SetStateFilePath:
|
||||
return target.RequestStateFilePath(operation.Value);
|
||||
case AetheriaClientTargetOperationKind.SetDiscoveryEndpoints:
|
||||
return target.RequestDiscoveryEndpoints(operation.DiscoveryEndpoints);
|
||||
case AetheriaClientTargetOperationKind.DiscoverVerses:
|
||||
return target.DiscoverVerses();
|
||||
case AetheriaClientTargetOperationKind.SelectDiscoveredVerse:
|
||||
return target.SelectDiscoveredVerse(
|
||||
operation.VerseId,
|
||||
operation.Title,
|
||||
operation.CultMeshAddress,
|
||||
operation.DiscoveryEndpoints);
|
||||
case AetheriaClientTargetOperationKind.SyncReplica:
|
||||
return target.SyncReplica();
|
||||
default:
|
||||
throw new ArgumentException(
|
||||
$"Unknown Aetheria client-target operation '{operation.Kind}'.",
|
||||
nameof(operation));
|
||||
}
|
||||
}
|
||||
|
||||
private static string ReadPayloadValue(EveSurfaceCommandRequest request, string key)
|
||||
{
|
||||
return request.Payload != null && request.Payload.TryGetValue(key, out var value)
|
||||
? value ?? ""
|
||||
: "";
|
||||
}
|
||||
|
||||
private static string[] ParseDiscoveryEndpoints(string value)
|
||||
{
|
||||
return (value ?? "")
|
||||
.Split(new[] { ',', ';', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
|
||||
.Select(endpoint => endpoint.Trim())
|
||||
.Where(endpoint => !string.IsNullOrWhiteSpace(endpoint))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private enum AetheriaClientTargetOperationKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Refresh = 1,
|
||||
CycleTransport = 2,
|
||||
SetTitle = 3,
|
||||
SetVerseId = 4,
|
||||
SetCultMeshAddress = 5,
|
||||
SetStateFilePath = 6,
|
||||
SetDiscoveryEndpoints = 7,
|
||||
DiscoverVerses = 8,
|
||||
SelectDiscoveredVerse = 9,
|
||||
SyncReplica = 10
|
||||
}
|
||||
|
||||
private readonly struct AetheriaClientTargetOperation
|
||||
{
|
||||
public AetheriaClientTargetOperation(
|
||||
AetheriaClientTargetOperationKind kind,
|
||||
string value = "",
|
||||
string verseId = "",
|
||||
string title = "",
|
||||
string cultMeshAddress = "",
|
||||
IReadOnlyList<string>? discoveryEndpoints = null)
|
||||
{
|
||||
Kind = kind;
|
||||
Value = value ?? "";
|
||||
VerseId = verseId ?? "";
|
||||
Title = title ?? "";
|
||||
CultMeshAddress = cultMeshAddress ?? "";
|
||||
DiscoveryEndpoints = discoveryEndpoints?.ToArray() ?? Array.Empty<string>();
|
||||
}
|
||||
|
||||
public AetheriaClientTargetOperationKind Kind { get; }
|
||||
public string Value { get; }
|
||||
public string VerseId { get; }
|
||||
public string Title { get; }
|
||||
public string CultMeshAddress { get; }
|
||||
public IReadOnlyList<string> DiscoveryEndpoints { get; }
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6bd3516801c897b40b02efef67e17fe9
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3aca91844413c7d46afaf6168a04ca8d
|
||||
|
|
@ -127,7 +127,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
? state.BootFailureMessage
|
||||
: string.Equals(state.TargetSource, "state-path-override", StringComparison.Ordinal)
|
||||
? "AETHERIA_STATE_PATH is overriding the persisted client target. Update the environment if you want boot to follow the saved target again."
|
||||
: "Client target edits persist in aetheria-client.cc. Verse discovery and selection mutate the same typed owner. Verse visibility changes queue provider-owned Eve commands for the daemon bridge. Remote Verse targets hydrate a cache-only local replica before Unity reads them.";
|
||||
: "Client target edits persist in aetheria-client.cc. Verse discovery and selection mutate the same typed owner. Verse visibility changes append provider-owned Eve requests for the daemon bridge. Remote Verse targets hydrate a cache-only local replica before Unity reads them.";
|
||||
|
||||
var discoveryChildren = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
|
|
@ -277,7 +277,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
new[] { ("title", "Ownership") },
|
||||
Text(
|
||||
"aetheria.clientTarget.host.note",
|
||||
"Client target edits are local. Visibility changes queue provider-owned Eve commands against the selected local Verse state file."))),
|
||||
"Client target edits are local. Visibility changes append provider-owned Eve requests against the selected local Verse state file."))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c51ae1e0547a6c45b454932a285a555
|
||||
|
|
@ -0,0 +1,267 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using GameCult.Caching;
|
||||
using GameCult.Caching.MessagePack;
|
||||
using GameCult.Mesh;
|
||||
using GameCult.Networking;
|
||||
using GameCult.Aetheria.State.Unity;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Aetheria.State
|
||||
{
|
||||
public sealed class AetheriaCommandPort : IDisposable
|
||||
{
|
||||
private readonly CultMeshNode _node;
|
||||
|
||||
private AetheriaCommandPort(string stateFilePath, CultMeshNode node)
|
||||
{
|
||||
StateFilePath = stateFilePath;
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public string StateFilePath { get; }
|
||||
|
||||
public static async Task<AetheriaCommandPort> OpenAsync(
|
||||
string stateFilePath,
|
||||
string runtimeId = "aetheria-command-client")
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stateFilePath))
|
||||
throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath));
|
||||
|
||||
var fullPath = Path.GetFullPath(stateFilePath);
|
||||
var registry = CreateCultCacheRegistry();
|
||||
var node = await CultMesh.CreateNodeAsync(
|
||||
fullPath,
|
||||
new CultMeshNodeOptions
|
||||
{
|
||||
StartServer = false,
|
||||
EnableDurableShardLogs = true,
|
||||
CacheOptions = new CultCacheOpenOptions
|
||||
{
|
||||
Registry = registry,
|
||||
PullOnOpen = false,
|
||||
StoreFlushOnDispose = true,
|
||||
UseDirectoryStore = true
|
||||
},
|
||||
DatabaseOptions = new CultNetDatabaseOptions
|
||||
{
|
||||
RuntimeId = string.IsNullOrWhiteSpace(runtimeId) ? "aetheria-command-client" : runtimeId,
|
||||
DocumentRegistry = CreateCultNetRegistry(registry)
|
||||
}
|
||||
})
|
||||
.ConfigureAwait(false);
|
||||
|
||||
return new AetheriaCommandPort(fullPath, node);
|
||||
}
|
||||
|
||||
public async Task<AetheriaRuntimeDaemonCommandEnvelope> SubmitDaemonCommandAsync(
|
||||
AetheriaRuntimeDaemonCommandDocument command)
|
||||
{
|
||||
if (command == null) throw new ArgumentNullException(nameof(command));
|
||||
|
||||
command.Schema = AetheriaRuntimeDaemonSchemas.Command;
|
||||
if (string.IsNullOrWhiteSpace(command.CommandId))
|
||||
command.CommandId = Guid.NewGuid().ToString("N");
|
||||
if (string.IsNullOrWhiteSpace(command.IssuedAtUtc))
|
||||
command.IssuedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
|
||||
await _node.Database.PutAsync(DaemonCommandKey(command.CommandId), command).ConfigureAwait(false);
|
||||
await _node.FlushAsync().ConfigureAwait(false);
|
||||
return AetheriaRuntimeDaemonOperationClient.ToEnvelope(command);
|
||||
}
|
||||
|
||||
public async Task<AetheriaRuntimeEveCommandEnvelope> SubmitEveCommandAsync(
|
||||
AetheriaRuntimeEveCommandDocument command)
|
||||
{
|
||||
if (command == null) throw new ArgumentNullException(nameof(command));
|
||||
|
||||
command.Schema = AetheriaRuntimeEveCommandDocument.SchemaId;
|
||||
if (string.IsNullOrWhiteSpace(command.CommandId))
|
||||
command.CommandId = Guid.NewGuid().ToString("N");
|
||||
if (string.IsNullOrWhiteSpace(command.IssuedAtUtc))
|
||||
command.IssuedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
|
||||
await _node.Database.PutAsync(EveCommandKey(command.CommandId), command).ConfigureAwait(false);
|
||||
await _node.FlushAsync().ConfigureAwait(false);
|
||||
return AetheriaRuntimeEveCommandClient.ToEnvelope(command);
|
||||
}
|
||||
|
||||
private static CultDocumentRegistry CreateCultCacheRegistry()
|
||||
{
|
||||
var registry = new CultDocumentRegistry();
|
||||
registry.GetRequired(typeof(AetheriaRuntimeDaemonCommandDocument));
|
||||
registry.GetRequired(typeof(AetheriaRuntimeEveCommandDocument));
|
||||
return registry;
|
||||
}
|
||||
|
||||
private static CultNetDocumentRegistry CreateCultNetRegistry(CultDocumentRegistry registry)
|
||||
{
|
||||
return new CultNetDocumentRegistry(
|
||||
registry,
|
||||
new[]
|
||||
{
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeDaemonCommandDocument>(registry),
|
||||
CultNetDocumentBinding.ForDocument<AetheriaRuntimeEveCommandDocument>(registry)
|
||||
});
|
||||
}
|
||||
|
||||
private static CultRecordKey DaemonCommandKey(string commandId)
|
||||
{
|
||||
return new CultRecordKey($"daemon:commands:{StableToken(commandId)}:gamecult.aetheria.daemon_command.v1");
|
||||
}
|
||||
|
||||
private static CultRecordKey EveCommandKey(string commandId)
|
||||
{
|
||||
return new CultRecordKey($"eve:commands:{StableToken(commandId)}:gamecult.eve.command.v1");
|
||||
}
|
||||
|
||||
private static string StableToken(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
var chars = value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? character : '-')
|
||||
.ToArray();
|
||||
var token = new string(chars).Trim('-').ToLowerInvariant();
|
||||
while (token.Contains("--", StringComparison.Ordinal))
|
||||
token = token.Replace("--", "-", StringComparison.Ordinal);
|
||||
return string.IsNullOrWhiteSpace(token) ? "empty" : token;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_node.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeCommandPort : IDisposable
|
||||
{
|
||||
private readonly global::Aetheria.State.AetheriaCommandPort _port;
|
||||
|
||||
private AetheriaRuntimeCommandPort(global::Aetheria.State.AetheriaCommandPort port)
|
||||
{
|
||||
_port = port ?? throw new ArgumentNullException(nameof(port));
|
||||
}
|
||||
|
||||
public string StateFilePath => _port.StateFilePath;
|
||||
|
||||
public static async Task<AetheriaRuntimeCommandPort> OpenAsync(
|
||||
string stateFilePath,
|
||||
string runtimeId = "unity-input-provider")
|
||||
{
|
||||
var port = await global::Aetheria.State.AetheriaCommandPort.OpenAsync(
|
||||
stateFilePath,
|
||||
string.IsNullOrWhiteSpace(runtimeId) ? "unity-input-provider" : runtimeId)
|
||||
.ConfigureAwait(false);
|
||||
return new AetheriaRuntimeCommandPort(port);
|
||||
}
|
||||
|
||||
public Task<AetheriaRuntimeDaemonCommandEnvelope> SubmitDaemonCommandAsync(
|
||||
AetheriaRuntimeDaemonCommandDocument command)
|
||||
{
|
||||
return _port.SubmitDaemonCommandAsync(command);
|
||||
}
|
||||
|
||||
public Task<AetheriaRuntimeEveCommandEnvelope> SubmitEveCommandAsync(
|
||||
AetheriaRuntimeEveCommandDocument command)
|
||||
{
|
||||
return _port.SubmitEveCommandAsync(command);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_port.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeCommandSubmitter
|
||||
{
|
||||
private static readonly object Sync = new object();
|
||||
private static readonly Dictionary<string, AetheriaRuntimeCommandPort> Ports =
|
||||
new Dictionary<string, AetheriaRuntimeCommandPort>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public static bool TrySubmitDaemonCommand(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeDaemonCommandDocument command,
|
||||
string runtimeId,
|
||||
out AetheriaRuntimeDaemonCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
envelope = null;
|
||||
error = "";
|
||||
|
||||
try
|
||||
{
|
||||
envelope = GetOrOpen(stateFilePath, runtimeId)
|
||||
.SubmitDaemonCommandAsync(command)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TrySubmitEveCommand(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeEveCommandDocument command,
|
||||
string runtimeId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
envelope = null;
|
||||
error = "";
|
||||
|
||||
try
|
||||
{
|
||||
envelope = GetOrOpen(stateFilePath, runtimeId)
|
||||
.SubmitEveCommandAsync(command)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
error = ex.ToString();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCommandPort GetOrOpen(string stateFilePath, string runtimeId)
|
||||
{
|
||||
var fullPath = Path.GetFullPath(stateFilePath ?? "");
|
||||
var key = $"{fullPath}|{(string.IsNullOrWhiteSpace(runtimeId) ? "unity-input-provider" : runtimeId)}";
|
||||
lock (Sync)
|
||||
{
|
||||
if (Ports.TryGetValue(key, out var existing))
|
||||
return existing;
|
||||
}
|
||||
|
||||
var created = AetheriaRuntimeCommandPort.OpenAsync(fullPath, runtimeId)
|
||||
.GetAwaiter()
|
||||
.GetResult();
|
||||
lock (Sync)
|
||||
{
|
||||
if (Ports.TryGetValue(key, out var existing))
|
||||
{
|
||||
created.Dispose();
|
||||
return existing;
|
||||
}
|
||||
|
||||
Ports.Add(key, created);
|
||||
return created;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0f4cc57dd7d14eddb7e3c3a4bde1a94e
|
||||
|
|
@ -0,0 +1,661 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
internal static class AetheriaRuntimeCultCacheDocumentStore
|
||||
{
|
||||
private const string FormatVersion = "cultcache.store.v1";
|
||||
private const int StoreSnapshotFieldCount = 3;
|
||||
private const int SchemaCatalogEntryFieldCount = 7;
|
||||
private const int SchemaCatalogMemberFieldCount = 8;
|
||||
private const int PersistedRecordFieldCount = 4;
|
||||
|
||||
public static void WriteEveCommand(string path, AetheriaRuntimeEveCommandDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"command:gamecult.eve.command.{document.CommandId}.v1",
|
||||
AetheriaRuntimeEveCommandDocument.SchemaId,
|
||||
"gamecult.eve.command",
|
||||
"gamecult.eve.command.v1",
|
||||
document.IssuedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandDocument ReadEveCommand(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeEveCommandDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeEveCommandDocument.SchemaId));
|
||||
}
|
||||
|
||||
public static void WriteDaemonCommand(string path, AetheriaRuntimeDaemonCommandDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"command:gamecult.aetheria.daemon_command.{document.CommandId}.v1",
|
||||
AetheriaRuntimeDaemonSchemas.Command,
|
||||
"gamecult.aetheria.daemon_command",
|
||||
"gamecult.aetheria.daemon_command.v1",
|
||||
document.IssuedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonCommandDocument ReadDaemonCommand(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeDaemonCommandDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.Command));
|
||||
}
|
||||
|
||||
public static void WriteDaemonFrame(string path, AetheriaRuntimeDaemonFrameDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"latest:gamecult.aetheria.daemon_frame.{document.SessionId}.v1",
|
||||
AetheriaRuntimeDaemonSchemas.Frame,
|
||||
"gamecult.aetheria.daemon_frame",
|
||||
"gamecult.aetheria.daemon_frame.v1",
|
||||
document.PublishedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonFrameDocument ReadDaemonFrame(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeDaemonFrameDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.Frame));
|
||||
}
|
||||
|
||||
public static void WriteDaemonSoaView(string path, AetheriaRuntimeDaemonSoaViewDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"latest:gamecult.aetheria.daemon_soa_view.{document.SessionId}.v1",
|
||||
AetheriaRuntimeDaemonSchemas.SoaView,
|
||||
"gamecult.aetheria.daemon_soa_view",
|
||||
"gamecult.aetheria.daemon_soa_view.v1",
|
||||
document.PublishedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonSoaViewDocument ReadDaemonSoaView(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeDaemonSoaViewDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.SoaView));
|
||||
}
|
||||
|
||||
public static void WriteDaemonProviderAdvertisement(
|
||||
string path,
|
||||
AetheriaRuntimeDaemonProviderAdvertisementDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"latest:gamecult.aetheria.daemon_provider.{document.DaemonId}.v1",
|
||||
AetheriaRuntimeDaemonSchemas.ProviderAdvertisement,
|
||||
"gamecult.aetheria.daemon_provider_advertisement",
|
||||
"gamecult.aetheria.daemon_provider_advertisement.v1",
|
||||
document.PublishedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonProviderAdvertisementDocument ReadDaemonProviderAdvertisement(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeDaemonProviderAdvertisementDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.ProviderAdvertisement));
|
||||
}
|
||||
|
||||
public static void WriteDaemonHealth(string path, AetheriaRuntimeDaemonHealthDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"latest:gamecult.aetheria.daemon_health.{document.DaemonId}.v1",
|
||||
AetheriaRuntimeDaemonSchemas.Health,
|
||||
"gamecult.aetheria.daemon_health",
|
||||
"gamecult.aetheria.daemon_health.v1",
|
||||
document.PublishedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonHealthDocument ReadDaemonHealth(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeDaemonHealthDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.Health));
|
||||
}
|
||||
|
||||
public static void WriteDaemonCommandBoundary(
|
||||
string path,
|
||||
AetheriaRuntimeDaemonCommandBoundaryDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"latest:gamecult.aetheria.daemon_command_boundary.{document.BoundaryId}.v1",
|
||||
AetheriaRuntimeDaemonSchemas.CommandBoundary,
|
||||
"gamecult.aetheria.daemon_command_boundary",
|
||||
"gamecult.aetheria.daemon_command_boundary.v1",
|
||||
document.PublishedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonCommandBoundaryDocument ReadDaemonCommandBoundary(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeDaemonCommandBoundaryDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.CommandBoundary));
|
||||
}
|
||||
|
||||
public static void WriteDaemonGameSurface(string path, AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
WriteDaemonSurface(
|
||||
path,
|
||||
document,
|
||||
AetheriaRuntimeDaemonSchemas.GameSurface,
|
||||
"gamecult.aetheria.daemon_game_surface",
|
||||
"gamecult.aetheria.daemon_game_surface.v1");
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument ReadDaemonGameSurface(string path)
|
||||
{
|
||||
return ReadRuntimeSurfaceDocument(ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.GameSurface));
|
||||
}
|
||||
|
||||
public static void WriteDaemonEditorSurface(string path, AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
WriteDaemonSurface(
|
||||
path,
|
||||
document,
|
||||
AetheriaRuntimeDaemonSchemas.EditorSurface,
|
||||
"gamecult.aetheria.daemon_editor_surface",
|
||||
"gamecult.aetheria.daemon_editor_surface.v1");
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument ReadDaemonEditorSurface(string path)
|
||||
{
|
||||
return ReadRuntimeSurfaceDocument(ReadDocumentPayload(path, AetheriaRuntimeDaemonSchemas.EditorSurface));
|
||||
}
|
||||
|
||||
private static void WriteDaemonSurface(
|
||||
string path,
|
||||
AetheriaRuntimeSurfaceDocument document,
|
||||
string schema,
|
||||
string schemaName,
|
||||
string schemaVersion)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"latest:{schemaName}.{document.Surface.Id}.v1",
|
||||
schema,
|
||||
schemaName,
|
||||
schemaVersion,
|
||||
document.UpdatedAtUtc,
|
||||
WriteRuntimeSurfaceDocument(document));
|
||||
}
|
||||
|
||||
private static void WriteDocument(
|
||||
string path,
|
||||
string key,
|
||||
string schemaId,
|
||||
string schemaName,
|
||||
string schemaVersion,
|
||||
string storedAt,
|
||||
byte[] payload)
|
||||
{
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
var writer = new MessagePackWriter(buffer);
|
||||
|
||||
writer.WriteArrayHeader(StoreSnapshotFieldCount);
|
||||
writer.Write(FormatVersion);
|
||||
writer.WriteArrayHeader(1);
|
||||
WriteSchemaCatalogEntry(ref writer, schemaId, schemaName, schemaVersion, payload);
|
||||
writer.WriteArrayHeader(1);
|
||||
WritePersistedRecord(ref writer, key, schemaId, storedAt, payload);
|
||||
writer.Flush();
|
||||
|
||||
WriteFileAtomically(path, buffer.WrittenSpan.ToArray());
|
||||
}
|
||||
|
||||
private static byte[] ReadDocumentPayload(string path, string expectedSchemaId)
|
||||
{
|
||||
var reader = new MessagePackReader(File.ReadAllBytes(path));
|
||||
var fieldCount = reader.ReadArrayHeader();
|
||||
if (fieldCount < StoreSnapshotFieldCount)
|
||||
{
|
||||
throw new InvalidDataException($"CultCache document '{path}' is missing store fields.");
|
||||
}
|
||||
|
||||
var formatVersion = reader.ReadString() ?? "";
|
||||
if (!formatVersion.StartsWith("cultcache.store.v1", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidDataException($"Document '{path}' is not a CultCache store.");
|
||||
}
|
||||
|
||||
var schemaIds = ReadSchemaCatalog(ref reader);
|
||||
var recordCount = reader.ReadArrayHeader();
|
||||
if (recordCount != 1)
|
||||
{
|
||||
throw new InvalidDataException($"CultCache document '{path}' must contain exactly one record.");
|
||||
}
|
||||
|
||||
var recordFieldCount = reader.ReadArrayHeader();
|
||||
if (recordFieldCount < PersistedRecordFieldCount)
|
||||
{
|
||||
throw new InvalidDataException($"CultCache record '{path}' is missing record fields.");
|
||||
}
|
||||
|
||||
reader.Skip(); // key
|
||||
var schemaId = reader.ReadString() ?? "";
|
||||
reader.Skip(); // storedAt
|
||||
var payload = reader.ReadBytes()?.ToArray() ?? Array.Empty<byte>();
|
||||
for (var index = PersistedRecordFieldCount; index < recordFieldCount; index++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
for (var index = StoreSnapshotFieldCount; index < fieldCount; index++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
if (!string.Equals(schemaId, expectedSchemaId, StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidDataException($"Document '{path}' has schema '{schemaId}', expected '{expectedSchemaId}'.");
|
||||
}
|
||||
|
||||
if (!schemaIds.Contains(schemaId, StringComparer.Ordinal))
|
||||
{
|
||||
throw new InvalidDataException($"Document '{path}' does not publish schema '{schemaId}' in its CultCache catalog.");
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
private static string[] ReadSchemaCatalog(ref MessagePackReader reader)
|
||||
{
|
||||
var count = reader.ReadArrayHeader();
|
||||
var schemaIds = new string[count];
|
||||
for (var index = 0; index < count; index++)
|
||||
{
|
||||
var fieldCount = reader.ReadArrayHeader();
|
||||
schemaIds[index] = fieldCount > 0 ? reader.ReadString() ?? "" : "";
|
||||
for (var field = 1; field < fieldCount; field++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
return schemaIds;
|
||||
}
|
||||
|
||||
private static byte[] WriteRuntimeSurfaceDocument(AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
var writer = new MessagePackWriter(buffer);
|
||||
|
||||
writer.WriteArrayHeader(7);
|
||||
writer.Write(document.ProviderId ?? "");
|
||||
writer.Write(document.ProviderKind ?? "");
|
||||
writer.Write(document.Title ?? "");
|
||||
writer.Write(document.Version);
|
||||
writer.Write(document.UpdatedAtUtc ?? "");
|
||||
WriteSurfaceTree(ref writer, document.Surface);
|
||||
WriteSurfaceCommands(ref writer, document.Commands);
|
||||
writer.Flush();
|
||||
|
||||
return buffer.WrittenSpan.ToArray();
|
||||
}
|
||||
|
||||
private static void WriteSurfaceTree(ref MessagePackWriter writer, AetheriaRuntimeSurfaceTree tree)
|
||||
{
|
||||
tree ??= new AetheriaRuntimeSurfaceTree(
|
||||
"",
|
||||
new AetheriaRuntimeSurfaceComponent(
|
||||
"",
|
||||
"surface",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>());
|
||||
|
||||
writer.WriteArrayHeader(3);
|
||||
writer.Write(tree.Id ?? "");
|
||||
WriteSurfaceComponent(ref writer, tree.Root);
|
||||
writer.WriteArrayHeader(tree.Styles?.Count ?? 0);
|
||||
foreach (var style in tree.Styles ?? Array.Empty<AetheriaRuntimeSurfaceStyleToken>())
|
||||
{
|
||||
writer.WriteArrayHeader(2);
|
||||
writer.Write(style.Name ?? "");
|
||||
writer.Write(style.Value ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteSurfaceComponent(ref MessagePackWriter writer, AetheriaRuntimeSurfaceComponent component)
|
||||
{
|
||||
component ??= new AetheriaRuntimeSurfaceComponent(
|
||||
"",
|
||||
"",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
|
||||
writer.WriteArrayHeader(4);
|
||||
writer.Write(component.Id ?? "");
|
||||
writer.Write(component.Kind ?? "");
|
||||
writer.WriteMapHeader(component.Props?.Count ?? 0);
|
||||
foreach (var prop in component.Props ?? new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal))
|
||||
{
|
||||
writer.Write(prop.Key ?? "");
|
||||
writer.Write(prop.Value ?? "");
|
||||
}
|
||||
|
||||
writer.WriteArrayHeader(component.Children?.Count ?? 0);
|
||||
foreach (var child in component.Children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>())
|
||||
{
|
||||
WriteSurfaceComponent(ref writer, child);
|
||||
}
|
||||
}
|
||||
|
||||
private static void WriteSurfaceCommands(
|
||||
ref MessagePackWriter writer,
|
||||
System.Collections.Generic.IReadOnlyList<AetheriaRuntimeSurfaceCommandTemplate> commands)
|
||||
{
|
||||
writer.WriteArrayHeader(commands?.Count ?? 0);
|
||||
foreach (var command in commands ?? Array.Empty<AetheriaRuntimeSurfaceCommandTemplate>())
|
||||
{
|
||||
writer.WriteArrayHeader(3);
|
||||
writer.Write(command.Command ?? "");
|
||||
writer.Write(command.Label ?? "");
|
||||
writer.Write(command.Transport ?? "");
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceDocument ReadRuntimeSurfaceDocument(byte[] payload)
|
||||
{
|
||||
var reader = new MessagePackReader(payload);
|
||||
var fields = reader.ReadArrayHeader();
|
||||
var providerId = ReadFieldString(ref reader, fields, 0, "");
|
||||
var providerKind = ReadFieldString(ref reader, fields, 1, "");
|
||||
var title = ReadFieldString(ref reader, fields, 2, "");
|
||||
var version = ReadFieldInt64(ref reader, fields, 3, 0);
|
||||
var updatedAtUtc = ReadFieldString(ref reader, fields, 4, "");
|
||||
var surface = ReadFieldSurfaceTree(ref reader, fields, 5);
|
||||
var commands = ReadFieldSurfaceCommands(ref reader, fields, 6);
|
||||
for (var index = 7; index < fields; index++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId,
|
||||
providerKind,
|
||||
title,
|
||||
version,
|
||||
updatedAtUtc,
|
||||
surface,
|
||||
commands);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceTree ReadFieldSurfaceTree(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
if (index >= fields || reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
if (index < fields)
|
||||
reader.ReadNil();
|
||||
|
||||
return new AetheriaRuntimeSurfaceTree(
|
||||
"",
|
||||
new AetheriaRuntimeSurfaceComponent(
|
||||
"",
|
||||
"surface",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>());
|
||||
}
|
||||
|
||||
var treeFields = reader.ReadArrayHeader();
|
||||
var id = ReadFieldString(ref reader, treeFields, 0, "");
|
||||
var root = ReadFieldSurfaceComponent(ref reader, treeFields, 1);
|
||||
var styles = ReadFieldSurfaceStyles(ref reader, treeFields, 2);
|
||||
for (var field = 3; field < treeFields; field++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeSurfaceTree(id, root, styles);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ReadFieldSurfaceComponent(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
if (index >= fields || reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
if (index < fields)
|
||||
reader.ReadNil();
|
||||
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
"",
|
||||
"",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
|
||||
var componentFields = reader.ReadArrayHeader();
|
||||
var id = ReadFieldString(ref reader, componentFields, 0, "");
|
||||
var kind = ReadFieldString(ref reader, componentFields, 1, "");
|
||||
var props = ReadFieldStringMap(ref reader, componentFields, 2);
|
||||
var children = ReadFieldSurfaceComponents(ref reader, componentFields, 3);
|
||||
for (var field = 4; field < componentFields; field++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeSurfaceComponent(id, kind, props, children);
|
||||
}
|
||||
|
||||
private static System.Collections.Generic.IReadOnlyList<AetheriaRuntimeSurfaceComponent> ReadFieldSurfaceComponents(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
if (index >= fields || reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
if (index < fields)
|
||||
reader.ReadNil();
|
||||
|
||||
return Array.Empty<AetheriaRuntimeSurfaceComponent>();
|
||||
}
|
||||
|
||||
var count = reader.ReadArrayHeader();
|
||||
var children = new AetheriaRuntimeSurfaceComponent[count];
|
||||
for (var child = 0; child < count; child++)
|
||||
{
|
||||
children[child] = ReadFieldSurfaceComponent(ref reader, 1, 0);
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
|
||||
private static System.Collections.Generic.IReadOnlyDictionary<string, string> ReadFieldStringMap(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
var values = new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal);
|
||||
if (index >= fields || reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
if (index < fields)
|
||||
reader.ReadNil();
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
var count = reader.ReadMapHeader();
|
||||
for (var item = 0; item < count; item++)
|
||||
{
|
||||
values[reader.ReadString() ?? ""] = reader.ReadString() ?? "";
|
||||
}
|
||||
|
||||
return values;
|
||||
}
|
||||
|
||||
private static System.Collections.Generic.IReadOnlyList<AetheriaRuntimeSurfaceStyleToken> ReadFieldSurfaceStyles(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
if (index >= fields || reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
if (index < fields)
|
||||
reader.ReadNil();
|
||||
|
||||
return Array.Empty<AetheriaRuntimeSurfaceStyleToken>();
|
||||
}
|
||||
|
||||
var count = reader.ReadArrayHeader();
|
||||
var styles = new AetheriaRuntimeSurfaceStyleToken[count];
|
||||
for (var style = 0; style < count; style++)
|
||||
{
|
||||
var styleFields = reader.ReadArrayHeader();
|
||||
var name = ReadFieldString(ref reader, styleFields, 0, "");
|
||||
var value = ReadFieldString(ref reader, styleFields, 1, "");
|
||||
for (var field = 2; field < styleFields; field++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
styles[style] = new AetheriaRuntimeSurfaceStyleToken(name, value);
|
||||
}
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
private static System.Collections.Generic.IReadOnlyList<AetheriaRuntimeSurfaceCommandTemplate> ReadFieldSurfaceCommands(
|
||||
ref MessagePackReader reader,
|
||||
int fields,
|
||||
int index)
|
||||
{
|
||||
if (index >= fields || reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
if (index < fields)
|
||||
reader.ReadNil();
|
||||
|
||||
return Array.Empty<AetheriaRuntimeSurfaceCommandTemplate>();
|
||||
}
|
||||
|
||||
var count = reader.ReadArrayHeader();
|
||||
var commands = new AetheriaRuntimeSurfaceCommandTemplate[count];
|
||||
for (var command = 0; command < count; command++)
|
||||
{
|
||||
var commandFields = reader.ReadArrayHeader();
|
||||
var name = ReadFieldString(ref reader, commandFields, 0, "");
|
||||
var label = ReadFieldString(ref reader, commandFields, 1, "");
|
||||
var transport = ReadFieldString(ref reader, commandFields, 2, "");
|
||||
for (var field = 3; field < commandFields; field++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
commands[command] = new AetheriaRuntimeSurfaceCommandTemplate(name, label, transport);
|
||||
}
|
||||
|
||||
return commands;
|
||||
}
|
||||
|
||||
private static void WriteSchemaCatalogEntry(
|
||||
ref MessagePackWriter writer,
|
||||
string schemaId,
|
||||
string schemaName,
|
||||
string schemaVersion,
|
||||
byte[] payload)
|
||||
{
|
||||
writer.WriteArrayHeader(SchemaCatalogEntryFieldCount);
|
||||
writer.Write(schemaId);
|
||||
writer.Write(schemaName);
|
||||
writer.Write(schemaVersion);
|
||||
writer.Write(ContentHash(payload));
|
||||
writer.Write("");
|
||||
writer.WriteArrayHeader(0);
|
||||
writer.WriteArrayHeader(0);
|
||||
}
|
||||
|
||||
private static void WritePersistedRecord(
|
||||
ref MessagePackWriter writer,
|
||||
string key,
|
||||
string schemaId,
|
||||
string storedAt,
|
||||
byte[] payload)
|
||||
{
|
||||
writer.WriteArrayHeader(PersistedRecordFieldCount);
|
||||
writer.Write(key);
|
||||
writer.Write(schemaId);
|
||||
writer.Write(storedAt ?? "");
|
||||
writer.Write(payload);
|
||||
}
|
||||
|
||||
private static string ReadFieldString(ref MessagePackReader reader, int fields, int index, string fallback)
|
||||
{
|
||||
return index >= fields ? fallback : reader.ReadString() ?? fallback;
|
||||
}
|
||||
|
||||
private static int ReadFieldInt32(ref MessagePackReader reader, int fields, int index, int fallback)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return reader.ReadInt32();
|
||||
}
|
||||
|
||||
private static long ReadFieldInt64(ref MessagePackReader reader, int fields, int index, long fallback)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return reader.ReadInt64();
|
||||
}
|
||||
|
||||
private static string ContentHash(byte[] payload)
|
||||
{
|
||||
using var sha256 = SHA256.Create();
|
||||
return BitConverter.ToString(sha256.ComputeHash(payload)).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static void WriteFileAtomically(string path, byte[] payload)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var tempPath = path + ".tmp";
|
||||
File.WriteAllBytes(tempPath, payload);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
File.Move(tempPath, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 730416bfa990947479bc2eb704361bd8
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09d3397c0783416489eb3c74c6e958c7
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 09ab260807a4ebb41b0f4e28be870b2d
|
||||
|
|
@ -227,14 +227,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public long FrameId { get; set; }
|
||||
|
||||
[Key(6)]
|
||||
public int PendingBeforeApply { get; set; }
|
||||
|
||||
[IgnoreMember]
|
||||
public int ObservedCommandCount
|
||||
{
|
||||
get => PendingBeforeApply;
|
||||
set => PendingBeforeApply = value;
|
||||
}
|
||||
public int ObservedCommandCount { get; set; }
|
||||
|
||||
[Key(7)]
|
||||
public int AppliedCommandCount { get; set; }
|
||||
|
|
@ -388,6 +381,9 @@ namespace GameCult.Aetheria.State.Unity
|
|||
[Key(12)]
|
||||
public IReadOnlyList<string> RejectedCommandIds { get; set; } = Array.Empty<string>();
|
||||
|
||||
[Key(13)]
|
||||
public IReadOnlyList<string> AccountedCommandIds { get; set; } = Array.Empty<string>();
|
||||
|
||||
public static AetheriaRuntimeDaemonFrameDocument Create(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
string daemonId,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 89b7a1cbc494a264ba4130e65485ee5b
|
||||
|
|
@ -0,0 +1,153 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonEditorSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.daemon.editor";
|
||||
public const string TuiSurfaceId = "aetheria.daemon.editor.tui";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeDaemonProviderAdvertisementDocument provider,
|
||||
AetheriaRuntimeDaemonHealthDocument health,
|
||||
AetheriaRuntimeDaemonCommandBoundaryDocument commandBoundary)
|
||||
{
|
||||
provider ??= new AetheriaRuntimeDaemonProviderAdvertisementDocument();
|
||||
health ??= new AetheriaRuntimeDaemonHealthDocument();
|
||||
commandBoundary ??= AetheriaRuntimeDaemonCommandBoundaryDocument.Create(provider.DaemonId);
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria.daemon",
|
||||
providerKind: "editor.daemon",
|
||||
title: "Aetheria Daemon Editor",
|
||||
version: health.FrameId,
|
||||
updatedAtUtc: string.IsNullOrWhiteSpace(health.PublishedAtUtc)
|
||||
? provider.PublishedAtUtc
|
||||
: health.PublishedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
"aetheria.daemon.editor.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Node(
|
||||
"aetheria.daemon.editor.provider",
|
||||
"card",
|
||||
new[] { ("title", "Verse Provider") },
|
||||
Metric("aetheria.daemon.editor.provider.verse", "Verse", provider.VerseId),
|
||||
Metric("aetheria.daemon.editor.provider.provider", "Provider", provider.ProviderId),
|
||||
Metric("aetheria.daemon.editor.provider.daemon", "Daemon", provider.DaemonId),
|
||||
Metric("aetheria.daemon.editor.provider.transport", "CultMesh", provider.CultMeshAddress),
|
||||
Metric("aetheria.daemon.editor.provider.state", "State Witness", provider.StateWitnessPath)),
|
||||
Node(
|
||||
"aetheria.daemon.editor.witnesses",
|
||||
"card",
|
||||
new[] { ("title", "Witnesses") },
|
||||
Metric("aetheria.daemon.editor.witnesses.frame", "Frame", provider.FrameWitnessPath),
|
||||
Metric("aetheria.daemon.editor.witnesses.soa", "SoA", provider.SoaWitnessPath),
|
||||
Metric("aetheria.daemon.editor.witnesses.health", "Health", provider.HealthWitnessPath),
|
||||
Metric("aetheria.daemon.editor.witnesses.commands", "Command Boundary", provider.CommandBoundaryWitnessPath),
|
||||
Metric("aetheria.daemon.editor.witnesses.game", "Game Surface", provider.EveGuiSurfaceWitnessPath),
|
||||
Metric("aetheria.daemon.editor.witnesses.editor", "Editor Surface", provider.EditorGuiSurfaceWitnessPath)),
|
||||
Node(
|
||||
"aetheria.daemon.editor.health",
|
||||
"card",
|
||||
new[] { ("title", "Health") },
|
||||
Metric("aetheria.daemon.editor.health.status", "Status", health.Status),
|
||||
Metric("aetheria.daemon.editor.health.frame", "Frame", health.FrameId.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.editor.health.observed_commands", "Observed Commands", health.ObservedCommandCount.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.editor.health.applied", "Applied", health.AppliedCommandCount.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.editor.health.rejected", "Rejected", health.RejectedCommandCount.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.editor.health.source", "Source", health.PublicationSource),
|
||||
Metric("aetheria.daemon.editor.health.transport", "Transport", health.Transport)),
|
||||
Node(
|
||||
"aetheria.daemon.editor.schemas",
|
||||
"card",
|
||||
new[] { ("title", "Published Schemas") },
|
||||
Row(
|
||||
"aetheria.daemon.editor.schemas.rows",
|
||||
provider.PublishedSchemas
|
||||
.Select((schema, index) => Metric(
|
||||
$"aetheria.daemon.editor.schemas.{index}",
|
||||
"Schema",
|
||||
schema))
|
||||
.ToArray())),
|
||||
Node(
|
||||
"aetheria.daemon.editor.commands",
|
||||
"card",
|
||||
new[] { ("title", "Typed Commands") },
|
||||
Metric(
|
||||
"aetheria.daemon.editor.commands.boundary",
|
||||
"Boundary",
|
||||
commandBoundary.BoundaryId),
|
||||
Metric(
|
||||
"aetheria.daemon.editor.commands.count",
|
||||
"Command Count",
|
||||
commandBoundary.Commands.Count.ToString(CultureInfo.InvariantCulture)),
|
||||
Row(
|
||||
"aetheria.daemon.editor.commands.rows",
|
||||
commandBoundary.Commands
|
||||
.Take(16)
|
||||
.Select((entry, index) => CommandRow(index, entry))
|
||||
.ToArray()))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: commandBoundary.Commands
|
||||
.Select(entry => new AetheriaRuntimeSurfaceCommandTemplate(
|
||||
CommandName(entry.Kind),
|
||||
entry.Kind.ToString(),
|
||||
"cultmesh"))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent CommandRow(
|
||||
int index,
|
||||
AetheriaRuntimeDaemonCommandBoundaryEntry entry)
|
||||
{
|
||||
return Node(
|
||||
$"aetheria.daemon.editor.commands.{index}",
|
||||
"inspector.kv",
|
||||
new[]
|
||||
{
|
||||
("kind", entry.Kind.ToString()),
|
||||
("body", entry.CommandBody),
|
||||
("authority", entry.Authority),
|
||||
("receipt", entry.Receipt)
|
||||
});
|
||||
}
|
||||
|
||||
private static string CommandName(AetheriaRuntimeDaemonCommandKinds kind)
|
||||
{
|
||||
return "aetheria.daemon.commands." + kind;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Row(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonFrameStore
|
||||
{
|
||||
public static string GetFramePath(string stateFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stateFilePath))
|
||||
throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath));
|
||||
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonFramePath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string PublishFrame(string stateFilePath, AetheriaRuntimeDaemonFrameDocument frame)
|
||||
{
|
||||
if (frame == null) throw new ArgumentNullException(nameof(frame));
|
||||
|
||||
frame.Schema = AetheriaRuntimeDaemonSchemas.Frame;
|
||||
if (string.IsNullOrWhiteSpace(frame.PublishedAtUtc))
|
||||
frame.PublishedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
|
||||
var framePath = GetFramePath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(framePath) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonFrame(framePath, frame);
|
||||
return framePath;
|
||||
}
|
||||
|
||||
public static bool TryReadFrame(string stateFilePath, out AetheriaRuntimeDaemonFrameDocument frame)
|
||||
{
|
||||
var framePath = GetFramePath(stateFilePath);
|
||||
if (!File.Exists(framePath))
|
||||
{
|
||||
frame = new AetheriaRuntimeDaemonFrameDocument();
|
||||
return false;
|
||||
}
|
||||
|
||||
frame = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonFrame(framePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonFrameDocument ReadFrame(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeCultCacheDocumentStore.ReadDaemonFrame(GetFramePath(stateFilePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2da25246f5a801f4db2d26f4100b70ad
|
||||
|
|
@ -0,0 +1,211 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonGameSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.game";
|
||||
public const string TuiSurfaceId = "aetheria.game.tui";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeDaemonFrameDocument frame,
|
||||
AetheriaRuntimeDaemonHealthDocument health,
|
||||
AetheriaRuntimeDaemonCommandBoundaryDocument commandBoundary)
|
||||
{
|
||||
frame ??= new AetheriaRuntimeDaemonFrameDocument();
|
||||
health ??= new AetheriaRuntimeDaemonHealthDocument();
|
||||
commandBoundary ??= AetheriaRuntimeDaemonCommandBoundaryDocument.Create(frame.DaemonId);
|
||||
|
||||
var run = frame.Run ?? new AetheriaRuntimeRunCheckpointCommit();
|
||||
var zone = FindCurrentZone(run);
|
||||
var entity = FindCurrentEntity(run, zone);
|
||||
var target = FindTargetEntity(zone, entity);
|
||||
var entityName = string.IsNullOrWhiteSpace(entity?.Name) ? "(no current entity)" : entity!.Name;
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria.daemon",
|
||||
providerKind: "game.daemon",
|
||||
title: "Aetheria Daemon",
|
||||
version: frame.FrameId,
|
||||
updatedAtUtc: frame.PublishedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
"aetheria.daemon.game.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Node(
|
||||
"aetheria.daemon.game.frame",
|
||||
"card",
|
||||
new[] { ("title", "Daemon Frame") },
|
||||
Metric("aetheria.daemon.game.frame.daemon", "Daemon", frame.DaemonId),
|
||||
Metric("aetheria.daemon.game.frame.verse", "Verse", health.VerseId),
|
||||
Metric("aetheria.daemon.game.frame.frameId", "Frame", frame.FrameId.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.frame.time", "Time", frame.SimulationTimeSeconds.ToString("0.###", CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.frame.status", "Status", health.Status),
|
||||
Metric("aetheria.daemon.game.frame.observed_commands", "Observed Commands", health.ObservedCommandCount.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.frame.applied", "Applied", health.AppliedCommandCount.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.frame.rejected", "Rejected", health.RejectedCommandCount.ToString(CultureInfo.InvariantCulture))),
|
||||
Node(
|
||||
"aetheria.daemon.game.player",
|
||||
"card",
|
||||
new[] { ("title", "Current Entity") },
|
||||
Metric("aetheria.daemon.game.player.run", "Run", run.RunId),
|
||||
Metric("aetheria.daemon.game.player.zone", "Zone", run.CurrentZoneIndex.ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.player.key", "Entity Key", run.CurrentEntityKey),
|
||||
Metric("aetheria.daemon.game.player.name", "Name", entityName),
|
||||
Metric("aetheria.daemon.game.player.position", "Position", FormatPosition(entity)),
|
||||
Metric("aetheria.daemon.game.player.target", "Target", string.IsNullOrWhiteSpace(target?.Name) ? "(none)" : target!.Name),
|
||||
Metric("aetheria.daemon.game.player.equipment", "Equipment", Count(entity?.Equipment).ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.player.cargo", "Cargo Bays", Count(entity?.CargoContents).ToString(CultureInfo.InvariantCulture)),
|
||||
Metric("aetheria.daemon.game.player.weaponGroups", "Weapon Groups", Count(entity?.WeaponGroups).ToString(CultureInfo.InvariantCulture))),
|
||||
Node(
|
||||
"aetheria.daemon.game.commands",
|
||||
"card",
|
||||
new[] { ("title", "Typed Command Boundary") },
|
||||
Metric(
|
||||
"aetheria.daemon.game.commands.boundary",
|
||||
"Boundary",
|
||||
commandBoundary.BoundaryId),
|
||||
Metric(
|
||||
"aetheria.daemon.game.commands.count",
|
||||
"Commands",
|
||||
Count(commandBoundary.Commands).ToString(CultureInfo.InvariantCulture)),
|
||||
Row(
|
||||
"aetheria.daemon.game.commands.primary",
|
||||
CommandButton("aetheria.daemon.game.commands.move", "Move", AetheriaRuntimeDaemonCommandKinds.SetMoveVector),
|
||||
CommandButton("aetheria.daemon.game.commands.target", "Set Target", AetheriaRuntimeDaemonCommandKinds.SetTarget),
|
||||
CommandButton("aetheria.daemon.game.commands.fire", "Fire", AetheriaRuntimeDaemonCommandKinds.FireWeaponGroup),
|
||||
CommandButton("aetheria.daemon.game.commands.ping", "Sensor Ping", AetheriaRuntimeDaemonCommandKinds.SensorPing)))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: commandBoundary.Commands
|
||||
.Select(entry => new AetheriaRuntimeSurfaceCommandTemplate(
|
||||
CommandName(entry.Kind),
|
||||
Label(entry.Kind),
|
||||
"cultmesh"))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeZoneSnapshotCommit FindCurrentZone(AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
return run.Zones.FirstOrDefault(zone => zone.ZoneIndex == run.CurrentZoneIndex)
|
||||
?? run.Zones.FirstOrDefault()
|
||||
?? new AetheriaRuntimeZoneSnapshotCommit();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEntitySnapshotCommit? FindCurrentEntity(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeZoneSnapshotCommit zone)
|
||||
{
|
||||
var entityIndex = TryParseEntityIndex(run.CurrentEntityKey);
|
||||
if (entityIndex >= 0)
|
||||
return zone.Entities.FirstOrDefault(entity => entity.EntityIndex == entityIndex);
|
||||
|
||||
return zone.Entities.FirstOrDefault();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEntitySnapshotCommit? FindTargetEntity(
|
||||
AetheriaRuntimeZoneSnapshotCommit zone,
|
||||
AetheriaRuntimeEntitySnapshotCommit? entity)
|
||||
{
|
||||
if (entity == null || entity.TargetEntityIndex < 0)
|
||||
return null;
|
||||
|
||||
return zone.Entities.FirstOrDefault(candidate => candidate.EntityIndex == entity.TargetEntityIndex);
|
||||
}
|
||||
|
||||
private static int TryParseEntityIndex(string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return -1;
|
||||
|
||||
var marker = ".entity.";
|
||||
var markerIndex = key.LastIndexOf(marker, StringComparison.Ordinal);
|
||||
if (markerIndex < 0)
|
||||
return -1;
|
||||
|
||||
var start = markerIndex + marker.Length;
|
||||
var end = start;
|
||||
while (end < key.Length && char.IsDigit(key[end]))
|
||||
end++;
|
||||
|
||||
return int.TryParse(key.Substring(start, end - start), NumberStyles.Integer, CultureInfo.InvariantCulture, out var value)
|
||||
? value
|
||||
: -1;
|
||||
}
|
||||
|
||||
private static string FormatPosition(AetheriaRuntimeEntitySnapshotCommit? entity)
|
||||
{
|
||||
if (entity == null)
|
||||
return "(none)";
|
||||
|
||||
return string.Join(", ", new[]
|
||||
{
|
||||
entity.PositionX.ToString("0.###", CultureInfo.InvariantCulture),
|
||||
entity.PositionY.ToString("0.###", CultureInfo.InvariantCulture),
|
||||
entity.PositionZ.ToString("0.###", CultureInfo.InvariantCulture)
|
||||
});
|
||||
}
|
||||
|
||||
private static int Count<T>(IReadOnlyCollection<T>? values)
|
||||
{
|
||||
return values?.Count ?? 0;
|
||||
}
|
||||
|
||||
private static string CommandName(AetheriaRuntimeDaemonCommandKinds kind)
|
||||
{
|
||||
return "aetheria.daemon.commands." + kind;
|
||||
}
|
||||
|
||||
private static string Label(AetheriaRuntimeDaemonCommandKinds kind)
|
||||
{
|
||||
return kind.ToString();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent CommandButton(
|
||||
string id,
|
||||
string label,
|
||||
AetheriaRuntimeDaemonCommandKinds kind)
|
||||
{
|
||||
return Node(
|
||||
id,
|
||||
"control.button",
|
||||
new[]
|
||||
{
|
||||
("label", label),
|
||||
("command", CommandName(kind)),
|
||||
("commandBody", nameof(AetheriaRuntimeDaemonCommandDocument))
|
||||
});
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Row(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeDaemonIntentState
|
||||
{
|
||||
public AetheriaRuntimeDaemonMovementIntent? Movement { get; set; }
|
||||
public List<AetheriaRuntimeDaemonWeaponGroupIntent> WeaponGroups { get; } =
|
||||
new List<AetheriaRuntimeDaemonWeaponGroupIntent>();
|
||||
public List<AetheriaRuntimeDaemonBehaviorIntent> Behaviors { get; } =
|
||||
new List<AetheriaRuntimeDaemonBehaviorIntent>();
|
||||
public List<AetheriaRuntimeDaemonConsumableIntent> Consumables { get; } =
|
||||
new List<AetheriaRuntimeDaemonConsumableIntent>();
|
||||
public List<AetheriaRuntimeDaemonDockingIntent> Docking { get; } =
|
||||
new List<AetheriaRuntimeDaemonDockingIntent>();
|
||||
public List<AetheriaRuntimeDaemonWormholeIntent> Wormholes { get; } =
|
||||
new List<AetheriaRuntimeDaemonWormholeIntent>();
|
||||
public List<AetheriaRuntimeDaemonTowIntent> Towing { get; } =
|
||||
new List<AetheriaRuntimeDaemonTowIntent>();
|
||||
public bool SensorPingRequested { get; set; }
|
||||
|
||||
public bool HasAny =>
|
||||
Movement != null ||
|
||||
SensorPingRequested ||
|
||||
WeaponGroups.Count > 0 ||
|
||||
Behaviors.Count > 0 ||
|
||||
Consumables.Count > 0 ||
|
||||
Docking.Count > 0 ||
|
||||
Wormholes.Count > 0 ||
|
||||
Towing.Count > 0;
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonMovementIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public double DirectionX { get; set; }
|
||||
public double DirectionY { get; set; }
|
||||
public double Magnitude { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonWeaponGroupIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public int WeaponGroup { get; set; } = -1;
|
||||
public bool Fire { get; set; }
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonBehaviorIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public int EquipmentIndex { get; set; } = -1;
|
||||
public int BehaviorIndex { get; set; } = -1;
|
||||
public bool Active { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonConsumableIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public string ItemKey { get; set; } = "";
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonDockingIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public string TargetEntityKey { get; set; } = "";
|
||||
public bool Dock { get; set; }
|
||||
public bool Undock { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonWormholeIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public int TargetZoneIndex { get; set; } = -1;
|
||||
public double PositionX { get; set; }
|
||||
public double PositionY { get; set; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonTowIntent
|
||||
{
|
||||
public string ActorEntityKey { get; set; } = "";
|
||||
public string StationEntityKey { get; set; } = "";
|
||||
public int TargetZoneIndex { get; set; } = -1;
|
||||
public double PositionX { get; set; }
|
||||
public double PositionY { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
using System;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeDaemonObservationResult
|
||||
{
|
||||
public AetheriaRuntimeDaemonObservationResult(
|
||||
bool observed,
|
||||
bool frameChanged,
|
||||
bool soaViewChanged,
|
||||
long frameId,
|
||||
long soaGeneration,
|
||||
bool isAuthoritative)
|
||||
{
|
||||
Observed = observed;
|
||||
FrameChanged = frameChanged;
|
||||
SoaViewChanged = soaViewChanged;
|
||||
FrameId = frameId;
|
||||
SoaGeneration = soaGeneration;
|
||||
IsAuthoritative = isAuthoritative;
|
||||
}
|
||||
|
||||
public bool Observed { get; }
|
||||
public bool FrameChanged { get; }
|
||||
public bool SoaViewChanged { get; }
|
||||
public bool Changed => FrameChanged || SoaViewChanged;
|
||||
public long FrameId { get; }
|
||||
public long SoaGeneration { get; }
|
||||
public bool IsAuthoritative { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonObservationCursor
|
||||
{
|
||||
public long LastFrameId { get; private set; } = -1;
|
||||
public long LastSoaGeneration { get; private set; } = -1;
|
||||
public string LastDaemonId { get; private set; } = "";
|
||||
public string LastSessionId { get; private set; } = "";
|
||||
public string LastFramePath { get; private set; } = "";
|
||||
public string LastSoaViewPath { get; private set; } = "";
|
||||
|
||||
public AetheriaRuntimeDaemonObservationResult Observe(AetheriaRuntimeObservedDaemonState? observed)
|
||||
{
|
||||
if (observed == null)
|
||||
{
|
||||
return new AetheriaRuntimeDaemonObservationResult(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
LastFrameId,
|
||||
LastSoaGeneration,
|
||||
false);
|
||||
}
|
||||
|
||||
var frame = observed.Frame;
|
||||
var soaGeneration = observed.SoaView?.Generation ?? -1;
|
||||
var frameChanged = frame.FrameId != LastFrameId ||
|
||||
!string.Equals(frame.DaemonId, LastDaemonId, StringComparison.Ordinal) ||
|
||||
!string.Equals(frame.SessionId, LastSessionId, StringComparison.Ordinal);
|
||||
var soaViewChanged = soaGeneration != LastSoaGeneration;
|
||||
|
||||
LastFrameId = frame.FrameId;
|
||||
LastSoaGeneration = soaGeneration;
|
||||
LastDaemonId = frame.DaemonId ?? "";
|
||||
LastSessionId = frame.SessionId ?? "";
|
||||
LastFramePath = observed.FramePath ?? "";
|
||||
LastSoaViewPath = observed.SoaViewPath ?? "";
|
||||
|
||||
return new AetheriaRuntimeDaemonObservationResult(
|
||||
true,
|
||||
frameChanged,
|
||||
soaViewChanged,
|
||||
frame.FrameId,
|
||||
soaGeneration,
|
||||
frame.IsAuthoritative);
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
LastFrameId = -1;
|
||||
LastSoaGeneration = -1;
|
||||
LastDaemonId = "";
|
||||
LastSessionId = "";
|
||||
LastFramePath = "";
|
||||
LastSoaViewPath = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bd46bb16aafbc684fa18d590767c9f9f
|
||||
|
|
@ -0,0 +1,282 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonPublicationStore
|
||||
{
|
||||
public static string GetProviderAdvertisementPath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonProviderPath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string GetHealthPath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonHealthPath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string GetCommandBoundaryPath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonCommandBoundaryPath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string GetGameSurfacePath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonGameSurfacePath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string GetGameTuiSurfacePath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonGameTuiSurfacePath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string GetEditorSurfacePath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonEditorSurfacePath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string GetEditorTuiSurfacePath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonEditorTuiSurfacePath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string PublishProviderAdvertisement(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeDaemonProviderAdvertisementDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
document.Schema = AetheriaRuntimeDaemonSchemas.ProviderAdvertisement;
|
||||
if (string.IsNullOrWhiteSpace(document.PublishedAtUtc))
|
||||
document.PublishedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
|
||||
var path = GetProviderAdvertisementPath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonProviderAdvertisement(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string PublishHealth(string stateFilePath, AetheriaRuntimeDaemonHealthDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
document.Schema = AetheriaRuntimeDaemonSchemas.Health;
|
||||
if (string.IsNullOrWhiteSpace(document.PublishedAtUtc))
|
||||
document.PublishedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
|
||||
var path = GetHealthPath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonHealth(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string PublishCommandBoundary(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeDaemonCommandBoundaryDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
document.Schema = AetheriaRuntimeDaemonSchemas.CommandBoundary;
|
||||
if (string.IsNullOrWhiteSpace(document.PublishedAtUtc))
|
||||
document.PublishedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
|
||||
var path = GetCommandBoundaryPath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonCommandBoundary(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string PublishGameSurface(string stateFilePath, AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
var path = GetGameSurfacePath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonGameSurface(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string PublishGameTuiSurface(string stateFilePath, AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
var path = GetGameTuiSurfacePath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonGameSurface(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string PublishEditorSurface(string stateFilePath, AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
var path = GetEditorSurfacePath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonEditorSurface(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static string PublishEditorTuiSurface(string stateFilePath, AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
var path = GetEditorTuiSurfacePath(stateFilePath);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path) ?? ".");
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonEditorSurface(path, document);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static bool TryReadProviderAdvertisement(
|
||||
string stateFilePath,
|
||||
out AetheriaRuntimeDaemonProviderAdvertisementDocument document)
|
||||
{
|
||||
var path = GetProviderAdvertisementPath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeDaemonProviderAdvertisementDocument();
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonProviderAdvertisement(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadHealth(string stateFilePath, out AetheriaRuntimeDaemonHealthDocument document)
|
||||
{
|
||||
var path = GetHealthPath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeDaemonHealthDocument();
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonHealth(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadCommandBoundary(
|
||||
string stateFilePath,
|
||||
out AetheriaRuntimeDaemonCommandBoundaryDocument document)
|
||||
{
|
||||
var path = GetCommandBoundaryPath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeDaemonCommandBoundaryDocument();
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonCommandBoundary(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadGameSurface(string stateFilePath, out AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
var path = GetGameSurfacePath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeSurfaceDocument(
|
||||
"aetheria.daemon",
|
||||
"game.daemon",
|
||||
"",
|
||||
0,
|
||||
"",
|
||||
new AetheriaRuntimeSurfaceTree(
|
||||
AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId,
|
||||
new AetheriaRuntimeSurfaceComponent(
|
||||
"aetheria.daemon.game.empty",
|
||||
"surface",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceCommandTemplate>());
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonGameSurface(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadGameTuiSurface(string stateFilePath, out AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
var path = GetGameTuiSurfacePath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeSurfaceDocument(
|
||||
"aetheria.daemon",
|
||||
"game.daemon",
|
||||
"Aetheria Daemon",
|
||||
0,
|
||||
"",
|
||||
new AetheriaRuntimeSurfaceTree(
|
||||
AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId,
|
||||
new AetheriaRuntimeSurfaceComponent(
|
||||
"aetheria.daemon.game.tui.missing",
|
||||
"surface",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceCommandTemplate>());
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonGameSurface(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadEditorSurface(string stateFilePath, out AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
var path = GetEditorSurfacePath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeSurfaceDocument(
|
||||
"aetheria.daemon",
|
||||
"editor.daemon",
|
||||
"",
|
||||
0,
|
||||
"",
|
||||
new AetheriaRuntimeSurfaceTree(
|
||||
AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId,
|
||||
new AetheriaRuntimeSurfaceComponent(
|
||||
"aetheria.daemon.editor.empty",
|
||||
"surface",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceCommandTemplate>());
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonEditorSurface(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadEditorTuiSurface(string stateFilePath, out AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
var path = GetEditorTuiSurfacePath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
document = new AetheriaRuntimeSurfaceDocument(
|
||||
"aetheria.daemon",
|
||||
"editor.daemon",
|
||||
"Aetheria Daemon Editor",
|
||||
0,
|
||||
"",
|
||||
new AetheriaRuntimeSurfaceTree(
|
||||
AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId,
|
||||
new AetheriaRuntimeSurfaceComponent(
|
||||
"aetheria.daemon.editor.tui.missing",
|
||||
"surface",
|
||||
new System.Collections.Generic.Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<AetheriaRuntimeSurfaceComponent>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceCommandTemplate>());
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonEditorSurface(path);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,271 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonSoaBackends
|
||||
{
|
||||
public const string CultCache = "cultcache";
|
||||
public const string MemoryMappedFile = "memory_mapped_file";
|
||||
public const string SharedNativeMemory = "shared_native_memory";
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeDaemonSoaSynchronizationModes
|
||||
{
|
||||
public const string ImmutableFrame = "immutable_frame";
|
||||
public const string DoubleBuffered = "double_buffered";
|
||||
public const string TripleBuffered = "triple_buffered";
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeDaemonSoaColumnKinds
|
||||
{
|
||||
public const string EntityKey = "entity.key";
|
||||
public const string ZoneIndex = "entity.zone_index";
|
||||
public const string PositionX = "transform.position.x";
|
||||
public const string PositionY = "transform.position.y";
|
||||
public const string PositionZ = "transform.position.z";
|
||||
public const string RotationRadians = "transform.rotation.radians";
|
||||
public const string VelocityX = "motion.velocity.x";
|
||||
public const string VelocityY = "motion.velocity.y";
|
||||
public const string VelocityZ = "motion.velocity.z";
|
||||
public const string PhysicsBodyRadius = "physics.body.radius";
|
||||
public const string PhysicsBodyMass = "physics.body.mass";
|
||||
public const string PhysicsBodyInverseMass = "physics.body.inverse_mass";
|
||||
public const string Hull = "stats.hull";
|
||||
public const string Heat = "stats.heat";
|
||||
public const string Quality = "stats.quality";
|
||||
public const string Durability = "stats.durability";
|
||||
public const string RenderGroupId = "render.group.id";
|
||||
public const string RenderScale = "render.scale";
|
||||
public const string RenderVisibility = "render.visibility";
|
||||
public const string RenderLod = "render.lod";
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeDaemonRenderShadowModes
|
||||
{
|
||||
public const string Off = "off";
|
||||
public const string On = "on";
|
||||
public const string TwoSided = "two_sided";
|
||||
public const string ShadowsOnly = "shadows_only";
|
||||
}
|
||||
|
||||
[CultDocument("gamecult.aetheria.daemon_soa_view", "gamecult.aetheria.daemon_soa_view.v1")]
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeDaemonSoaViewDocument
|
||||
{
|
||||
[Key(0)]
|
||||
public string Schema { get; set; } = AetheriaRuntimeDaemonSchemas.SoaView;
|
||||
|
||||
[Key(1)]
|
||||
public string DaemonId { get; set; } = "local";
|
||||
|
||||
[Key(2)]
|
||||
public string SessionId { get; set; } = "local";
|
||||
|
||||
[Key(3)]
|
||||
public long FrameId { get; set; }
|
||||
|
||||
[Key(4)]
|
||||
public long Generation { get; set; }
|
||||
|
||||
[Key(5)]
|
||||
public string PublishedAtUtc { get; set; } = "";
|
||||
|
||||
[Key(6)]
|
||||
public bool IsAuthoritative { get; set; } = true;
|
||||
|
||||
[Key(7)]
|
||||
public string Backend { get; set; } = AetheriaRuntimeDaemonSoaBackends.CultCache;
|
||||
|
||||
[Key(8)]
|
||||
public string SynchronizationMode { get; set; } = AetheriaRuntimeDaemonSoaSynchronizationModes.ImmutableFrame;
|
||||
|
||||
[Key(9)]
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonSoaBufferDocument> Buffers { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeDaemonSoaBufferDocument>();
|
||||
|
||||
[Key(10)]
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonSoaColumnDocument> Columns { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeDaemonSoaColumnDocument>();
|
||||
|
||||
[Key(11)]
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonSoaDirtyRangeDocument> DirtyRanges { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeDaemonSoaDirtyRangeDocument>();
|
||||
|
||||
[Key(12)]
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonRenderGroupDocument> RenderGroups { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeDaemonRenderGroupDocument>();
|
||||
|
||||
public static AetheriaRuntimeDaemonSoaViewDocument Create(
|
||||
string daemonId,
|
||||
string sessionId,
|
||||
long frameId,
|
||||
long generation,
|
||||
IReadOnlyList<AetheriaRuntimeDaemonSoaBufferDocument>? buffers,
|
||||
IReadOnlyList<AetheriaRuntimeDaemonSoaColumnDocument>? columns,
|
||||
IReadOnlyList<AetheriaRuntimeDaemonSoaDirtyRangeDocument>? dirtyRanges = null,
|
||||
string backend = AetheriaRuntimeDaemonSoaBackends.CultCache,
|
||||
string synchronizationMode = AetheriaRuntimeDaemonSoaSynchronizationModes.ImmutableFrame,
|
||||
bool isAuthoritative = true,
|
||||
IReadOnlyList<AetheriaRuntimeDaemonRenderGroupDocument>? renderGroups = null)
|
||||
{
|
||||
return new AetheriaRuntimeDaemonSoaViewDocument
|
||||
{
|
||||
DaemonId = string.IsNullOrWhiteSpace(daemonId) ? "local" : daemonId,
|
||||
SessionId = string.IsNullOrWhiteSpace(sessionId) ? "local" : sessionId,
|
||||
FrameId = frameId,
|
||||
Generation = generation,
|
||||
PublishedAtUtc = DateTime.UtcNow.ToString("O"),
|
||||
IsAuthoritative = isAuthoritative,
|
||||
Backend = string.IsNullOrWhiteSpace(backend) ? AetheriaRuntimeDaemonSoaBackends.CultCache : backend,
|
||||
SynchronizationMode = string.IsNullOrWhiteSpace(synchronizationMode)
|
||||
? AetheriaRuntimeDaemonSoaSynchronizationModes.ImmutableFrame
|
||||
: synchronizationMode,
|
||||
Buffers = buffers ?? Array.Empty<AetheriaRuntimeDaemonSoaBufferDocument>(),
|
||||
Columns = columns ?? Array.Empty<AetheriaRuntimeDaemonSoaColumnDocument>(),
|
||||
DirtyRanges = dirtyRanges ?? Array.Empty<AetheriaRuntimeDaemonSoaDirtyRangeDocument>(),
|
||||
RenderGroups = renderGroups ?? Array.Empty<AetheriaRuntimeDaemonRenderGroupDocument>()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeDaemonRenderGroupDocument
|
||||
{
|
||||
[Key(0)]
|
||||
public int GroupId { get; set; }
|
||||
|
||||
[Key(1)]
|
||||
public string MeshKey { get; set; } = "";
|
||||
|
||||
[Key(2)]
|
||||
public string MaterialKey { get; set; } = "";
|
||||
|
||||
[Key(3)]
|
||||
public int SubMeshIndex { get; set; }
|
||||
|
||||
[Key(4)]
|
||||
public int Layer { get; set; }
|
||||
|
||||
[Key(5)]
|
||||
public string ShaderKey { get; set; } = "";
|
||||
|
||||
[Key(6)]
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
[Key(7)]
|
||||
public int InstanceCount { get; set; } = -1;
|
||||
|
||||
[Key(8)]
|
||||
public float BoundsCenterX { get; set; }
|
||||
|
||||
[Key(9)]
|
||||
public float BoundsCenterY { get; set; }
|
||||
|
||||
[Key(10)]
|
||||
public float BoundsCenterZ { get; set; }
|
||||
|
||||
[Key(11)]
|
||||
public float BoundsSizeX { get; set; } = -1.0f;
|
||||
|
||||
[Key(12)]
|
||||
public float BoundsSizeY { get; set; } = -1.0f;
|
||||
|
||||
[Key(13)]
|
||||
public float BoundsSizeZ { get; set; } = -1.0f;
|
||||
|
||||
[Key(14)]
|
||||
public string ShadowMode { get; set; } = AetheriaRuntimeDaemonRenderShadowModes.On;
|
||||
|
||||
[Key(15)]
|
||||
public bool ReceiveShadows { get; set; } = true;
|
||||
|
||||
[Key(16)]
|
||||
public float DefaultScale { get; set; } = 1.0f;
|
||||
|
||||
[Key(17)]
|
||||
public int Lod { get; set; } = -1;
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeDaemonSoaBufferDocument
|
||||
{
|
||||
[Key(0)]
|
||||
public string BufferId { get; set; } = "";
|
||||
|
||||
[Key(1)]
|
||||
public string DisplayName { get; set; } = "";
|
||||
|
||||
[Key(2)]
|
||||
public string Backend { get; set; } = AetheriaRuntimeDaemonSoaBackends.CultCache;
|
||||
|
||||
[Key(3)]
|
||||
public string Location { get; set; } = "";
|
||||
|
||||
[Key(4)]
|
||||
public long ByteOffset { get; set; }
|
||||
|
||||
[Key(5)]
|
||||
public long ByteLength { get; set; }
|
||||
|
||||
[Key(6)]
|
||||
public long Generation { get; set; }
|
||||
|
||||
[Key(7)]
|
||||
public bool DaemonWritable { get; set; } = true;
|
||||
|
||||
[Key(8)]
|
||||
public bool ObserverWritable { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeDaemonSoaColumnDocument
|
||||
{
|
||||
[Key(0)]
|
||||
public string ColumnId { get; set; } = "";
|
||||
|
||||
[Key(1)]
|
||||
public string Kind { get; set; } = "";
|
||||
|
||||
[Key(2)]
|
||||
public string BufferId { get; set; } = "";
|
||||
|
||||
[Key(3)]
|
||||
public string ScalarType { get; set; } = "";
|
||||
|
||||
[Key(4)]
|
||||
public long ByteOffset { get; set; }
|
||||
|
||||
[Key(5)]
|
||||
public int ElementStride { get; set; }
|
||||
|
||||
[Key(6)]
|
||||
public int ElementCount { get; set; }
|
||||
|
||||
[Key(7)]
|
||||
public string Unit { get; set; } = "";
|
||||
|
||||
[Key(8)]
|
||||
public string CoordinateSpace { get; set; } = "";
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeDaemonSoaDirtyRangeDocument
|
||||
{
|
||||
[Key(0)]
|
||||
public string ColumnId { get; set; } = "";
|
||||
|
||||
[Key(1)]
|
||||
public int StartIndex { get; set; }
|
||||
|
||||
[Key(2)]
|
||||
public int Count { get; set; }
|
||||
|
||||
[Key(3)]
|
||||
public long Generation { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: aaba35482c606b241adcf479cbfa4298
|
||||
|
|
@ -0,0 +1,451 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeDaemonSoaColumnBinding
|
||||
{
|
||||
public AetheriaRuntimeDaemonSoaColumnBinding(
|
||||
AetheriaRuntimeDaemonSoaColumnDocument column,
|
||||
AetheriaRuntimeDaemonSoaBufferDocument buffer,
|
||||
long absoluteByteOffset,
|
||||
long byteLength,
|
||||
bool directMemoryCompatible)
|
||||
{
|
||||
Column = column ?? throw new ArgumentNullException(nameof(column));
|
||||
Buffer = buffer ?? throw new ArgumentNullException(nameof(buffer));
|
||||
AbsoluteByteOffset = absoluteByteOffset;
|
||||
ByteLength = byteLength;
|
||||
DirectMemoryCompatible = directMemoryCompatible;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonSoaColumnDocument Column { get; }
|
||||
public AetheriaRuntimeDaemonSoaBufferDocument Buffer { get; }
|
||||
public long AbsoluteByteOffset { get; }
|
||||
public long ByteLength { get; }
|
||||
public bool DirectMemoryCompatible { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonSoaViewIndex
|
||||
{
|
||||
private readonly Dictionary<string, AetheriaRuntimeDaemonSoaBufferDocument> _buffersById;
|
||||
private readonly Dictionary<string, AetheriaRuntimeDaemonSoaColumnBinding> _columnsById;
|
||||
private readonly Dictionary<string, List<AetheriaRuntimeDaemonSoaColumnBinding>> _columnsByKind;
|
||||
private readonly Dictionary<string, List<AetheriaRuntimeDaemonSoaDirtyRangeDocument>> _dirtyRangesByColumnId;
|
||||
private readonly Dictionary<int, AetheriaRuntimeDaemonRenderGroupDocument> _renderGroupsById;
|
||||
|
||||
private AetheriaRuntimeDaemonSoaViewIndex(
|
||||
AetheriaRuntimeDaemonSoaViewDocument view,
|
||||
Dictionary<string, AetheriaRuntimeDaemonSoaBufferDocument> buffersById,
|
||||
Dictionary<string, AetheriaRuntimeDaemonSoaColumnBinding> columnsById,
|
||||
Dictionary<string, List<AetheriaRuntimeDaemonSoaColumnBinding>> columnsByKind,
|
||||
Dictionary<string, List<AetheriaRuntimeDaemonSoaDirtyRangeDocument>> dirtyRangesByColumnId,
|
||||
Dictionary<int, AetheriaRuntimeDaemonRenderGroupDocument> renderGroupsById,
|
||||
string[] validationErrors)
|
||||
{
|
||||
View = view ?? throw new ArgumentNullException(nameof(view));
|
||||
_buffersById = buffersById;
|
||||
_columnsById = columnsById;
|
||||
_columnsByKind = columnsByKind;
|
||||
_dirtyRangesByColumnId = dirtyRangesByColumnId;
|
||||
_renderGroupsById = renderGroupsById;
|
||||
ValidationErrors = validationErrors;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonSoaViewDocument View { get; }
|
||||
public IReadOnlyList<string> ValidationErrors { get; }
|
||||
public bool IsValid => ValidationErrors.Count == 0;
|
||||
|
||||
public static AetheriaRuntimeDaemonSoaViewIndex Empty { get; } =
|
||||
Build(new AetheriaRuntimeDaemonSoaViewDocument { IsAuthoritative = false });
|
||||
|
||||
public static AetheriaRuntimeDaemonSoaViewIndex Build(
|
||||
AetheriaRuntimeDaemonSoaViewDocument? view,
|
||||
bool requireObserverReadOnly = true)
|
||||
{
|
||||
var effectiveView = view ?? new AetheriaRuntimeDaemonSoaViewDocument { IsAuthoritative = false };
|
||||
var errors = new List<string>();
|
||||
var buffersById = new Dictionary<string, AetheriaRuntimeDaemonSoaBufferDocument>(StringComparer.Ordinal);
|
||||
var columnsById = new Dictionary<string, AetheriaRuntimeDaemonSoaColumnBinding>(StringComparer.Ordinal);
|
||||
var columnsByKind = new Dictionary<string, List<AetheriaRuntimeDaemonSoaColumnBinding>>(StringComparer.Ordinal);
|
||||
var dirtyRangesByColumnId = new Dictionary<string, List<AetheriaRuntimeDaemonSoaDirtyRangeDocument>>(StringComparer.Ordinal);
|
||||
var renderGroupsById = new Dictionary<int, AetheriaRuntimeDaemonRenderGroupDocument>();
|
||||
|
||||
if (!string.Equals(effectiveView.Schema, AetheriaRuntimeDaemonSchemas.SoaView, StringComparison.Ordinal))
|
||||
{
|
||||
errors.Add($"Unexpected SoA schema '{effectiveView.Schema}'.");
|
||||
}
|
||||
|
||||
foreach (var buffer in effectiveView.Buffers ?? Array.Empty<AetheriaRuntimeDaemonSoaBufferDocument>())
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(buffer.BufferId))
|
||||
{
|
||||
errors.Add("SoA buffer is missing a buffer id.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (buffersById.ContainsKey(buffer.BufferId))
|
||||
{
|
||||
errors.Add($"Duplicate SoA buffer id '{buffer.BufferId}'.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (buffer.ByteOffset < 0)
|
||||
{
|
||||
errors.Add($"SoA buffer '{buffer.BufferId}' has a negative byte offset.");
|
||||
}
|
||||
|
||||
if (buffer.ByteLength < 0)
|
||||
{
|
||||
errors.Add($"SoA buffer '{buffer.BufferId}' has a negative byte length.");
|
||||
}
|
||||
|
||||
if (requireObserverReadOnly && buffer.ObserverWritable)
|
||||
{
|
||||
errors.Add($"SoA buffer '{buffer.BufferId}' is observer-writable; Unity must observe daemon state read-only.");
|
||||
}
|
||||
|
||||
buffersById.Add(buffer.BufferId, buffer);
|
||||
}
|
||||
|
||||
foreach (var column in effectiveView.Columns ?? Array.Empty<AetheriaRuntimeDaemonSoaColumnDocument>())
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(column.ColumnId))
|
||||
{
|
||||
errors.Add("SoA column is missing a column id.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (columnsById.ContainsKey(column.ColumnId))
|
||||
{
|
||||
errors.Add($"Duplicate SoA column id '{column.ColumnId}'.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!buffersById.TryGetValue(column.BufferId ?? "", out var buffer))
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' references missing buffer '{column.BufferId}'.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(column.Kind))
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' is missing a semantic kind.");
|
||||
}
|
||||
|
||||
if (column.ByteOffset < 0)
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' has a negative byte offset.");
|
||||
}
|
||||
|
||||
if (column.ElementStride <= 0)
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' has a non-positive element stride.");
|
||||
}
|
||||
|
||||
if (column.ElementCount < 0)
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' has a negative element count.");
|
||||
}
|
||||
|
||||
var scalarByteLength = GetScalarByteLength(column.ScalarType);
|
||||
if (scalarByteLength <= 0)
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' has unsupported scalar type '{column.ScalarType}'.");
|
||||
scalarByteLength = Math.Max(1, column.ElementStride);
|
||||
}
|
||||
|
||||
var columnByteLength = GetColumnByteLength(column.ElementCount, column.ElementStride, scalarByteLength);
|
||||
var absoluteByteOffset = buffer.ByteOffset + column.ByteOffset;
|
||||
if (column.ByteOffset >= 0 && columnByteLength >= 0 && buffer.ByteLength >= 0)
|
||||
{
|
||||
var columnEnd = column.ByteOffset + columnByteLength;
|
||||
if (columnEnd > buffer.ByteLength)
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' exceeds buffer '{buffer.BufferId}'.");
|
||||
}
|
||||
}
|
||||
|
||||
var binding = new AetheriaRuntimeDaemonSoaColumnBinding(
|
||||
column,
|
||||
buffer,
|
||||
absoluteByteOffset,
|
||||
columnByteLength,
|
||||
IsDirectMemoryCompatible(buffer));
|
||||
|
||||
ValidateSemanticColumn(column, errors);
|
||||
|
||||
columnsById.Add(column.ColumnId, binding);
|
||||
if (!columnsByKind.TryGetValue(column.Kind ?? "", out var kindBindings))
|
||||
{
|
||||
kindBindings = new List<AetheriaRuntimeDaemonSoaColumnBinding>();
|
||||
columnsByKind[column.Kind ?? ""] = kindBindings;
|
||||
}
|
||||
|
||||
kindBindings.Add(binding);
|
||||
}
|
||||
|
||||
foreach (var dirtyRange in effectiveView.DirtyRanges ?? Array.Empty<AetheriaRuntimeDaemonSoaDirtyRangeDocument>())
|
||||
{
|
||||
if (!columnsById.TryGetValue(dirtyRange.ColumnId ?? "", out var binding))
|
||||
{
|
||||
errors.Add($"SoA dirty range references missing column '{dirtyRange.ColumnId}'.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (dirtyRange.StartIndex < 0)
|
||||
{
|
||||
errors.Add($"SoA dirty range for column '{dirtyRange.ColumnId}' has a negative start index.");
|
||||
}
|
||||
|
||||
if (dirtyRange.Count < 0)
|
||||
{
|
||||
errors.Add($"SoA dirty range for column '{dirtyRange.ColumnId}' has a negative count.");
|
||||
}
|
||||
|
||||
if (dirtyRange.StartIndex >= 0 && dirtyRange.Count >= 0 &&
|
||||
dirtyRange.StartIndex + dirtyRange.Count > binding.Column.ElementCount)
|
||||
{
|
||||
errors.Add($"SoA dirty range for column '{dirtyRange.ColumnId}' exceeds the column element count.");
|
||||
}
|
||||
|
||||
if (!dirtyRangesByColumnId.TryGetValue(dirtyRange.ColumnId ?? "", out var ranges))
|
||||
{
|
||||
ranges = new List<AetheriaRuntimeDaemonSoaDirtyRangeDocument>();
|
||||
dirtyRangesByColumnId[dirtyRange.ColumnId ?? ""] = ranges;
|
||||
}
|
||||
|
||||
ranges.Add(dirtyRange);
|
||||
}
|
||||
|
||||
foreach (var renderGroup in effectiveView.RenderGroups ?? Array.Empty<AetheriaRuntimeDaemonRenderGroupDocument>())
|
||||
{
|
||||
if (renderGroup.GroupId < 0)
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' has a negative group id.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (renderGroupsById.ContainsKey(renderGroup.GroupId))
|
||||
{
|
||||
errors.Add($"Duplicate render group id '{renderGroup.GroupId}'.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(renderGroup.MeshKey))
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' is missing a mesh key.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(renderGroup.MaterialKey))
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' is missing a material key.");
|
||||
}
|
||||
|
||||
if (renderGroup.SubMeshIndex < 0)
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' has a negative submesh index.");
|
||||
}
|
||||
|
||||
if (renderGroup.InstanceCount < -1)
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' has an invalid instance count.");
|
||||
}
|
||||
|
||||
if (renderGroup.BoundsSizeX <= 0 ||
|
||||
renderGroup.BoundsSizeY <= 0 ||
|
||||
renderGroup.BoundsSizeZ <= 0)
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' must publish positive render bounds.");
|
||||
}
|
||||
|
||||
if (!IsValidShadowMode(renderGroup.ShadowMode))
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' has invalid shadow mode '{renderGroup.ShadowMode}'.");
|
||||
}
|
||||
|
||||
if (renderGroup.DefaultScale <= 0)
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' has a non-positive default scale.");
|
||||
}
|
||||
|
||||
if (renderGroup.Lod < -1)
|
||||
{
|
||||
errors.Add($"Render group '{renderGroup.GroupId}' has an invalid render lod.");
|
||||
}
|
||||
|
||||
renderGroupsById.Add(renderGroup.GroupId, renderGroup);
|
||||
}
|
||||
|
||||
if (renderGroupsById.Count > 1 &&
|
||||
!columnsByKind.ContainsKey(AetheriaRuntimeDaemonSoaColumnKinds.RenderGroupId))
|
||||
{
|
||||
errors.Add("Multiple render groups require a render group id column.");
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeDaemonSoaViewIndex(
|
||||
effectiveView,
|
||||
buffersById,
|
||||
columnsById,
|
||||
columnsByKind,
|
||||
dirtyRangesByColumnId,
|
||||
renderGroupsById,
|
||||
errors.ToArray());
|
||||
}
|
||||
|
||||
public bool TryGetBuffer(string bufferId, out AetheriaRuntimeDaemonSoaBufferDocument buffer)
|
||||
{
|
||||
return _buffersById.TryGetValue(bufferId ?? "", out buffer);
|
||||
}
|
||||
|
||||
public bool TryGetColumn(string columnId, out AetheriaRuntimeDaemonSoaColumnBinding binding)
|
||||
{
|
||||
return _columnsById.TryGetValue(columnId ?? "", out binding);
|
||||
}
|
||||
|
||||
public bool TryGetFirstColumnOfKind(string kind, out AetheriaRuntimeDaemonSoaColumnBinding binding)
|
||||
{
|
||||
if (_columnsByKind.TryGetValue(kind ?? "", out var bindings) && bindings.Count > 0)
|
||||
{
|
||||
binding = bindings[0];
|
||||
return true;
|
||||
}
|
||||
|
||||
binding = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonSoaColumnBinding> GetColumnsOfKind(string kind)
|
||||
{
|
||||
return _columnsByKind.TryGetValue(kind ?? "", out var bindings)
|
||||
? bindings
|
||||
: Array.Empty<AetheriaRuntimeDaemonSoaColumnBinding>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonSoaDirtyRangeDocument> GetDirtyRanges(string columnId)
|
||||
{
|
||||
return _dirtyRangesByColumnId.TryGetValue(columnId ?? "", out var ranges)
|
||||
? ranges
|
||||
: Array.Empty<AetheriaRuntimeDaemonSoaDirtyRangeDocument>();
|
||||
}
|
||||
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonRenderGroupDocument> RenderGroups =>
|
||||
View.RenderGroups ?? Array.Empty<AetheriaRuntimeDaemonRenderGroupDocument>();
|
||||
|
||||
public bool TryGetRenderGroup(int groupId, out AetheriaRuntimeDaemonRenderGroupDocument renderGroup)
|
||||
{
|
||||
return _renderGroupsById.TryGetValue(groupId, out renderGroup);
|
||||
}
|
||||
|
||||
private static bool IsDirectMemoryCompatible(AetheriaRuntimeDaemonSoaBufferDocument buffer)
|
||||
{
|
||||
return !buffer.ObserverWritable &&
|
||||
(string.Equals(buffer.Backend, AetheriaRuntimeDaemonSoaBackends.MemoryMappedFile, StringComparison.Ordinal) ||
|
||||
string.Equals(buffer.Backend, AetheriaRuntimeDaemonSoaBackends.SharedNativeMemory, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
private static void ValidateSemanticColumn(
|
||||
AetheriaRuntimeDaemonSoaColumnDocument column,
|
||||
List<string> errors)
|
||||
{
|
||||
switch (column.Kind)
|
||||
{
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.PositionX:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.PositionY:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.PositionZ:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.RotationRadians:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.VelocityX:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.VelocityY:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.VelocityZ:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.PhysicsBodyRadius:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.PhysicsBodyMass:
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.PhysicsBodyInverseMass:
|
||||
if (!string.Equals(column.ScalarType, "float32", StringComparison.Ordinal))
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' {column.Kind} must use float32.");
|
||||
}
|
||||
|
||||
break;
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.RenderScale:
|
||||
if (!string.Equals(column.ScalarType, "float32", StringComparison.Ordinal))
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' render scale must use float32.");
|
||||
}
|
||||
|
||||
break;
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.RenderVisibility:
|
||||
if (!string.Equals(column.ScalarType, "bool", StringComparison.Ordinal) &&
|
||||
!string.Equals(column.ScalarType, "byte", StringComparison.Ordinal) &&
|
||||
!string.Equals(column.ScalarType, "uint8", StringComparison.Ordinal))
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' render visibility must use bool, byte, or uint8.");
|
||||
}
|
||||
|
||||
break;
|
||||
case AetheriaRuntimeDaemonSoaColumnKinds.RenderLod:
|
||||
if (!string.Equals(column.ScalarType, "int32", StringComparison.Ordinal))
|
||||
{
|
||||
errors.Add($"SoA column '{column.ColumnId}' render lod must use int32.");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsValidShadowMode(string? shadowMode)
|
||||
{
|
||||
switch (shadowMode)
|
||||
{
|
||||
case AetheriaRuntimeDaemonRenderShadowModes.Off:
|
||||
case AetheriaRuntimeDaemonRenderShadowModes.On:
|
||||
case AetheriaRuntimeDaemonRenderShadowModes.TwoSided:
|
||||
case AetheriaRuntimeDaemonRenderShadowModes.ShadowsOnly:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int GetScalarByteLength(string? scalarType)
|
||||
{
|
||||
switch (scalarType)
|
||||
{
|
||||
case "float32":
|
||||
case "int32":
|
||||
case "uint32":
|
||||
return 4;
|
||||
case "float64":
|
||||
case "int64":
|
||||
case "uint64":
|
||||
return 8;
|
||||
case "int16":
|
||||
case "uint16":
|
||||
return 2;
|
||||
case "byte":
|
||||
case "uint8":
|
||||
case "int8":
|
||||
case "bool":
|
||||
return 1;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private static long GetColumnByteLength(int elementCount, int elementStride, int scalarByteLength)
|
||||
{
|
||||
if (elementCount <= 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (elementStride <= 0 || scalarByteLength <= 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ((long)elementCount - 1) * elementStride + scalarByteLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0e36baec351d02f4f8de31d3a9ad74dd
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using System.IO;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonSoaViewStore
|
||||
{
|
||||
public static string GetViewPath(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeStateBoundary.GetDaemonSoaViewPath(stateFilePath);
|
||||
}
|
||||
|
||||
public static string PublishView(string stateFilePath, AetheriaRuntimeDaemonSoaViewDocument view)
|
||||
{
|
||||
var path = GetViewPath(stateFilePath);
|
||||
AetheriaRuntimeCultCacheDocumentStore.WriteDaemonSoaView(path, view);
|
||||
return path;
|
||||
}
|
||||
|
||||
public static bool TryReadView(string stateFilePath, out AetheriaRuntimeDaemonSoaViewDocument view)
|
||||
{
|
||||
var path = GetViewPath(stateFilePath);
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
view = new AetheriaRuntimeDaemonSoaViewDocument();
|
||||
return false;
|
||||
}
|
||||
|
||||
view = AetheriaRuntimeCultCacheDocumentStore.ReadDaemonSoaView(path);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeDaemonSoaViewDocument ReadView(string stateFilePath)
|
||||
{
|
||||
return AetheriaRuntimeCultCacheDocumentStore.ReadDaemonSoaView(GetViewPath(stateFilePath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e7b9b2f5fbcc6fd44b0a7984041a6330
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
using System;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeDaemonSurfaceCommands
|
||||
{
|
||||
private const string CommandPrefix = "aetheria.daemon.commands.";
|
||||
|
||||
public static bool TrySubmit(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeDaemonCommandEnvelope? envelope)
|
||||
{
|
||||
envelope = null;
|
||||
if (request == null ||
|
||||
!string.Equals(request.ProviderId, "aetheria.daemon", StringComparison.Ordinal) ||
|
||||
!TryResolveKind(request, out var kind))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
AetheriaRuntimeStateReader.TryReadObservedDaemonState(stateFilePath, out var observed);
|
||||
var client = new AetheriaRuntimeDaemonOperationClient(
|
||||
stateFilePath,
|
||||
string.IsNullOrWhiteSpace(request.ClientId) ? "unity-uitoolkit" : request.ClientId,
|
||||
observed?.Frame.SessionId ?? "local");
|
||||
var command = client.Create(kind, observed);
|
||||
if (client.TrySend(command, out envelope, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
envelope = AetheriaRuntimeDaemonOperationClient.ToEnvelope(command);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool TryResolveKind(EveSurfaceCommandRequest request, out AetheriaRuntimeDaemonCommandKinds kind)
|
||||
{
|
||||
kind = AetheriaRuntimeDaemonCommandKinds.None;
|
||||
var command = request.Command ?? "";
|
||||
if (command.StartsWith(CommandPrefix, StringComparison.Ordinal))
|
||||
command = command.Substring(CommandPrefix.Length);
|
||||
|
||||
return Enum.TryParse(command, ignoreCase: false, out kind) &&
|
||||
kind != AetheriaRuntimeDaemonCommandKinds.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,193 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeDaemonTickOptions
|
||||
{
|
||||
public string DaemonId { get; set; } = "aetheria-daemon";
|
||||
public string SessionId { get; set; } = "local";
|
||||
public string VerseId { get; set; } = "aetheria.local";
|
||||
public string CultMeshAddress { get; set; } = "cultmesh://aetheria.local/eve/providers/aetheria.daemon";
|
||||
public long FrameId { get; set; }
|
||||
public double SimulationTimeSeconds { get; set; }
|
||||
public double FixedDeltaSeconds { get; set; }
|
||||
public IReadOnlyList<AetheriaRuntimeDaemonCommandDocument> ObservedCommands { get; set; } =
|
||||
Array.Empty<AetheriaRuntimeDaemonCommandDocument>();
|
||||
public IReadOnlyList<string> AccountedCommandIds { get; set; } =
|
||||
Array.Empty<string>();
|
||||
public AetheriaRuntimeDaemonOperationContext OperationContext { get; set; } =
|
||||
new AetheriaRuntimeDaemonOperationContext();
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeDaemonTickResult
|
||||
{
|
||||
public AetheriaRuntimeDaemonTickResult(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonOperationResult operationResult,
|
||||
AetheriaRuntimeDaemonFrameDocument frame,
|
||||
string framePath,
|
||||
string providerAdvertisementPath,
|
||||
string healthPath,
|
||||
string commandBoundaryPath,
|
||||
string gameSurfacePath,
|
||||
string gameTuiSurfacePath,
|
||||
string editorSurfacePath,
|
||||
string editorTuiSurfacePath)
|
||||
{
|
||||
Run = run ?? new AetheriaRuntimeRunCheckpointCommit();
|
||||
OperationResult = operationResult ?? new AetheriaRuntimeDaemonOperationResult(
|
||||
Run,
|
||||
Array.Empty<string>(),
|
||||
Array.Empty<string>());
|
||||
Frame = frame ?? new AetheriaRuntimeDaemonFrameDocument();
|
||||
FramePath = framePath ?? "";
|
||||
ProviderAdvertisementPath = providerAdvertisementPath ?? "";
|
||||
HealthPath = healthPath ?? "";
|
||||
CommandBoundaryPath = commandBoundaryPath ?? "";
|
||||
GameSurfacePath = gameSurfacePath ?? "";
|
||||
GameTuiSurfacePath = gameTuiSurfacePath ?? "";
|
||||
EditorSurfacePath = editorSurfacePath ?? "";
|
||||
EditorTuiSurfacePath = editorTuiSurfacePath ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeRunCheckpointCommit Run { get; }
|
||||
public AetheriaRuntimeDaemonOperationResult OperationResult { get; }
|
||||
public AetheriaRuntimeDaemonFrameDocument Frame { get; }
|
||||
public string FramePath { get; }
|
||||
public string ProviderAdvertisementPath { get; }
|
||||
public string HealthPath { get; }
|
||||
public string CommandBoundaryPath { get; }
|
||||
public string GameSurfacePath { get; }
|
||||
public string GameTuiSurfacePath { get; }
|
||||
public string EditorSurfacePath { get; }
|
||||
public string EditorTuiSurfacePath { get; }
|
||||
public AetheriaRuntimeDaemonIntentState Intents => OperationResult.Intents;
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeDaemonTickRunner
|
||||
{
|
||||
public static AetheriaRuntimeDaemonTickResult Tick(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonTickOptions options)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stateFilePath))
|
||||
throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath));
|
||||
|
||||
run ??= new AetheriaRuntimeRunCheckpointCommit();
|
||||
options ??= new AetheriaRuntimeDaemonTickOptions();
|
||||
options.OperationContext ??= new AetheriaRuntimeDaemonOperationContext();
|
||||
|
||||
var observedCommands = (options.ObservedCommands ?? Array.Empty<AetheriaRuntimeDaemonCommandDocument>())
|
||||
.Where(command => command != null)
|
||||
.ToArray();
|
||||
var accountedBeforeTick = new HashSet<string>(
|
||||
options.AccountedCommandIds ?? Array.Empty<string>(),
|
||||
StringComparer.Ordinal);
|
||||
var commands = observedCommands
|
||||
.Where(command => !string.IsNullOrWhiteSpace(command.CommandId))
|
||||
.Where(command => !accountedBeforeTick.Contains(command.CommandId))
|
||||
.ToArray();
|
||||
var operationResult = AetheriaRuntimeDaemonOperations.Execute(
|
||||
run,
|
||||
commands,
|
||||
options.OperationContext);
|
||||
|
||||
var frame = AetheriaRuntimeDaemonFrameDocument.Create(
|
||||
operationResult.Run,
|
||||
options.DaemonId,
|
||||
options.SessionId,
|
||||
options.FrameId,
|
||||
options.SimulationTimeSeconds,
|
||||
options.FixedDeltaSeconds);
|
||||
frame.AppliedCommandIds = operationResult.AppliedCommandIds;
|
||||
frame.RejectedCommandIds = operationResult.RejectedCommandIds;
|
||||
frame.AccountedCommandIds = accountedBeforeTick
|
||||
.Concat(operationResult.AppliedCommandIds)
|
||||
.Concat(operationResult.RejectedCommandIds)
|
||||
.Where(commandId => !string.IsNullOrWhiteSpace(commandId))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
frame.Capabilities = new[]
|
||||
{
|
||||
"aetheria.daemon.operation_execute.v1",
|
||||
"aetheria.daemon.intent_state.v1",
|
||||
"aetheria.daemon.authoritative_frame.v1",
|
||||
AetheriaRuntimeDaemonSchemas.ProviderAdvertisement,
|
||||
AetheriaRuntimeDaemonSchemas.Health,
|
||||
AetheriaRuntimeDaemonSchemas.CommandBoundary,
|
||||
AetheriaRuntimeDaemonSchemas.GameSurface,
|
||||
AetheriaRuntimeDaemonSchemas.EditorSurface
|
||||
};
|
||||
|
||||
var framePath = AetheriaRuntimeDaemonFrameStore.PublishFrame(stateFilePath, frame);
|
||||
var commandBoundary = AetheriaRuntimeDaemonCommandBoundaryDocument.Create(options.DaemonId);
|
||||
var commandBoundaryPath = AetheriaRuntimeDaemonPublicationStore.PublishCommandBoundary(
|
||||
stateFilePath,
|
||||
commandBoundary);
|
||||
var providerAdvertisement = AetheriaRuntimeDaemonProviderAdvertisementDocument.Create(
|
||||
stateFilePath,
|
||||
options.DaemonId,
|
||||
options.VerseId,
|
||||
options.CultMeshAddress);
|
||||
var providerAdvertisementPath = AetheriaRuntimeDaemonPublicationStore.PublishProviderAdvertisement(
|
||||
stateFilePath,
|
||||
providerAdvertisement);
|
||||
var healthPath = AetheriaRuntimeDaemonPublicationStore.PublishHealth(
|
||||
stateFilePath,
|
||||
new AetheriaRuntimeDaemonHealthDocument
|
||||
{
|
||||
DaemonId = string.IsNullOrWhiteSpace(options.DaemonId) ? "aetheria-daemon" : options.DaemonId,
|
||||
VerseId = string.IsNullOrWhiteSpace(options.VerseId) ? "aetheria.local" : options.VerseId,
|
||||
PublishedAtUtc = DateTime.UtcNow.ToString("O"),
|
||||
StatePath = stateFilePath,
|
||||
FrameId = frame.FrameId,
|
||||
ObservedCommandCount = observedCommands.Length,
|
||||
AppliedCommandCount = operationResult.AppliedCommandIds.Count,
|
||||
RejectedCommandCount = operationResult.RejectedCommandIds.Count,
|
||||
Status = operationResult.RejectedCommandIds.Count == 0 ? "healthy" : "commands-rejected",
|
||||
PublicationSource = "daemon-published",
|
||||
Transport = "cultcache-witness",
|
||||
CommandBoundaryPath = commandBoundaryPath
|
||||
});
|
||||
AetheriaRuntimeDaemonPublicationStore.TryReadHealth(stateFilePath, out var health);
|
||||
var gameSurface = AetheriaRuntimeDaemonGameSurfaceBuilder.Build(
|
||||
frame,
|
||||
health,
|
||||
commandBoundary);
|
||||
var gameSurfacePath = AetheriaRuntimeDaemonPublicationStore.PublishGameSurface(
|
||||
stateFilePath,
|
||||
gameSurface);
|
||||
var gameTuiSurfacePath = AetheriaRuntimeDaemonPublicationStore.PublishGameTuiSurface(
|
||||
stateFilePath,
|
||||
gameSurface);
|
||||
var editorSurface = AetheriaRuntimeDaemonEditorSurfaceBuilder.Build(
|
||||
providerAdvertisement,
|
||||
health,
|
||||
commandBoundary);
|
||||
var editorSurfacePath = AetheriaRuntimeDaemonPublicationStore.PublishEditorSurface(
|
||||
stateFilePath,
|
||||
editorSurface);
|
||||
var editorTuiSurfacePath = AetheriaRuntimeDaemonPublicationStore.PublishEditorTuiSurface(
|
||||
stateFilePath,
|
||||
editorSurface);
|
||||
return new AetheriaRuntimeDaemonTickResult(
|
||||
operationResult.Run,
|
||||
operationResult,
|
||||
frame,
|
||||
framePath,
|
||||
providerAdvertisementPath,
|
||||
healthPath,
|
||||
commandBoundaryPath,
|
||||
gameSurfacePath,
|
||||
gameTuiSurfacePath,
|
||||
editorSurfacePath,
|
||||
editorTuiSurfacePath);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,522 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeEquippedItemMetric
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemMetric(string id, string label, string value)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Value = value ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Value { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEquippedItemSection
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemSection(
|
||||
string id,
|
||||
string title,
|
||||
IReadOnlyList<AetheriaRuntimeEquippedItemMetric> metrics)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Title = title ?? "";
|
||||
Metrics = metrics ?? Array.Empty<AetheriaRuntimeEquippedItemMetric>();
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Title { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEquippedItemMetric> Metrics { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEquippedItemControl
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemControl(
|
||||
string id,
|
||||
string label,
|
||||
string command,
|
||||
IReadOnlyDictionary<string, string> payload)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Command = command ?? "";
|
||||
Payload = payload ?? EmptyPayload;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Command { get; }
|
||||
public IReadOnlyDictionary<string, string> Payload { get; }
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, string> EmptyPayload =
|
||||
new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEquippedItemTemperatureControl
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemTemperatureControl(
|
||||
string id,
|
||||
string label,
|
||||
string value,
|
||||
IReadOnlyDictionary<string, string> payload)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Value = value ?? "";
|
||||
Payload = payload ?? EmptyPayload;
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Value { get; }
|
||||
public IReadOnlyDictionary<string, string> Payload { get; }
|
||||
|
||||
private static readonly IReadOnlyDictionary<string, string> EmptyPayload =
|
||||
new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEquippedItemActionBarSlot
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemActionBarSlot(
|
||||
string id,
|
||||
string title,
|
||||
string currentBinding,
|
||||
IReadOnlyList<AetheriaRuntimeEquippedItemControl> controls)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Title = title ?? "";
|
||||
CurrentBinding = currentBinding ?? "";
|
||||
Controls = controls ?? Array.Empty<AetheriaRuntimeEquippedItemControl>();
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Title { get; }
|
||||
public string CurrentBinding { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEquippedItemControl> Controls { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeEquippedItemDetailsSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemDetailsSurfaceState(
|
||||
string itemName,
|
||||
string description,
|
||||
string manufacturer,
|
||||
string mass,
|
||||
string durability,
|
||||
string temperature,
|
||||
string thermalRange,
|
||||
string overrideShutdown,
|
||||
string overrideShutdownLabel,
|
||||
IReadOnlyList<AetheriaRuntimeEquippedItemTemperatureControl> temperatureControls,
|
||||
IReadOnlyList<AetheriaRuntimeEquippedItemSection> behaviorSections,
|
||||
IReadOnlyList<AetheriaRuntimeEquippedItemControl> weaponGroupControls,
|
||||
IReadOnlyList<AetheriaRuntimeEquippedItemActionBarSlot> actionBarSlots,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
ItemName = itemName ?? "";
|
||||
Description = description ?? "";
|
||||
Manufacturer = manufacturer ?? "";
|
||||
Mass = mass ?? "";
|
||||
Durability = durability ?? "";
|
||||
Temperature = temperature ?? "";
|
||||
ThermalRange = thermalRange ?? "";
|
||||
OverrideShutdown = overrideShutdown ?? "";
|
||||
OverrideShutdownLabel = overrideShutdownLabel ?? "";
|
||||
TemperatureControls = temperatureControls ?? Array.Empty<AetheriaRuntimeEquippedItemTemperatureControl>();
|
||||
BehaviorSections = behaviorSections ?? Array.Empty<AetheriaRuntimeEquippedItemSection>();
|
||||
WeaponGroupControls = weaponGroupControls ?? Array.Empty<AetheriaRuntimeEquippedItemControl>();
|
||||
ActionBarSlots = actionBarSlots ?? Array.Empty<AetheriaRuntimeEquippedItemActionBarSlot>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string ItemName { get; }
|
||||
public string Description { get; }
|
||||
public string Manufacturer { get; }
|
||||
public string Mass { get; }
|
||||
public string Durability { get; }
|
||||
public string Temperature { get; }
|
||||
public string ThermalRange { get; }
|
||||
public string OverrideShutdown { get; }
|
||||
public string OverrideShutdownLabel { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEquippedItemTemperatureControl> TemperatureControls { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEquippedItemSection> BehaviorSections { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEquippedItemControl> WeaponGroupControls { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeEquippedItemActionBarSlot> ActionBarSlots { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
public bool HasWeaponControls => WeaponGroupControls.Count > 0;
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeEquippedItemDetailsSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.inventory.equipped_item_details";
|
||||
public const string Close = "aetheria.inventory.equipped_item_details.close";
|
||||
public const string ToggleOverrideShutdown = "aetheria.inventory.equipped_item_details.override_shutdown.toggle";
|
||||
public const string SetTargetTemperature = "aetheria.inventory.equipped_item_details.target_temperature.set";
|
||||
public const string ToggleWeaponGroup = "aetheria.inventory.equipped_item_details.weapon_group.toggle";
|
||||
public const string BindWeaponGroup = "aetheria.inventory.equipped_item_details.weapon_group.bind";
|
||||
public const string ClearActionBarBinding = "aetheria.inventory.equipped_item_details.action_bar.clear";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeEquippedItemDetailsSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeEquippedItemDetailsSurfaceState(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeEquippedItemTemperatureControl>(),
|
||||
Array.Empty<AetheriaRuntimeEquippedItemSection>(),
|
||||
Array.Empty<AetheriaRuntimeEquippedItemControl>(),
|
||||
Array.Empty<AetheriaRuntimeEquippedItemActionBarSlot>(),
|
||||
"");
|
||||
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{SurfaceId}.summary",
|
||||
state.ItemName,
|
||||
Text(
|
||||
$"{SurfaceId}.description",
|
||||
string.IsNullOrWhiteSpace(state.Description)
|
||||
? "No typed item description is available."
|
||||
: state.Description),
|
||||
Text(
|
||||
$"{SurfaceId}.note",
|
||||
"Unity projects the selected equipment; the shared runtime surface owns equipped-item inspection layout and commands."),
|
||||
Metric($"{SurfaceId}.manufacturer", "Manufacturer", state.Manufacturer),
|
||||
Metric($"{SurfaceId}.mass", "Mass", state.Mass)),
|
||||
Card(
|
||||
$"{SurfaceId}.status.card",
|
||||
"Status",
|
||||
Metric($"{SurfaceId}.durability", "Durability", state.Durability),
|
||||
Metric($"{SurfaceId}.temperature", "Temperature", state.Temperature),
|
||||
Metric($"{SurfaceId}.thermal_range", "Thermal Range", state.ThermalRange))
|
||||
};
|
||||
|
||||
foreach (var section in state.BehaviorSections)
|
||||
{
|
||||
if (section?.Metrics == null || section.Metrics.Count == 0)
|
||||
continue;
|
||||
|
||||
children.Add(Card(
|
||||
string.IsNullOrWhiteSpace(section.Id)
|
||||
? $"{SurfaceId}.behavior.{SafeId(section.Title)}"
|
||||
: section.Id,
|
||||
section.Title,
|
||||
section.Metrics
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
children.Add(BuildControlsCard(state));
|
||||
|
||||
if (state.HasWeaponControls)
|
||||
{
|
||||
children.Add(Card(
|
||||
$"{SurfaceId}.weapon_groups.card",
|
||||
"Weapon Groups",
|
||||
Text(
|
||||
$"{SurfaceId}.weapon_groups.note",
|
||||
"Toggle membership directly; action-bar group binding is handled below."),
|
||||
ButtonRow(
|
||||
$"{SurfaceId}.weapon_groups.actions",
|
||||
state.WeaponGroupControls.Select(Button).ToArray())));
|
||||
|
||||
children.AddRange(state.ActionBarSlots.Select(BuildActionBarCard));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{SurfaceId}.actions",
|
||||
Button($"{SurfaceId}.close", "Close", Close)));
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "inventory.menu",
|
||||
title: "Inventory Equipped Item Details",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(ToggleOverrideShutdown, "Toggle Override Shutdown", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(SetTargetTemperature, "Set Target Temperature", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(ToggleWeaponGroup, "Toggle Weapon Group", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(BindWeaponGroup, "Bind Weapon Group", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(ClearActionBarBinding, "Clear Action Bar Binding", "unity-uitoolkit")
|
||||
});
|
||||
}
|
||||
|
||||
public static IReadOnlyDictionary<string, string> Payload(params (string Key, string Value)[] values)
|
||||
{
|
||||
return (values ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(value => value.Key ?? "", value => value.Value ?? "", StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildControlsCard(
|
||||
AetheriaRuntimeEquippedItemDetailsSurfaceState state)
|
||||
{
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Metric(
|
||||
$"{SurfaceId}.controls.override_shutdown.metric",
|
||||
"Override Shutdown",
|
||||
state.OverrideShutdown),
|
||||
ButtonRow(
|
||||
$"{SurfaceId}.controls.override_shutdown.actions",
|
||||
Button(
|
||||
$"{SurfaceId}.controls.override_shutdown.toggle",
|
||||
string.IsNullOrWhiteSpace(state.OverrideShutdownLabel)
|
||||
? "Toggle Override"
|
||||
: state.OverrideShutdownLabel,
|
||||
ToggleOverrideShutdown))
|
||||
};
|
||||
|
||||
children.AddRange(state.TemperatureControls.Select(control => Metric(
|
||||
$"{control.Id}.metric",
|
||||
control.Label,
|
||||
control.Value)));
|
||||
children.AddRange(state.TemperatureControls.Select(control => TextField(
|
||||
control.Id,
|
||||
control.Label,
|
||||
SetTargetTemperature,
|
||||
control.Value,
|
||||
control.Payload)));
|
||||
|
||||
return Card($"{SurfaceId}.controls.card", "Controls", children.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildActionBarCard(
|
||||
AetheriaRuntimeEquippedItemActionBarSlot slot)
|
||||
{
|
||||
return Card(
|
||||
slot.Id,
|
||||
slot.Title,
|
||||
Metric($"{slot.Id}.binding", "Current", slot.CurrentBinding),
|
||||
ButtonRow($"{slot.Id}.actions", slot.Controls.Select(Button).ToArray()));
|
||||
}
|
||||
|
||||
private static string SafeId(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
return new string(value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? char.ToLowerInvariant(character) : '-')
|
||||
.ToArray()).Trim('-');
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(AetheriaRuntimeEquippedItemControl control)
|
||||
{
|
||||
return CommandButton(control.Id, control.Label, control.Command, control.Payload);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent CommandButton(
|
||||
string id,
|
||||
string label,
|
||||
string command,
|
||||
IReadOnlyDictionary<string, string> payload)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("command", command ?? "")
|
||||
};
|
||||
|
||||
if (payload != null)
|
||||
{
|
||||
props.AddRange(payload.Select(entry => (entry.Key, entry.Value)));
|
||||
}
|
||||
|
||||
return Node(id, "control.button", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent TextField(
|
||||
string id,
|
||||
string label,
|
||||
string command,
|
||||
string value,
|
||||
IReadOnlyDictionary<string, string> payload)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("command", command ?? ""),
|
||||
("value", value ?? "")
|
||||
};
|
||||
|
||||
if (payload != null)
|
||||
{
|
||||
props.AddRange(payload.Select(entry => (entry.Key, entry.Value)));
|
||||
}
|
||||
|
||||
return Node(id, "control.text", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeEquippedItemDetailsCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1,
|
||||
ToggleOverrideShutdown = 2,
|
||||
SetTargetTemperature = 3,
|
||||
ToggleWeaponGroup = 4,
|
||||
BindWeaponGroup = 5,
|
||||
ClearActionBarBinding = 6
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeEquippedItemDetailsCommand
|
||||
{
|
||||
public AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind kind,
|
||||
int behaviorIndex = -1,
|
||||
float targetTemperature = 0f,
|
||||
int groupIndex = -1,
|
||||
int slotIndex = -1)
|
||||
{
|
||||
Kind = kind;
|
||||
BehaviorIndex = behaviorIndex;
|
||||
TargetTemperature = targetTemperature;
|
||||
GroupIndex = groupIndex;
|
||||
SlotIndex = slotIndex;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeEquippedItemDetailsCommandKind Kind { get; }
|
||||
public int BehaviorIndex { get; }
|
||||
public float TargetTemperature { get; }
|
||||
public int GroupIndex { get; }
|
||||
public int SlotIndex { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeEquippedItemDetailsSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeEquippedItemDetailsCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
switch (request.Command ?? "")
|
||||
{
|
||||
case AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.Close:
|
||||
command = new AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind.Close);
|
||||
return true;
|
||||
case AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.ToggleOverrideShutdown:
|
||||
command = new AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind.ToggleOverrideShutdown);
|
||||
return true;
|
||||
case AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.SetTargetTemperature:
|
||||
command = new AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind.SetTargetTemperature,
|
||||
behaviorIndex: ReadInt(request, "behaviorIndex", -1),
|
||||
targetTemperature: ReadFloat(request, "value", 0f));
|
||||
return true;
|
||||
case AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.ToggleWeaponGroup:
|
||||
command = new AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind.ToggleWeaponGroup,
|
||||
groupIndex: ReadInt(request, "group", -1));
|
||||
return true;
|
||||
case AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.BindWeaponGroup:
|
||||
command = new AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind.BindWeaponGroup,
|
||||
groupIndex: ReadInt(request, "group", -1),
|
||||
slotIndex: ReadInt(request, "slot", -1));
|
||||
return true;
|
||||
case AetheriaRuntimeEquippedItemDetailsSurfaceBuilder.ClearActionBarBinding:
|
||||
command = new AetheriaRuntimeEquippedItemDetailsCommand(
|
||||
AetheriaRuntimeEquippedItemDetailsCommandKind.ClearActionBarBinding,
|
||||
slotIndex: ReadInt(request, "slot", -1));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static int ReadInt(EveSurfaceCommandRequest request, string key, int defaultValue)
|
||||
{
|
||||
return request.Payload != null &&
|
||||
request.Payload.TryGetValue(key, out var raw) &&
|
||||
int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value)
|
||||
? value
|
||||
: defaultValue;
|
||||
}
|
||||
|
||||
private static float ReadFloat(EveSurfaceCommandRequest request, string key, float defaultValue)
|
||||
{
|
||||
return request.Payload != null &&
|
||||
request.Payload.TryGetValue(key, out var raw) &&
|
||||
float.TryParse(raw, NumberStyles.Float | NumberStyles.AllowThousands, CultureInfo.InvariantCulture, out var value)
|
||||
? value
|
||||
: defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,433 @@
|
|||
using System;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeEveCommands
|
||||
{
|
||||
public static bool TryCreateKnownSurfaceCommand(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.TryCreateKnownSurfaceCommand(request, out envelope);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitPlayerSettingsCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
AetheriaRuntimePlayerSettingsCommandBody body,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreatePlayerSettingsCommand(command, body, clientId);
|
||||
}
|
||||
|
||||
public static bool TrySendPlayerSettingsCommand(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request,
|
||||
string clientId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
return TrySend(
|
||||
stateFilePath,
|
||||
AetheriaRuntimeEveCommandClient.CreatePlayerSettingsCommand(request, clientId),
|
||||
clientId,
|
||||
out envelope,
|
||||
out error);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitPlayerSettingsCommand(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreatePlayerSettingsCommand(request, request?.ClientId ?? "");
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitPlayerSettingsCommand(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreatePlayerSettingsCommand(request, clientId);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitInputSettingsCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
AetheriaRuntimeInputSettingsCommandBody body,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreateInputSettingsCommand(command, body, clientId);
|
||||
}
|
||||
|
||||
public static bool TrySendInputSettingsCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
AetheriaRuntimeInputSettingsCommandBody body,
|
||||
string clientId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
return TrySend(
|
||||
stateFilePath,
|
||||
AetheriaRuntimeEveCommandClient.CreateInputSettingsCommand(command, body, clientId),
|
||||
clientId,
|
||||
out envelope,
|
||||
out error);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitCatalogCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreateCatalogCommand(command, clientId);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitOperationsCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreateOperationsCommand(command, clientId);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitVerseHostCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreateVerseHostCommand(command, clientId);
|
||||
}
|
||||
|
||||
public static bool TrySendVerseHostCommand(
|
||||
string stateFilePath,
|
||||
string command,
|
||||
string clientId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
return TrySend(
|
||||
stateFilePath,
|
||||
AetheriaRuntimeEveCommandClient.CreateVerseHostCommand(command, clientId),
|
||||
clientId,
|
||||
out envelope,
|
||||
out error);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope SubmitLoadoutTemplateCommand(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeLoadoutTemplateCommit loadoutTemplate,
|
||||
string clientId)
|
||||
{
|
||||
return AetheriaRuntimeEveCommandClient.CreateLoadoutTemplateCommand(loadoutTemplate, clientId);
|
||||
}
|
||||
|
||||
public static bool TrySendLoadoutTemplateCommand(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeLoadoutTemplateCommit loadoutTemplate,
|
||||
string clientId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
return TrySend(
|
||||
stateFilePath,
|
||||
AetheriaRuntimeEveCommandClient.CreateLoadoutTemplateCommand(loadoutTemplate, clientId),
|
||||
clientId,
|
||||
out envelope,
|
||||
out error);
|
||||
}
|
||||
|
||||
public static bool TrySendKnownSurfaceCommand(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request,
|
||||
string clientId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
if (!AetheriaRuntimeEveCommandClient.TryCreateKnownSurfaceCommand(request, out var commandEnvelope))
|
||||
{
|
||||
envelope = null;
|
||||
error = $"Unknown Aetheria Eve surface command: {request?.ProviderId}/{request?.SurfaceId}/{request?.Command}";
|
||||
return false;
|
||||
}
|
||||
|
||||
return TrySend(
|
||||
stateFilePath,
|
||||
commandEnvelope!,
|
||||
clientId,
|
||||
out envelope,
|
||||
out error);
|
||||
}
|
||||
|
||||
private static bool TrySend(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeEveCommandEnvelope commandEnvelope,
|
||||
string clientId,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
return AetheriaRuntimeCommandSubmitter.TrySubmitEveCommand(
|
||||
stateFilePath,
|
||||
AetheriaRuntimeEveCommandClient.ToDocument(commandEnvelope),
|
||||
string.IsNullOrWhiteSpace(clientId) ? "aetheria-eve-client" : clientId,
|
||||
out envelope,
|
||||
out error);
|
||||
}
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeEveCommandClient
|
||||
{
|
||||
public const string CommandSchema = AetheriaRuntimeEveCommandDocument.SchemaId;
|
||||
|
||||
public static bool TryCreateKnownSurfaceCommand(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeEveCommandEnvelope? envelope)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
var command = request.Command ?? "";
|
||||
var clientId = request.ClientId ?? "";
|
||||
switch (request.SurfaceId ?? "")
|
||||
{
|
||||
case AetheriaRuntimePlayerSettingsCommands.SurfaceId
|
||||
when AetheriaRuntimePlayerSettingsCommands.IsKnown(command):
|
||||
envelope = CreatePlayerSettingsCommand(request, clientId);
|
||||
return true;
|
||||
case AetheriaRuntimeInputSettingsCommands.SurfaceId
|
||||
when AetheriaRuntimeInputSettingsCommands.IsKnown(command):
|
||||
envelope = CreateInputSettingsCommand(request, clientId);
|
||||
return true;
|
||||
case AetheriaRuntimeCatalogCommands.SurfaceId
|
||||
when AetheriaRuntimeCatalogCommands.IsKnown(command):
|
||||
envelope = CreateCatalogCommand(command, clientId);
|
||||
return true;
|
||||
case AetheriaRuntimeOperationsCommands.SurfaceId
|
||||
when AetheriaRuntimeOperationsCommands.IsKnown(command):
|
||||
envelope = CreateOperationsCommand(command, clientId);
|
||||
return true;
|
||||
case AetheriaRuntimeVerseHostCommands.SurfaceId
|
||||
when AetheriaRuntimeVerseHostCommands.IsKnown(command):
|
||||
envelope = CreateVerseHostCommand(command, clientId);
|
||||
return true;
|
||||
}
|
||||
|
||||
envelope = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreatePlayerSettingsCommand(
|
||||
string command,
|
||||
AetheriaRuntimePlayerSettingsCommandBody body,
|
||||
string clientId)
|
||||
{
|
||||
return CreateTypedCommand(
|
||||
AetheriaRuntimePlayerSettingsCommands.SurfaceId,
|
||||
command,
|
||||
clientId,
|
||||
playerSettings: body ?? new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
inputSettings: new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
loadoutTemplate: null);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreatePlayerSettingsCommand(
|
||||
EveSurfaceCommandRequest request)
|
||||
{
|
||||
return CreatePlayerSettingsCommand(request, request?.ClientId ?? "");
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreatePlayerSettingsCommand(
|
||||
EveSurfaceCommandRequest request,
|
||||
string clientId)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
return CreatePlayerSettingsCommand(
|
||||
request.Command ?? "",
|
||||
ReadPlayerSettingsBody(request),
|
||||
string.IsNullOrWhiteSpace(clientId) ? request.ClientId ?? "" : clientId);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreateInputSettingsCommand(
|
||||
string command,
|
||||
AetheriaRuntimeInputSettingsCommandBody body,
|
||||
string clientId)
|
||||
{
|
||||
return CreateTypedCommand(
|
||||
AetheriaRuntimeInputSettingsCommands.SurfaceId,
|
||||
command,
|
||||
clientId,
|
||||
playerSettings: new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
inputSettings: body ?? new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
loadoutTemplate: null);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreateInputSettingsCommand(
|
||||
EveSurfaceCommandRequest request,
|
||||
string clientId)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
return CreateInputSettingsCommand(
|
||||
request.Command ?? "",
|
||||
ReadInputSettingsBody(request),
|
||||
string.IsNullOrWhiteSpace(clientId) ? request.ClientId ?? "" : clientId);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreateCatalogCommand(
|
||||
string command,
|
||||
string clientId)
|
||||
{
|
||||
return CreateTypedCommand(
|
||||
AetheriaRuntimeCatalogCommands.SurfaceId,
|
||||
command,
|
||||
clientId,
|
||||
playerSettings: new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
inputSettings: new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
loadoutTemplate: null);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreateOperationsCommand(
|
||||
string command,
|
||||
string clientId)
|
||||
{
|
||||
return CreateTypedCommand(
|
||||
AetheriaRuntimeOperationsCommands.SurfaceId,
|
||||
command,
|
||||
clientId,
|
||||
playerSettings: new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
inputSettings: new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
loadoutTemplate: null);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreateVerseHostCommand(
|
||||
string command,
|
||||
string clientId)
|
||||
{
|
||||
return CreateTypedCommand(
|
||||
AetheriaRuntimeVerseHostCommands.SurfaceId,
|
||||
command,
|
||||
clientId,
|
||||
playerSettings: new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
inputSettings: new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
loadoutTemplate: null);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope CreateLoadoutTemplateCommand(
|
||||
AetheriaRuntimeLoadoutTemplateCommit loadoutTemplate,
|
||||
string clientId)
|
||||
{
|
||||
return CreateTypedCommand(
|
||||
AetheriaRuntimeLoadoutTemplateCommands.SurfaceId,
|
||||
AetheriaRuntimeLoadoutTemplateCommands.Save,
|
||||
clientId,
|
||||
playerSettings: new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
inputSettings: new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
loadoutTemplate: loadoutTemplate);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandDocument ToDocument(AetheriaRuntimeEveCommandEnvelope envelope)
|
||||
{
|
||||
if (envelope == null) throw new ArgumentNullException(nameof(envelope));
|
||||
|
||||
return new AetheriaRuntimeEveCommandDocument
|
||||
{
|
||||
Schema = string.IsNullOrWhiteSpace(envelope.Schema) ? CommandSchema : envelope.Schema,
|
||||
CommandId = envelope.CommandId ?? "",
|
||||
ProviderId = envelope.ProviderId ?? "",
|
||||
SurfaceId = envelope.SurfaceId ?? "",
|
||||
Command = envelope.Command ?? "",
|
||||
IssuedAtUtc = envelope.IssuedAtUtc ?? "",
|
||||
ClientId = envelope.ClientId ?? "",
|
||||
PlayerSettings = envelope.PlayerSettings ?? new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
InputSettings = envelope.InputSettings ?? new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
LoadoutTemplate = envelope.LoadoutTemplate
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEveCommandEnvelope CreateTypedCommand(
|
||||
string surfaceId,
|
||||
string command,
|
||||
string clientId,
|
||||
AetheriaRuntimePlayerSettingsCommandBody playerSettings,
|
||||
AetheriaRuntimeInputSettingsCommandBody inputSettings,
|
||||
AetheriaRuntimeLoadoutTemplateCommit? loadoutTemplate)
|
||||
{
|
||||
var commandId = Guid.NewGuid().ToString("N");
|
||||
var issuedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
var document = new AetheriaRuntimeEveCommandDocument
|
||||
{
|
||||
Schema = CommandSchema,
|
||||
CommandId = commandId,
|
||||
ProviderId = "aetheria",
|
||||
SurfaceId = surfaceId ?? "",
|
||||
Command = command ?? "",
|
||||
IssuedAtUtc = issuedAtUtc,
|
||||
ClientId = clientId ?? "",
|
||||
PlayerSettings = playerSettings,
|
||||
InputSettings = inputSettings,
|
||||
LoadoutTemplate = loadoutTemplate
|
||||
};
|
||||
|
||||
return ToEnvelope(document);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope ToEnvelope(AetheriaRuntimeEveCommandDocument document)
|
||||
{
|
||||
return new AetheriaRuntimeEveCommandEnvelope(
|
||||
document.Schema ?? "",
|
||||
document.CommandId ?? "",
|
||||
document.ProviderId ?? "",
|
||||
document.SurfaceId ?? "",
|
||||
document.Command ?? "",
|
||||
document.IssuedAtUtc ?? "",
|
||||
document.ClientId ?? "",
|
||||
document.PlayerSettings ?? new AetheriaRuntimePlayerSettingsCommandBody(),
|
||||
document.InputSettings ?? new AetheriaRuntimeInputSettingsCommandBody(),
|
||||
"",
|
||||
document.LoadoutTemplate);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimePlayerSettingsCommandBody ReadPlayerSettingsBody(EveSurfaceCommandRequest request)
|
||||
{
|
||||
if (!string.Equals(request.SurfaceId, AetheriaRuntimePlayerSettingsCommands.SurfaceId, StringComparison.Ordinal))
|
||||
return new AetheriaRuntimePlayerSettingsCommandBody();
|
||||
|
||||
return new AetheriaRuntimePlayerSettingsCommandBody
|
||||
{
|
||||
PlayerName = ReadPayload(request, "value")
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeInputSettingsCommandBody ReadInputSettingsBody(EveSurfaceCommandRequest request)
|
||||
{
|
||||
if (!string.Equals(request.SurfaceId, AetheriaRuntimeInputSettingsCommands.SurfaceId, StringComparison.Ordinal))
|
||||
return new AetheriaRuntimeInputSettingsCommandBody();
|
||||
|
||||
return new AetheriaRuntimeInputSettingsCommandBody
|
||||
{
|
||||
ActionName = ReadPayload(request, "actionName"),
|
||||
BindingIndex = ReadPayloadInt(request, "bindingIndex", -1),
|
||||
InputSystemPath = ReadPayload(request, "inputSystemPath"),
|
||||
Enabled = string.Equals(ReadPayload(request, "enabled"), "true", StringComparison.OrdinalIgnoreCase)
|
||||
};
|
||||
}
|
||||
|
||||
private static string ReadPayload(EveSurfaceCommandRequest request, string key)
|
||||
{
|
||||
return request.Payload != null && request.Payload.TryGetValue(key, out var value)
|
||||
? value ?? ""
|
||||
: "";
|
||||
}
|
||||
|
||||
private static int ReadPayloadInt(EveSurfaceCommandRequest request, string key, int defaultValue)
|
||||
{
|
||||
return int.TryParse(ReadPayload(request, key), out var value)
|
||||
? value
|
||||
: defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4b9f4bb18b4c4f348b3ed44f0b797275
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GameCult.Caching;
|
||||
using MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
|
@ -16,8 +16,10 @@ namespace GameCult.Aetheria.State.Unity
|
|||
string command,
|
||||
string issuedAtUtc,
|
||||
string clientId,
|
||||
IReadOnlyDictionary<string, string> payload,
|
||||
string path)
|
||||
AetheriaRuntimePlayerSettingsCommandBody playerSettings,
|
||||
AetheriaRuntimeInputSettingsCommandBody inputSettings,
|
||||
string path,
|
||||
AetheriaRuntimeLoadoutTemplateCommit? loadoutTemplate = null)
|
||||
{
|
||||
Schema = schema;
|
||||
CommandId = commandId;
|
||||
|
|
@ -26,8 +28,10 @@ namespace GameCult.Aetheria.State.Unity
|
|||
Command = command;
|
||||
IssuedAtUtc = issuedAtUtc;
|
||||
ClientId = clientId;
|
||||
Payload = payload;
|
||||
PlayerSettings = playerSettings ?? new AetheriaRuntimePlayerSettingsCommandBody();
|
||||
InputSettings = inputSettings ?? new AetheriaRuntimeInputSettingsCommandBody();
|
||||
Path = path;
|
||||
LoadoutTemplate = loadoutTemplate;
|
||||
}
|
||||
|
||||
public string Schema { get; }
|
||||
|
|
@ -37,10 +41,13 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public string Command { get; }
|
||||
public string IssuedAtUtc { get; }
|
||||
public string ClientId { get; }
|
||||
public IReadOnlyDictionary<string, string> Payload { get; }
|
||||
public AetheriaRuntimePlayerSettingsCommandBody PlayerSettings { get; }
|
||||
public AetheriaRuntimeInputSettingsCommandBody InputSettings { get; }
|
||||
public AetheriaRuntimeLoadoutTemplateCommit? LoadoutTemplate { get; }
|
||||
public string Path { get; }
|
||||
}
|
||||
|
||||
[CultDocument("gamecult.eve.command", "gamecult.eve.command.v1")]
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeEveCommandDocument
|
||||
{
|
||||
|
|
@ -68,6 +75,35 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public string ClientId { get; set; } = "";
|
||||
|
||||
[Key(7)]
|
||||
public Dictionary<string, string> Payload { get; set; } = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
public AetheriaRuntimePlayerSettingsCommandBody PlayerSettings { get; set; } = new AetheriaRuntimePlayerSettingsCommandBody();
|
||||
|
||||
[Key(8)]
|
||||
public AetheriaRuntimeLoadoutTemplateCommit? LoadoutTemplate { get; set; }
|
||||
|
||||
[Key(9)]
|
||||
public AetheriaRuntimeInputSettingsCommandBody InputSettings { get; set; } = new AetheriaRuntimeInputSettingsCommandBody();
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimePlayerSettingsCommandBody
|
||||
{
|
||||
[Key(0)]
|
||||
public string PlayerName { get; set; } = "";
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeInputSettingsCommandBody
|
||||
{
|
||||
[Key(0)]
|
||||
public string ActionName { get; set; } = "";
|
||||
|
||||
[Key(1)]
|
||||
public int BindingIndex { get; set; } = -1;
|
||||
|
||||
[Key(2)]
|
||||
public string InputSystemPath { get; set; } = "";
|
||||
|
||||
[Key(3)]
|
||||
public bool Enabled { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1a2cc3083bb1d0b4299e0175dd9e4b8e
|
||||
|
|
@ -1,129 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeEveCommandLog
|
||||
{
|
||||
public const string CommandSchema = AetheriaRuntimeEveCommandDocument.SchemaId;
|
||||
|
||||
public static string GetPendingDirectory(string stateFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stateFilePath))
|
||||
throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath));
|
||||
|
||||
return stateFilePath + ".eve.pending";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandEnvelope QueueCommand(
|
||||
string stateFilePath,
|
||||
EveSurfaceCommandRequest request)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
var commandId = Guid.NewGuid().ToString("N");
|
||||
var issuedAtUtc = request.IssuedAt.UtcDateTime.ToString("O");
|
||||
var pendingDirectory = GetPendingDirectory(stateFilePath);
|
||||
Directory.CreateDirectory(pendingDirectory);
|
||||
|
||||
var finalPath = Path.Combine(
|
||||
pendingDirectory,
|
||||
$"{issuedAtUtc.Replace(':', '-')}.{StableToken(request.SurfaceId)}.{StableToken(request.Command)}.{commandId}.cc");
|
||||
var document = new AetheriaRuntimeEveCommandDocument
|
||||
{
|
||||
Schema = CommandSchema,
|
||||
CommandId = commandId,
|
||||
ProviderId = request.ProviderId ?? "",
|
||||
SurfaceId = request.SurfaceId ?? "",
|
||||
Command = request.Command ?? "",
|
||||
IssuedAtUtc = issuedAtUtc,
|
||||
ClientId = request.ClientId ?? "",
|
||||
Payload = CopyPayload(request.Payload)
|
||||
};
|
||||
|
||||
AetheriaRuntimePendingCultCacheStore.WriteEveCommand(finalPath, document);
|
||||
|
||||
return new AetheriaRuntimeEveCommandEnvelope(
|
||||
document.Schema,
|
||||
document.CommandId,
|
||||
document.ProviderId,
|
||||
document.SurfaceId,
|
||||
document.Command,
|
||||
document.IssuedAtUtc,
|
||||
document.ClientId,
|
||||
document.Payload,
|
||||
finalPath);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<AetheriaRuntimeEveCommandEnvelope> ReadPending(string stateFilePath)
|
||||
{
|
||||
var pendingDirectory = GetPendingDirectory(stateFilePath);
|
||||
if (!Directory.Exists(pendingDirectory))
|
||||
return Array.Empty<AetheriaRuntimeEveCommandEnvelope>();
|
||||
|
||||
return Directory
|
||||
.EnumerateFiles(pendingDirectory, "*.cc")
|
||||
.OrderBy(path => path, StringComparer.Ordinal)
|
||||
.Select(ReadEnvelope)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandDocument ReadDocument(string path)
|
||||
{
|
||||
return AetheriaRuntimePendingCultCacheStore.ReadEveCommand(path);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeEveCommandEnvelope ReadEnvelope(string path)
|
||||
{
|
||||
var document = ReadDocument(path);
|
||||
|
||||
return new AetheriaRuntimeEveCommandEnvelope(
|
||||
document.Schema ?? "",
|
||||
document.CommandId ?? "",
|
||||
document.ProviderId ?? "",
|
||||
document.SurfaceId ?? "",
|
||||
document.Command ?? "",
|
||||
document.IssuedAtUtc ?? "",
|
||||
document.ClientId ?? "",
|
||||
document.Payload ?? EmptyPayload(),
|
||||
path);
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> CopyPayload(IReadOnlyDictionary<string, string>? payload)
|
||||
{
|
||||
var copy = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var entry in (payload ?? EmptyPayload()).OrderBy(entry => entry.Key, StringComparer.Ordinal))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(entry.Key))
|
||||
copy[entry.Key] = entry.Value ?? "";
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> EmptyPayload()
|
||||
{
|
||||
return new Dictionary<string, string>(0, StringComparer.Ordinal);
|
||||
}
|
||||
|
||||
private static string StableToken(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
var chars = value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? character : '-')
|
||||
.ToArray();
|
||||
var token = new string(chars).Trim('-').ToLowerInvariant();
|
||||
while (token.Contains("--", StringComparison.Ordinal))
|
||||
token = token.Replace("--", "-", StringComparison.Ordinal);
|
||||
return string.IsNullOrWhiteSpace(token) ? "empty" : token;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e066eaa98317c243847ce778a1a5305
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeEveSurfaceAdapter
|
||||
{
|
||||
public static EveSurfaceDocument ToEveSurfaceDocument(AetheriaRuntimeSurfaceDocument document)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
return new EveSurfaceDocument(
|
||||
"surface-state",
|
||||
"gamecult.eve.surface.v1",
|
||||
document.ProviderId,
|
||||
document.ProviderKind,
|
||||
document.Title,
|
||||
document.Version,
|
||||
document.UpdatedAtUtc,
|
||||
new EveSurfaceTree(
|
||||
document.Surface.Id,
|
||||
ToEveSurfaceComponent(document.Surface.Root),
|
||||
document.Surface.Styles
|
||||
.Select(style => new EveStyleToken(style.Name, style.Value))
|
||||
.ToArray()),
|
||||
document.Commands
|
||||
.Select(command => new EveCommandTemplate(command.Command, command.Label, command.Transport))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
public static EveSurfaceDocument EmptySurface(string surfaceId)
|
||||
{
|
||||
var id = string.IsNullOrWhiteSpace(surfaceId) ? "aetheria.surface.missing" : surfaceId;
|
||||
return new EveSurfaceDocument(
|
||||
"surface-state",
|
||||
"gamecult.eve.surface.v1",
|
||||
"aetheria.daemon",
|
||||
"daemon",
|
||||
"",
|
||||
0,
|
||||
"",
|
||||
new EveSurfaceTree(
|
||||
id,
|
||||
new EveSurfaceComponent(
|
||||
id + ".missing",
|
||||
"surface",
|
||||
new Dictionary<string, string>(StringComparer.Ordinal),
|
||||
Array.Empty<EveSurfaceComponent>()),
|
||||
Array.Empty<EveStyleToken>()),
|
||||
Array.Empty<EveCommandTemplate>());
|
||||
}
|
||||
|
||||
private static EveSurfaceComponent ToEveSurfaceComponent(AetheriaRuntimeSurfaceComponent component)
|
||||
{
|
||||
return new EveSurfaceComponent(
|
||||
component.Id,
|
||||
component.Kind,
|
||||
new Dictionary<string, string>(component.Props, StringComparer.Ordinal),
|
||||
component.Children.Select(ToEveSurfaceComponent).ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,14 +6,18 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public const string Refresh = "aetheria.input_settings.refresh";
|
||||
public const string BeginCapture = "aetheria.input_settings.binding.capture";
|
||||
public const string CancelCapture = "aetheria.input_settings.binding.cancel";
|
||||
public const string SetBindingOverride = "aetheria.input_settings.binding.override";
|
||||
public const string ToggleActionBar = "aetheria.input_settings.action_bar.toggle";
|
||||
public const string SetActionBarEnabled = "aetheria.input_settings.action_bar.set_enabled";
|
||||
|
||||
public static bool IsKnown(string command)
|
||||
{
|
||||
return command == Refresh ||
|
||||
command == BeginCapture ||
|
||||
command == CancelCapture ||
|
||||
command == ToggleActionBar;
|
||||
command == SetBindingOverride ||
|
||||
command == ToggleActionBar ||
|
||||
command == SetActionBarEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f3ca8e46e25c53b44a8309d50f1eb429
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
|
|
@ -109,7 +111,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
settings.ActionBarInputs.Count(entry => entry.Enabled).ToString()),
|
||||
Text(
|
||||
"aetheria.inputSettings.summary.note",
|
||||
"Low-level InputSystem edits flow through this Eve surface and queue typed player-settings commits.")),
|
||||
"Low-level InputSystem edits flow through this Eve surface as typed input-setting requests.")),
|
||||
Node(
|
||||
"aetheria.inputSettings.capture",
|
||||
"card",
|
||||
|
|
@ -147,7 +149,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
"aetheria.inputSettings.actionBarInputs.grid",
|
||||
"grid",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
settings.ActionBarInputs.Select(BuildActionBarCard).ToArray())),
|
||||
settings.ActionBarInputs.Select(BuildActionBarCard).ToArray()))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
|
|
@ -259,4 +261,106 @@ namespace GameCult.Aetheria.State.Unity
|
|||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeInputSettingsCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Refresh = 1,
|
||||
BeginCapture = 2,
|
||||
CancelCapture = 3,
|
||||
ToggleActionBar = 4
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeInputSettingsSurfaceCommand
|
||||
{
|
||||
public AetheriaRuntimeInputSettingsSurfaceCommand(
|
||||
AetheriaRuntimeInputSettingsCommandKind kind,
|
||||
string actionName = "",
|
||||
int bindingIndex = -1,
|
||||
string bindingLabel = "",
|
||||
string inputPath = "",
|
||||
bool enabled = false)
|
||||
{
|
||||
Kind = kind;
|
||||
ActionName = actionName ?? "";
|
||||
BindingIndex = bindingIndex;
|
||||
BindingLabel = bindingLabel ?? "";
|
||||
InputPath = inputPath ?? "";
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeInputSettingsCommandKind Kind { get; }
|
||||
public string ActionName { get; }
|
||||
public int BindingIndex { get; }
|
||||
public string BindingLabel { get; }
|
||||
public string InputPath { get; }
|
||||
public bool Enabled { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeInputSettingsSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeInputSettingsSurfaceCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeInputSettingsCommands.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
switch (request.Command ?? "")
|
||||
{
|
||||
case AetheriaRuntimeInputSettingsCommands.Refresh:
|
||||
command = new AetheriaRuntimeInputSettingsSurfaceCommand(
|
||||
AetheriaRuntimeInputSettingsCommandKind.Refresh);
|
||||
return true;
|
||||
case AetheriaRuntimeInputSettingsCommands.CancelCapture:
|
||||
command = new AetheriaRuntimeInputSettingsSurfaceCommand(
|
||||
AetheriaRuntimeInputSettingsCommandKind.CancelCapture);
|
||||
return true;
|
||||
case AetheriaRuntimeInputSettingsCommands.BeginCapture:
|
||||
var actionName = ReadString(request, "actionName");
|
||||
command = new AetheriaRuntimeInputSettingsSurfaceCommand(
|
||||
AetheriaRuntimeInputSettingsCommandKind.BeginCapture,
|
||||
actionName: actionName,
|
||||
bindingIndex: ReadInt(request, "bindingIndex", -1),
|
||||
bindingLabel: ReadString(request, "bindingLabel", actionName));
|
||||
return true;
|
||||
case AetheriaRuntimeInputSettingsCommands.ToggleActionBar:
|
||||
command = new AetheriaRuntimeInputSettingsSurfaceCommand(
|
||||
AetheriaRuntimeInputSettingsCommandKind.ToggleActionBar,
|
||||
inputPath: ReadString(request, "inputPath"),
|
||||
enabled: ReadBool(request, "enabled", false));
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static string ReadString(EveSurfaceCommandRequest request, string key, string defaultValue = "")
|
||||
{
|
||||
return request.Payload != null &&
|
||||
request.Payload.TryGetValue(key, out var raw)
|
||||
? raw ?? defaultValue
|
||||
: defaultValue;
|
||||
}
|
||||
|
||||
private static int ReadInt(EveSurfaceCommandRequest request, string key, int defaultValue)
|
||||
{
|
||||
return request.Payload != null &&
|
||||
request.Payload.TryGetValue(key, out var raw) &&
|
||||
int.TryParse(raw, NumberStyles.Integer, CultureInfo.InvariantCulture, out var value)
|
||||
? value
|
||||
: defaultValue;
|
||||
}
|
||||
|
||||
private static bool ReadBool(EveSurfaceCommandRequest request, string key, bool defaultValue)
|
||||
{
|
||||
return request.Payload != null &&
|
||||
request.Payload.TryGetValue(key, out var raw) &&
|
||||
bool.TryParse(raw, out var value)
|
||||
? value
|
||||
: defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5f5930ec908217844a62e1c49ecb72e2
|
||||
|
|
@ -0,0 +1,269 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeInventoryDropdownOption
|
||||
{
|
||||
public AetheriaRuntimeInventoryDropdownOption(string id, string label, string command)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Command { get; }
|
||||
public bool IsCommand => !string.IsNullOrWhiteSpace(Command);
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeInventoryDropdownGroup
|
||||
{
|
||||
public AetheriaRuntimeInventoryDropdownGroup(
|
||||
string id,
|
||||
string title,
|
||||
IReadOnlyList<AetheriaRuntimeInventoryDropdownOption> options)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Title = title ?? "";
|
||||
Options = options ?? Array.Empty<AetheriaRuntimeInventoryDropdownOption>();
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Title { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeInventoryDropdownOption> Options { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeInventoryDropdownSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeInventoryDropdownSurfaceState(
|
||||
string currentView,
|
||||
IReadOnlyList<AetheriaRuntimeInventoryDropdownGroup> groups,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
CurrentView = currentView ?? "";
|
||||
Groups = groups ?? Array.Empty<AetheriaRuntimeInventoryDropdownGroup>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string CurrentView { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeInventoryDropdownGroup> Groups { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeInventoryDropdownSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.inventory.panel.dropdown";
|
||||
public const string Close = "aetheria.inventory.panel.dropdown.close";
|
||||
public const string SaveLoadout = "aetheria.inventory.panel.dropdown.save_loadout";
|
||||
public const string DockingBay = "aetheria.inventory.panel.dropdown.docking_bay";
|
||||
|
||||
public static string EntityEquipmentCommand(int entityIndex)
|
||||
{
|
||||
return $"{SurfaceId}.entity_{entityIndex}.equipment";
|
||||
}
|
||||
|
||||
public static string EntityBayCommand(int entityIndex, int bayIndex)
|
||||
{
|
||||
return $"{SurfaceId}.entity_{entityIndex}.bay_{bayIndex}";
|
||||
}
|
||||
|
||||
public static string EntityCommand(int entityIndex)
|
||||
{
|
||||
return $"{SurfaceId}.entity_{entityIndex}";
|
||||
}
|
||||
|
||||
public static string LoadoutCommand(int templateIndex)
|
||||
{
|
||||
return $"{SurfaceId}.loadout_{templateIndex}";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeInventoryDropdownSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeInventoryDropdownSurfaceState(
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeInventoryDropdownGroup>(),
|
||||
"");
|
||||
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{SurfaceId}.summary",
|
||||
"Inventory Actions",
|
||||
Metric(
|
||||
$"{SurfaceId}.current",
|
||||
"Current View",
|
||||
string.IsNullOrWhiteSpace(state.CurrentView) ? "None" : state.CurrentView),
|
||||
Text(
|
||||
$"{SurfaceId}.note",
|
||||
"Unity projects available inventory navigation; the shared runtime surface owns the dropdown contract."))
|
||||
};
|
||||
|
||||
foreach (var group in state.Groups)
|
||||
{
|
||||
if (group?.Options == null || group.Options.Count == 0)
|
||||
continue;
|
||||
|
||||
children.Add(Card(
|
||||
string.IsNullOrWhiteSpace(group.Id) ? $"{SurfaceId}.group.{SafeId(group.Title)}" : group.Id,
|
||||
group.Title,
|
||||
ButtonColumn(
|
||||
$"{(string.IsNullOrWhiteSpace(group.Id) ? $"{SurfaceId}.group.{SafeId(group.Title)}" : group.Id)}.options",
|
||||
group.Options.Select(ToOptionComponent).ToArray())));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{SurfaceId}.actions",
|
||||
Button($"{SurfaceId}.close", "Close", Close)));
|
||||
|
||||
var commands = state.Groups
|
||||
.Where(group => group?.Options != null)
|
||||
.SelectMany(group => group.Options)
|
||||
.Where(option => option?.IsCommand == true)
|
||||
.Select(option => new AetheriaRuntimeSurfaceCommandTemplate(option.Command, option.Label, "unity-uitoolkit"))
|
||||
.Append(new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit"))
|
||||
.ToArray();
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "inventory.panel",
|
||||
title: "Inventory Dropdown",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: commands);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ToOptionComponent(AetheriaRuntimeInventoryDropdownOption option)
|
||||
{
|
||||
if (option.IsCommand)
|
||||
return Button(option.Id, option.Label, option.Command);
|
||||
|
||||
return Text(option.Id, option.Label);
|
||||
}
|
||||
|
||||
private static string SafeId(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
return new string(value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? char.ToLowerInvariant(character) : '-')
|
||||
.ToArray()).Trim('-');
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonColumn(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "column", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeInventoryDropdownCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1,
|
||||
Select = 2
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeInventoryDropdownCommand
|
||||
{
|
||||
public AetheriaRuntimeInventoryDropdownCommand(
|
||||
AetheriaRuntimeInventoryDropdownCommandKind kind,
|
||||
string command)
|
||||
{
|
||||
Kind = kind;
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeInventoryDropdownCommandKind Kind { get; }
|
||||
public string Command { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeInventoryDropdownSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeInventoryDropdownCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeInventoryDropdownSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
var commandText = request.Command ?? "";
|
||||
if (string.Equals(commandText, AetheriaRuntimeInventoryDropdownSurfaceBuilder.Close, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeInventoryDropdownCommand(
|
||||
AetheriaRuntimeInventoryDropdownCommandKind.Close,
|
||||
commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(commandText))
|
||||
return false;
|
||||
|
||||
command = new AetheriaRuntimeInventoryDropdownCommand(
|
||||
AetheriaRuntimeInventoryDropdownCommandKind.Select,
|
||||
commandText);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d28ccdf9a2f86a94e943981f0b35b432
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeLoadoutSnapshotProjector
|
||||
{
|
||||
public static string AppendToZone(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
int zoneIndex,
|
||||
string parentEntityKey,
|
||||
AetheriaRuntimeLoadoutTemplateCommit template)
|
||||
{
|
||||
if (run == null || template?.RootEntity == null)
|
||||
return "";
|
||||
|
||||
var zones = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>()).ToArray();
|
||||
var zone = zones.FirstOrDefault(candidate => candidate != null && candidate.ZoneIndex == zoneIndex);
|
||||
if (zone == null)
|
||||
return "";
|
||||
|
||||
var entities = (zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>()).ToList();
|
||||
var parentIndex = TryParseEntityKey(parentEntityKey, out var parentZoneIndex, out var parsedParentIndex) &&
|
||||
parentZoneIndex == zoneIndex
|
||||
? parsedParentIndex
|
||||
: -1;
|
||||
var rootIndex = AppendEntity(entities, template.RootEntity, template.Name);
|
||||
|
||||
if (parentIndex >= 0 && parentIndex < entities.Count)
|
||||
{
|
||||
var children = (entities[parentIndex].ChildEntityIndices ?? Array.Empty<int>()).ToList();
|
||||
if (!children.Contains(rootIndex))
|
||||
children.Add(rootIndex);
|
||||
entities[parentIndex].ChildEntityIndices = children.ToArray();
|
||||
}
|
||||
|
||||
zone.Entities = entities.ToArray();
|
||||
run.Zones = zones;
|
||||
return EntityKey(run.RunId, zoneIndex, rootIndex);
|
||||
}
|
||||
|
||||
private static int AppendEntity(
|
||||
List<AetheriaRuntimeEntitySnapshotCommit> entities,
|
||||
AetheriaRuntimeEntityLoadoutCommit loadout,
|
||||
string templateName)
|
||||
{
|
||||
var entityIndex = entities.Count;
|
||||
var entity = new AetheriaRuntimeEntitySnapshotCommit
|
||||
{
|
||||
EntityIndex = entityIndex,
|
||||
Name = string.IsNullOrWhiteSpace(loadout.Name) ? templateName ?? "" : loadout.Name,
|
||||
Kind = string.IsNullOrWhiteSpace(loadout.Kind) ? "ship" : loadout.Kind,
|
||||
DirectionX = 0,
|
||||
DirectionY = 1,
|
||||
IsActive = true,
|
||||
HullItemKey = loadout.Hull?.ItemKey ?? "",
|
||||
FactionKey = loadout.FactionKey ?? "",
|
||||
Equipment = CloneSlots(loadout.Equipment),
|
||||
CargoBays = CloneSlots(loadout.CargoBays),
|
||||
DockingBays = CloneSlots(loadout.DockingBays),
|
||||
CargoContents = CloneCargo(loadout.CargoContents),
|
||||
DockingBayContents = CloneCargo(loadout.DockingBayContents),
|
||||
DockingBayAssignments = (loadout.DockingBayAssignments ?? Array.Empty<int>()).ToArray(),
|
||||
WeaponGroups = (loadout.WeaponGroups ?? Array.Empty<IReadOnlyList<int>>())
|
||||
.Select(group => (IReadOnlyList<int>)(group ?? Array.Empty<int>()).ToArray())
|
||||
.ToArray(),
|
||||
TargetEntityIndex = -1,
|
||||
ShutdownPerformance = 0.25
|
||||
};
|
||||
entities.Add(entity);
|
||||
|
||||
var childIndices = new List<int>();
|
||||
foreach (var child in loadout.Children ?? Array.Empty<AetheriaRuntimeEntityLoadoutCommit>())
|
||||
{
|
||||
if (child == null)
|
||||
continue;
|
||||
childIndices.Add(AppendEntity(entities, child, ""));
|
||||
}
|
||||
|
||||
entity.ChildEntityIndices = childIndices.ToArray();
|
||||
return entityIndex;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemSlotCommit[] CloneSlots(
|
||||
IReadOnlyList<AetheriaRuntimeLoadoutItemSlotCommit>? slots)
|
||||
{
|
||||
return (slots ?? Array.Empty<AetheriaRuntimeLoadoutItemSlotCommit>())
|
||||
.Where(slot => slot != null)
|
||||
.Select(CloneSlot)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCargoBayLoadoutCommit[] CloneCargo(
|
||||
IReadOnlyList<AetheriaRuntimeCargoBayLoadoutCommit>? cargo)
|
||||
{
|
||||
return (cargo ?? Array.Empty<AetheriaRuntimeCargoBayLoadoutCommit>())
|
||||
.Select(bay => new AetheriaRuntimeCargoBayLoadoutCommit
|
||||
{
|
||||
Items = CloneSlots(bay?.Items)
|
||||
})
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemSlotCommit CloneSlot(AetheriaRuntimeLoadoutItemSlotCommit slot)
|
||||
{
|
||||
return new AetheriaRuntimeLoadoutItemSlotCommit
|
||||
{
|
||||
X = slot.X,
|
||||
Y = slot.Y,
|
||||
Item = CloneItem(slot.Item)
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeLoadoutItemCommit CloneItem(AetheriaRuntimeLoadoutItemCommit? item)
|
||||
{
|
||||
return new AetheriaRuntimeLoadoutItemCommit
|
||||
{
|
||||
ItemKey = item?.ItemKey ?? "",
|
||||
Quality = item?.Quality ?? 1.0,
|
||||
Durability = item?.Durability ?? 1.0,
|
||||
Quantity = item?.Quantity ?? 1,
|
||||
Enabled = item?.Enabled ?? true,
|
||||
OverrideShutdown = item?.OverrideShutdown ?? false
|
||||
};
|
||||
}
|
||||
|
||||
private static string EntityKey(string runId, int zoneIndex, int entityIndex)
|
||||
{
|
||||
return $"global:aetheria.run_state.{(string.IsNullOrWhiteSpace(runId) ? "local" : runId)}.zone.{zoneIndex}.entity.{entityIndex}.v1";
|
||||
}
|
||||
|
||||
private static bool TryParseEntityKey(string entityKey, out int zoneIndex, out int entityIndex)
|
||||
{
|
||||
zoneIndex = -1;
|
||||
entityIndex = -1;
|
||||
if (string.IsNullOrWhiteSpace(entityKey))
|
||||
return false;
|
||||
|
||||
var parts = entityKey.Split('.');
|
||||
for (var i = 0; i < parts.Length - 1; i++)
|
||||
{
|
||||
if (string.Equals(parts[i], "zone", StringComparison.Ordinal) &&
|
||||
int.TryParse(parts[i + 1], out zoneIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Equals(parts[i], "entity", StringComparison.Ordinal) &&
|
||||
int.TryParse(parts[i + 1], out entityIndex))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
return zoneIndex >= 0 && entityIndex >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeLoadoutTemplateCommands
|
||||
{
|
||||
public const string SurfaceId = "aetheria.loadout_templates";
|
||||
public const string Save = "aetheria.loadout_templates.save";
|
||||
|
||||
public static bool IsKnown(string command)
|
||||
{
|
||||
return command == Save;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,568 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeMainMenuCommands
|
||||
{
|
||||
public const string RootSurfaceId = "aetheria.main_menu.root";
|
||||
public const string SettingsSurfaceId = "aetheria.main_menu.settings";
|
||||
public const string InputSettingsSurfaceId = "aetheria.main_menu.input_settings";
|
||||
public const string PlayerSettingsShellSurfaceId = "aetheria.main_menu.player_settings";
|
||||
public const string VerseSettingsShellSurfaceId = "aetheria.main_menu.verse_settings";
|
||||
|
||||
public const string ContinueRun = "aetheria.main_menu.root.continue";
|
||||
public const string NewGame = "aetheria.main_menu.root.new_game";
|
||||
public const string ShowSettings = "aetheria.main_menu.root.show_settings";
|
||||
public const string Quit = "aetheria.main_menu.root.quit";
|
||||
public const string OpenRuntimeInputScreen = "aetheria.main_menu.input_settings.open_runtime_screen";
|
||||
public const string ShowPlayerSettings = "aetheria.main_menu.settings.show_player_settings";
|
||||
public const string ShowVerseSettings = "aetheria.main_menu.settings.show_verse_settings";
|
||||
public const string ShowInputSettings = "aetheria.main_menu.settings.show_input_settings";
|
||||
public const string BackToMain = "aetheria.main_menu.settings.back_to_main";
|
||||
public const string BackToSettings = "aetheria.main_menu.settings.back_to_settings";
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeMainMenuSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeMainMenuSurfaceState(
|
||||
string targetLabel,
|
||||
string targetKind,
|
||||
string targetSource,
|
||||
string verseTitle,
|
||||
string verseId,
|
||||
string verseVisibility,
|
||||
string verseCultMeshAddress,
|
||||
bool inGame,
|
||||
bool hasAuthoritativeDaemonFrame,
|
||||
string daemonRunId,
|
||||
long daemonFrameId,
|
||||
int bindingOverrideCount,
|
||||
int actionBarInputCount,
|
||||
bool canOpenRuntimeInputScreen,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
TargetLabel = targetLabel ?? "";
|
||||
TargetKind = targetKind ?? "";
|
||||
TargetSource = targetSource ?? "";
|
||||
VerseTitle = verseTitle ?? "";
|
||||
VerseId = verseId ?? "";
|
||||
VerseVisibility = verseVisibility ?? "";
|
||||
VerseCultMeshAddress = verseCultMeshAddress ?? "";
|
||||
InGame = inGame;
|
||||
HasAuthoritativeDaemonFrame = hasAuthoritativeDaemonFrame;
|
||||
DaemonRunId = daemonRunId ?? "";
|
||||
DaemonFrameId = daemonFrameId;
|
||||
BindingOverrideCount = bindingOverrideCount;
|
||||
ActionBarInputCount = actionBarInputCount;
|
||||
CanOpenRuntimeInputScreen = canOpenRuntimeInputScreen;
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string TargetLabel { get; }
|
||||
public string TargetKind { get; }
|
||||
public string TargetSource { get; }
|
||||
public string VerseTitle { get; }
|
||||
public string VerseId { get; }
|
||||
public string VerseVisibility { get; }
|
||||
public string VerseCultMeshAddress { get; }
|
||||
public bool InGame { get; }
|
||||
public bool HasAuthoritativeDaemonFrame { get; }
|
||||
public string DaemonRunId { get; }
|
||||
public long DaemonFrameId { get; }
|
||||
public int BindingOverrideCount { get; }
|
||||
public int ActionBarInputCount { get; }
|
||||
public bool CanOpenRuntimeInputScreen { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
|
||||
public string VerseLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
var title = string.IsNullOrWhiteSpace(VerseTitle) ? "Unknown Verse" : VerseTitle;
|
||||
var verseId = string.IsNullOrWhiteSpace(VerseId) ? "unknown" : VerseId;
|
||||
return string.Equals(title, verseId, StringComparison.Ordinal) ? title : $"{title} ({verseId})";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeMainMenuSurfaceBuilder
|
||||
{
|
||||
public static AetheriaRuntimeSurfaceDocument BuildRoot(
|
||||
AetheriaRuntimeMainMenuSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
|
||||
var commands = new List<AetheriaRuntimeSurfaceCommandTemplate>();
|
||||
var actionButtons = new List<AetheriaRuntimeSurfaceComponent>();
|
||||
var cardChildren = new List<AetheriaRuntimeSurfaceComponent>();
|
||||
var targetKind = string.IsNullOrWhiteSpace(state.TargetKind) ? "unknown" : state.TargetKind;
|
||||
var targetSource = string.IsNullOrWhiteSpace(state.TargetSource) ? "unknown" : state.TargetSource;
|
||||
var verseVisibility = string.IsNullOrWhiteSpace(state.VerseVisibility) ? "unknown" : state.VerseVisibility;
|
||||
var verseMeshAddress = string.IsNullOrWhiteSpace(state.VerseCultMeshAddress) ? "unpublished" : state.VerseCultMeshAddress;
|
||||
|
||||
if (!state.InGame)
|
||||
{
|
||||
if (!state.HasAuthoritativeDaemonFrame)
|
||||
{
|
||||
cardChildren.Add(Text(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.continue.note",
|
||||
$"No authoritative daemon frame is available in {state.VerseLabel} yet. Start or connect a daemon before opening the observer scene."));
|
||||
}
|
||||
else
|
||||
{
|
||||
commands.Add(Command(AetheriaRuntimeMainMenuCommands.ContinueRun, "Continue"));
|
||||
actionButtons.Add(Button(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.continue",
|
||||
"Continue",
|
||||
AetheriaRuntimeMainMenuCommands.ContinueRun));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.continue.run",
|
||||
"Daemon Run",
|
||||
state.DaemonRunId));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.continue.frame",
|
||||
"Daemon Frame",
|
||||
state.DaemonFrameId.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.target.title",
|
||||
"Client Target",
|
||||
state.TargetLabel));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.target.transport",
|
||||
"Transport",
|
||||
targetKind));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.target.source",
|
||||
"Target Source",
|
||||
targetSource));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.verse.title",
|
||||
"Verse",
|
||||
state.VerseLabel));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.verse.visibility",
|
||||
"Visibility",
|
||||
verseVisibility));
|
||||
cardChildren.Add(Metric(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.verse.mesh",
|
||||
"CultMesh",
|
||||
verseMeshAddress));
|
||||
|
||||
commands.Add(Command(AetheriaRuntimeMainMenuCommands.NewGame, "New Game"));
|
||||
commands.Add(Command(AetheriaRuntimeMainMenuCommands.ShowSettings, "Settings"));
|
||||
commands.Add(Command(AetheriaRuntimeMainMenuCommands.Quit, "Quit"));
|
||||
|
||||
actionButtons.Add(Button($"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.newGame", "New Game", AetheriaRuntimeMainMenuCommands.NewGame));
|
||||
actionButtons.Add(Button($"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.settings", "Settings", AetheriaRuntimeMainMenuCommands.ShowSettings));
|
||||
actionButtons.Add(Button($"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.quit", "Quit", AetheriaRuntimeMainMenuCommands.Quit));
|
||||
|
||||
cardChildren.Add(Text(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.note",
|
||||
$"The client lowers this shell through Eve. The client target chooses which Verse it follows; game truth belongs to the daemon serving {state.VerseLabel}."));
|
||||
cardChildren.Add(ButtonColumn($"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.actions", actionButtons.ToArray()));
|
||||
|
||||
return BuildSurfaceDocument(
|
||||
AetheriaRuntimeMainMenuCommands.RootSurfaceId,
|
||||
"Aetheria Terminus",
|
||||
state.UpdatedAtUtc,
|
||||
version,
|
||||
commands,
|
||||
Card(
|
||||
$"{AetheriaRuntimeMainMenuCommands.RootSurfaceId}.card",
|
||||
"Aetheria Terminus",
|
||||
cardChildren.ToArray()));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument BuildSettings(
|
||||
string updatedAtUtc,
|
||||
long version = 1)
|
||||
{
|
||||
return BuildSurfaceDocument(
|
||||
AetheriaRuntimeMainMenuCommands.SettingsSurfaceId,
|
||||
"Aetheria Settings",
|
||||
updatedAtUtc,
|
||||
version,
|
||||
new[]
|
||||
{
|
||||
Command(AetheriaRuntimeMainMenuCommands.ShowPlayerSettings, "Player Settings"),
|
||||
Command(AetheriaRuntimeMainMenuCommands.ShowVerseSettings, "Verse"),
|
||||
Command(AetheriaRuntimeMainMenuCommands.ShowInputSettings, "Input"),
|
||||
Command(AetheriaRuntimeMainMenuCommands.BackToMain, "Back")
|
||||
},
|
||||
Card(
|
||||
"aetheria.mainMenu.settings.card",
|
||||
"Settings",
|
||||
Text(
|
||||
"aetheria.mainMenu.settings.note",
|
||||
"Player settings, client target selection, and input rebinding all lower through typed Eve surfaces. Audio still has no typed owner."),
|
||||
ButtonRow(
|
||||
"aetheria.mainMenu.settings.actions",
|
||||
Button("aetheria.mainMenu.settings.playerSettings", "Player Settings", AetheriaRuntimeMainMenuCommands.ShowPlayerSettings),
|
||||
Button("aetheria.mainMenu.settings.verse", "Verse", AetheriaRuntimeMainMenuCommands.ShowVerseSettings),
|
||||
Button("aetheria.mainMenu.settings.input", "Input", AetheriaRuntimeMainMenuCommands.ShowInputSettings),
|
||||
Button("aetheria.mainMenu.settings.back", "Back", AetheriaRuntimeMainMenuCommands.BackToMain))));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument BuildInputSettings(
|
||||
AetheriaRuntimeMainMenuSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
|
||||
var commands = new List<AetheriaRuntimeSurfaceCommandTemplate>
|
||||
{
|
||||
Command(AetheriaRuntimeMainMenuCommands.BackToSettings, "Back")
|
||||
};
|
||||
|
||||
var cardChildren = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Metric(
|
||||
"aetheria.mainMenu.input.bindingOverrides",
|
||||
"Binding Overrides",
|
||||
state.BindingOverrideCount.ToString()),
|
||||
Metric(
|
||||
"aetheria.mainMenu.input.actionBarInputs",
|
||||
"Action-Bar Inputs",
|
||||
state.ActionBarInputCount.ToString())
|
||||
};
|
||||
|
||||
if (state.CanOpenRuntimeInputScreen)
|
||||
{
|
||||
commands.Insert(0, Command(AetheriaRuntimeMainMenuCommands.OpenRuntimeInputScreen, "Open Remap Screen"));
|
||||
cardChildren.Add(Text(
|
||||
"aetheria.mainMenu.input.note",
|
||||
"The runtime Eve input screen owns low-level InputSystem rebinding and action-bar input edits. This title shell reports typed player-settings state and hands off to that owner."));
|
||||
}
|
||||
else if (state.InGame)
|
||||
{
|
||||
cardChildren.Add(Text(
|
||||
"aetheria.mainMenu.input.note",
|
||||
"The runtime Eve input screen should own rebinding here, but this scene has no active input surface to hand off to."));
|
||||
}
|
||||
else
|
||||
{
|
||||
cardChildren.Add(Text(
|
||||
"aetheria.mainMenu.input.note",
|
||||
"This title shell reports the typed player-settings state. Launch a run to open the runtime Eve input screen that owns low-level InputSystem rebinding."));
|
||||
}
|
||||
|
||||
var buttons = new List<AetheriaRuntimeSurfaceComponent>();
|
||||
if (state.CanOpenRuntimeInputScreen)
|
||||
{
|
||||
buttons.Add(Button(
|
||||
"aetheria.mainMenu.input.openRuntimeScreen",
|
||||
"Open Remap Screen",
|
||||
AetheriaRuntimeMainMenuCommands.OpenRuntimeInputScreen));
|
||||
}
|
||||
|
||||
buttons.Add(Button("aetheria.mainMenu.input.back", "Back", AetheriaRuntimeMainMenuCommands.BackToSettings));
|
||||
cardChildren.Add(ButtonRow("aetheria.mainMenu.input.actions", buttons.ToArray()));
|
||||
|
||||
return BuildSurfaceDocument(
|
||||
AetheriaRuntimeMainMenuCommands.InputSettingsSurfaceId,
|
||||
"Aetheria Input Settings",
|
||||
state.UpdatedAtUtc,
|
||||
version,
|
||||
commands,
|
||||
Card(
|
||||
"aetheria.mainMenu.input.card",
|
||||
"Input Settings",
|
||||
cardChildren.ToArray()));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument WithBackAction(
|
||||
AetheriaRuntimeSurfaceDocument document,
|
||||
string surfaceId,
|
||||
string backCommand,
|
||||
string backLabel)
|
||||
{
|
||||
if (document == null) throw new ArgumentNullException(nameof(document));
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
document.ProviderId,
|
||||
document.ProviderKind,
|
||||
document.Title,
|
||||
document.Version,
|
||||
document.UpdatedAtUtc,
|
||||
new AetheriaRuntimeSurfaceTree(
|
||||
surfaceId,
|
||||
Node(
|
||||
$"{surfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
document.Surface.Root,
|
||||
ButtonRow(
|
||||
$"{surfaceId}.actions",
|
||||
Button($"{surfaceId}.back", backLabel, backCommand))),
|
||||
document.Surface.Styles),
|
||||
document.Commands
|
||||
.Concat(new[] { Command(backCommand, backLabel) })
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeMainMenuSurfaceState EmptyState()
|
||||
{
|
||||
return new AetheriaRuntimeMainMenuSurfaceState(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
inGame: false,
|
||||
hasAuthoritativeDaemonFrame: false,
|
||||
daemonRunId: "",
|
||||
daemonFrameId: -1,
|
||||
bindingOverrideCount: 0,
|
||||
actionBarInputCount: 0,
|
||||
canOpenRuntimeInputScreen: false,
|
||||
updatedAtUtc: "");
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceDocument BuildSurfaceDocument(
|
||||
string surfaceId,
|
||||
string title,
|
||||
string updatedAtUtc,
|
||||
long version,
|
||||
IReadOnlyList<AetheriaRuntimeSurfaceCommandTemplate> commands,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "game.menu",
|
||||
title: title,
|
||||
version: version,
|
||||
updatedAtUtc: updatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
surfaceId,
|
||||
Node($"{surfaceId}.root", "surface", Array.Empty<(string Key, string Value)>(), children),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: commands);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceCommandTemplate Command(string command, string label)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceCommandTemplate(command, label, "unity-uitoolkit");
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title) }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label), ("command", command) });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonColumn(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "column", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeMainMenuCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
ContinueRun = 1,
|
||||
NewGame = 2,
|
||||
ShowSettings = 3,
|
||||
Quit = 4,
|
||||
ShowPlayerSettings = 5,
|
||||
ShowVerseSettings = 6,
|
||||
ShowInputSettings = 7,
|
||||
BackToMain = 8,
|
||||
BackToSettings = 9,
|
||||
OpenRuntimeInputScreen = 10,
|
||||
PlayerSettingsCommand = 11,
|
||||
ClientTargetCommand = 12,
|
||||
VerseHostCommand = 13
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeMainMenuCommand
|
||||
{
|
||||
public AetheriaRuntimeMainMenuCommand(
|
||||
AetheriaRuntimeMainMenuCommandKind kind,
|
||||
string command = "")
|
||||
{
|
||||
Kind = kind;
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeMainMenuCommandKind Kind { get; }
|
||||
public string Command { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeMainMenuSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeMainMenuCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null)
|
||||
return false;
|
||||
|
||||
switch (request.SurfaceId ?? "")
|
||||
{
|
||||
case AetheriaRuntimeMainMenuCommands.RootSurfaceId:
|
||||
return TryReadRoot(request.Command ?? "", out command);
|
||||
case AetheriaRuntimeMainMenuCommands.SettingsSurfaceId:
|
||||
return TryReadSettings(request.Command ?? "", out command);
|
||||
case AetheriaRuntimeMainMenuCommands.InputSettingsSurfaceId:
|
||||
return TryReadInputSettings(request.Command ?? "", out command);
|
||||
case AetheriaRuntimeMainMenuCommands.PlayerSettingsShellSurfaceId:
|
||||
return TryReadPlayerSettingsShell(request.Command ?? "", out command);
|
||||
case AetheriaRuntimeMainMenuCommands.VerseSettingsShellSurfaceId:
|
||||
return TryReadVerseSettingsShell(request.Command ?? "", out command);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadRoot(string commandText, out AetheriaRuntimeMainMenuCommand command)
|
||||
{
|
||||
switch (commandText)
|
||||
{
|
||||
case AetheriaRuntimeMainMenuCommands.ContinueRun:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.ContinueRun, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.NewGame:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.NewGame, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.ShowSettings:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.ShowSettings, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.Quit:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.Quit, commandText);
|
||||
return true;
|
||||
default:
|
||||
command = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadSettings(string commandText, out AetheriaRuntimeMainMenuCommand command)
|
||||
{
|
||||
switch (commandText)
|
||||
{
|
||||
case AetheriaRuntimeMainMenuCommands.ShowPlayerSettings:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.ShowPlayerSettings, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.ShowVerseSettings:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.ShowVerseSettings, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.ShowInputSettings:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.ShowInputSettings, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.BackToMain:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.BackToMain, commandText);
|
||||
return true;
|
||||
default:
|
||||
command = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadInputSettings(string commandText, out AetheriaRuntimeMainMenuCommand command)
|
||||
{
|
||||
switch (commandText)
|
||||
{
|
||||
case AetheriaRuntimeMainMenuCommands.OpenRuntimeInputScreen:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.OpenRuntimeInputScreen, commandText);
|
||||
return true;
|
||||
case AetheriaRuntimeMainMenuCommands.BackToSettings:
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.BackToSettings, commandText);
|
||||
return true;
|
||||
default:
|
||||
command = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryReadPlayerSettingsShell(string commandText, out AetheriaRuntimeMainMenuCommand command)
|
||||
{
|
||||
if (string.Equals(commandText, AetheriaRuntimeMainMenuCommands.BackToSettings, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.BackToSettings, commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (AetheriaRuntimePlayerSettingsCommands.IsKnown(commandText))
|
||||
{
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.PlayerSettingsCommand, commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
command = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
private static bool TryReadVerseSettingsShell(string commandText, out AetheriaRuntimeMainMenuCommand command)
|
||||
{
|
||||
if (string.Equals(commandText, AetheriaRuntimeMainMenuCommands.BackToSettings, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.BackToSettings, commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (AetheriaRuntimeClientTargetCommands.IsKnown(commandText))
|
||||
{
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.ClientTargetCommand, commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (AetheriaRuntimeVerseHostCommands.IsKnown(commandText))
|
||||
{
|
||||
command = new AetheriaRuntimeMainMenuCommand(AetheriaRuntimeMainMenuCommandKind.VerseHostCommand, commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
command = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeMenuTabSurfaceEntry
|
||||
{
|
||||
public AetheriaRuntimeMenuTabSurfaceEntry(string key, string label, bool selected)
|
||||
{
|
||||
Key = key ?? "";
|
||||
Label = label ?? "";
|
||||
Selected = selected;
|
||||
}
|
||||
|
||||
public string Key { get; }
|
||||
public string Label { get; }
|
||||
public bool Selected { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeMenuTabsSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeMenuTabsSurfaceState(
|
||||
string currentTabKey,
|
||||
IReadOnlyList<AetheriaRuntimeMenuTabSurfaceEntry> visibleTabs,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
CurrentTabKey = currentTabKey ?? "";
|
||||
VisibleTabs = visibleTabs ?? Array.Empty<AetheriaRuntimeMenuTabSurfaceEntry>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string CurrentTabKey { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeMenuTabSurfaceEntry> VisibleTabs { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeMenuTabsSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.runtime_menu.tabs";
|
||||
|
||||
public static string CommandFor(string tabKey)
|
||||
{
|
||||
var normalized = string.IsNullOrWhiteSpace(tabKey)
|
||||
? "unknown"
|
||||
: tabKey.Trim().ToLowerInvariant();
|
||||
return $"aetheria.runtime_menu.tab.{normalized}";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeMenuTabsSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeMenuTabsSurfaceState(
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeMenuTabSurfaceEntry>(),
|
||||
"");
|
||||
|
||||
var commands = state.VisibleTabs
|
||||
.Select(tab => new AetheriaRuntimeSurfaceCommandTemplate(
|
||||
CommandFor(tab.Key),
|
||||
LabelFor(tab),
|
||||
"unity-uitoolkit"))
|
||||
.ToArray();
|
||||
var buttons = state.VisibleTabs
|
||||
.Select(tab => Button(
|
||||
$"{SurfaceId}.{SafeId(tab.Key)}",
|
||||
tab.Selected ? $"{LabelFor(tab)} *" : LabelFor(tab),
|
||||
CommandFor(tab.Key)))
|
||||
.ToArray();
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "runtime.menu",
|
||||
title: "Runtime Menu Tabs",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Text(
|
||||
$"{SurfaceId}.current",
|
||||
$"Current: {state.CurrentTabKey}"),
|
||||
ButtonRow($"{SurfaceId}.tabs", buttons)),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: commands);
|
||||
}
|
||||
|
||||
private static string LabelFor(AetheriaRuntimeMenuTabSurfaceEntry tab)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(tab.Label) ? tab.Key : tab.Label;
|
||||
}
|
||||
|
||||
private static string SafeId(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
return new string(value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? char.ToLowerInvariant(character) : '-')
|
||||
.ToArray()).Trim('-');
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeMenuTabCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
SelectTab = 1
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeMenuTabCommand
|
||||
{
|
||||
public AetheriaRuntimeMenuTabCommand(
|
||||
AetheriaRuntimeMenuTabCommandKind kind,
|
||||
string tabKey)
|
||||
{
|
||||
Kind = kind;
|
||||
TabKey = tabKey ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeMenuTabCommandKind Kind { get; }
|
||||
public string TabKey { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeMenuTabsSurfaceCommands
|
||||
{
|
||||
private const string CommandPrefix = "aetheria.runtime_menu.tab.";
|
||||
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeMenuTabCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeMenuTabsSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
var commandText = request.Command ?? "";
|
||||
if (!commandText.StartsWith(CommandPrefix, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
var tabKey = commandText.Substring(CommandPrefix.Length);
|
||||
if (string.IsNullOrWhiteSpace(tabKey))
|
||||
return false;
|
||||
|
||||
command = new AetheriaRuntimeMenuTabCommand(
|
||||
AetheriaRuntimeMenuTabCommandKind.SelectTab,
|
||||
tabKey);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
using System;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeObservedDaemonState
|
||||
{
|
||||
public AetheriaRuntimeObservedDaemonState(
|
||||
AetheriaRuntimeDaemonFrameDocument frame,
|
||||
AetheriaRuntimeDaemonSoaViewDocument? soaView,
|
||||
string framePath,
|
||||
string soaViewPath)
|
||||
{
|
||||
Frame = frame ?? throw new ArgumentNullException(nameof(frame));
|
||||
SoaView = soaView;
|
||||
SoaIndex = AetheriaRuntimeDaemonSoaViewIndex.Build(soaView);
|
||||
FramePath = framePath ?? "";
|
||||
SoaViewPath = soaViewPath ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeDaemonFrameDocument Frame { get; }
|
||||
public AetheriaRuntimeDaemonSoaViewDocument? SoaView { get; }
|
||||
public AetheriaRuntimeDaemonSoaViewIndex SoaIndex { get; }
|
||||
public string FramePath { get; }
|
||||
public string SoaViewPath { get; }
|
||||
public bool HasSoaView => SoaView != null && SoaIndex.IsValid;
|
||||
public bool IsAuthoritative => Frame.IsAuthoritative;
|
||||
public AetheriaRuntimeRunCheckpointCommit Run => Frame.Run;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: faf4bdd4c3ff79548932e1e85d115eed
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeOperationsCommands
|
||||
{
|
||||
public const string SurfaceId = "aetheria.operations";
|
||||
public const string Refresh = "aetheria.operations.refresh";
|
||||
|
||||
public static bool IsKnown(string command)
|
||||
{
|
||||
return command == Refresh;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,403 +0,0 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using MessagePack;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
internal static class AetheriaRuntimePendingCultCacheStore
|
||||
{
|
||||
private const string FormatVersion = "cultcache.store.v1";
|
||||
private const int StoreSnapshotFieldCount = 3;
|
||||
private const int SchemaCatalogEntryFieldCount = 7;
|
||||
private const int SchemaCatalogMemberFieldCount = 8;
|
||||
private const int PersistedRecordFieldCount = 4;
|
||||
|
||||
public static void WriteStateCommit(string path, AetheriaRuntimeStateCommitDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"pending:aetheria.runtime_commit.{document.CommandId}.v1",
|
||||
AetheriaRuntimeStateCommitDocument.SchemaId,
|
||||
"aetheria.runtime_commit",
|
||||
"aetheria.runtime_commit.v1",
|
||||
document.CreatedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStateCommitDocument ReadStateCommit(string path)
|
||||
{
|
||||
return ReadStateCommitDocument(ReadDocumentPayload(path, AetheriaRuntimeStateCommitDocument.SchemaId));
|
||||
}
|
||||
|
||||
public static void WriteEveCommand(string path, AetheriaRuntimeEveCommandDocument document)
|
||||
{
|
||||
WriteDocument(
|
||||
path,
|
||||
$"pending:gamecult.eve.command.{document.CommandId}.v1",
|
||||
AetheriaRuntimeEveCommandDocument.SchemaId,
|
||||
"gamecult.eve.command",
|
||||
"gamecult.eve.command.v1",
|
||||
document.IssuedAtUtc,
|
||||
MessagePackSerializer.Serialize(document));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeEveCommandDocument ReadEveCommand(string path)
|
||||
{
|
||||
return MessagePackSerializer.Deserialize<AetheriaRuntimeEveCommandDocument>(
|
||||
ReadDocumentPayload(path, AetheriaRuntimeEveCommandDocument.SchemaId));
|
||||
}
|
||||
|
||||
private static void WriteDocument(
|
||||
string path,
|
||||
string key,
|
||||
string schemaId,
|
||||
string schemaName,
|
||||
string schemaVersion,
|
||||
string storedAt,
|
||||
byte[] payload)
|
||||
{
|
||||
var buffer = new ArrayBufferWriter<byte>();
|
||||
var writer = new MessagePackWriter(buffer);
|
||||
|
||||
writer.WriteArrayHeader(StoreSnapshotFieldCount);
|
||||
writer.Write(FormatVersion);
|
||||
writer.WriteArrayHeader(1);
|
||||
WriteSchemaCatalogEntry(ref writer, schemaId, schemaName, schemaVersion, payload);
|
||||
writer.WriteArrayHeader(1);
|
||||
WritePersistedRecord(ref writer, key, schemaId, storedAt, payload);
|
||||
writer.Flush();
|
||||
|
||||
WriteFileAtomically(path, buffer.WrittenSpan.ToArray());
|
||||
}
|
||||
|
||||
private static byte[] ReadDocumentPayload(string path, string expectedSchemaId)
|
||||
{
|
||||
var reader = new MessagePackReader(File.ReadAllBytes(path));
|
||||
var fieldCount = reader.ReadArrayHeader();
|
||||
if (fieldCount < StoreSnapshotFieldCount)
|
||||
{
|
||||
throw new InvalidDataException($"Pending CultCache document '{path}' is missing store fields.");
|
||||
}
|
||||
|
||||
var formatVersion = reader.ReadString() ?? "";
|
||||
if (!formatVersion.StartsWith("cultcache.store.v1", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidDataException($"Pending document '{path}' is not a CultCache store.");
|
||||
}
|
||||
|
||||
var schemaIds = ReadSchemaCatalog(ref reader);
|
||||
var recordCount = reader.ReadArrayHeader();
|
||||
if (recordCount != 1)
|
||||
{
|
||||
throw new InvalidDataException($"Pending CultCache document '{path}' must contain exactly one record.");
|
||||
}
|
||||
|
||||
var recordFieldCount = reader.ReadArrayHeader();
|
||||
if (recordFieldCount < PersistedRecordFieldCount)
|
||||
{
|
||||
throw new InvalidDataException($"Pending CultCache record '{path}' is missing record fields.");
|
||||
}
|
||||
|
||||
reader.Skip(); // key
|
||||
var schemaId = reader.ReadString() ?? "";
|
||||
reader.Skip(); // storedAt
|
||||
var payload = reader.ReadBytes()?.ToArray() ?? Array.Empty<byte>();
|
||||
for (var index = PersistedRecordFieldCount; index < recordFieldCount; index++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
for (var index = StoreSnapshotFieldCount; index < fieldCount; index++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
if (!string.Equals(schemaId, expectedSchemaId, StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidDataException($"Pending document '{path}' has schema '{schemaId}', expected '{expectedSchemaId}'.");
|
||||
}
|
||||
|
||||
if (!schemaIds.Contains(schemaId, StringComparer.Ordinal))
|
||||
{
|
||||
throw new InvalidDataException($"Pending document '{path}' does not publish schema '{schemaId}' in its CultCache catalog.");
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStateCommitDocument ReadStateCommitDocument(byte[] payload)
|
||||
{
|
||||
var reader = new MessagePackReader(payload);
|
||||
var fieldCount = reader.ReadArrayHeader();
|
||||
var document = new AetheriaRuntimeStateCommitDocument
|
||||
{
|
||||
Schema = ReadFieldString(ref reader, fieldCount, 0, AetheriaRuntimeStateCommitDocument.SchemaId),
|
||||
Kind = ReadFieldString(ref reader, fieldCount, 1, ""),
|
||||
CommandId = ReadFieldString(ref reader, fieldCount, 2, ""),
|
||||
CreatedAtUtc = ReadFieldString(ref reader, fieldCount, 3, ""),
|
||||
PlayerSettings = ReadFieldDocument<AetheriaRuntimePlayerSettingsCommit>(ref reader, fieldCount, 4),
|
||||
LoadoutTemplate = ReadFieldDocument<AetheriaRuntimeLoadoutTemplateCommit>(ref reader, fieldCount, 5),
|
||||
RunCheckpoint = ReadFieldRunCheckpoint(ref reader, fieldCount, 6)
|
||||
};
|
||||
|
||||
for (var index = 7; index < fieldCount; index++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
private static T? ReadFieldDocument<T>(ref MessagePackReader reader, int fields, int index)
|
||||
where T : class
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return null;
|
||||
}
|
||||
|
||||
return MessagePackSerializer.Deserialize<T>(ReadRawBytes(ref reader));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeRunCheckpointCommit? ReadFieldRunCheckpoint(ref MessagePackReader reader, int fields, int index)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return null;
|
||||
}
|
||||
|
||||
return ReadRunCheckpoint(ReadRawBytes(ref reader));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeRunCheckpointCommit ReadRunCheckpoint(byte[] payload)
|
||||
{
|
||||
var reader = new MessagePackReader(payload);
|
||||
var fields = reader.ReadArrayHeader();
|
||||
|
||||
var runId = ReadFieldString(ref reader, fields, 0, "local");
|
||||
var isTutorial = ReadFieldBool(ref reader, fields, 1, false);
|
||||
var entranceZoneIndex = ReadFieldInt32(ref reader, fields, 2, -1);
|
||||
var exitZoneIndex = ReadFieldInt32(ref reader, fields, 3, -1);
|
||||
var currentZoneIndex = ReadFieldInt32(ref reader, fields, 4, -1);
|
||||
|
||||
string currentEntityKey;
|
||||
int[] discoveredZoneIndices;
|
||||
AetheriaRuntimeZoneSnapshotCommit[] zones;
|
||||
AetheriaRuntimeActionBarBindingCommit[] actionBarBindings;
|
||||
AetheriaRuntimeFactionRelationshipCommit[] factionRelationships;
|
||||
uint generationSeed;
|
||||
|
||||
if (fields >= 12)
|
||||
{
|
||||
var legacyCurrentZoneEntityIndex = ReadFieldInt32(ref reader, fields, 5, -1);
|
||||
discoveredZoneIndices = ReadFieldArray<int>(ref reader, fields, 6);
|
||||
zones = ReadFieldArray<AetheriaRuntimeZoneSnapshotCommit>(ref reader, fields, 7);
|
||||
actionBarBindings = ReadFieldArray<AetheriaRuntimeActionBarBindingCommit>(ref reader, fields, 8);
|
||||
factionRelationships = ReadFieldArray<AetheriaRuntimeFactionRelationshipCommit>(ref reader, fields, 9);
|
||||
generationSeed = ReadFieldUInt32(ref reader, fields, 10, 0);
|
||||
currentEntityKey = ReadFieldString(ref reader, fields, 11, "");
|
||||
if (string.IsNullOrWhiteSpace(currentEntityKey))
|
||||
{
|
||||
currentEntityKey = LegacyCurrentEntityKey(runId, currentZoneIndex, legacyCurrentZoneEntityIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
discoveredZoneIndices = ReadFieldArray<int>(ref reader, fields, 5);
|
||||
zones = ReadFieldArray<AetheriaRuntimeZoneSnapshotCommit>(ref reader, fields, 6);
|
||||
actionBarBindings = ReadFieldArray<AetheriaRuntimeActionBarBindingCommit>(ref reader, fields, 7);
|
||||
factionRelationships = ReadFieldArray<AetheriaRuntimeFactionRelationshipCommit>(ref reader, fields, 8);
|
||||
generationSeed = ReadFieldUInt32(ref reader, fields, 9, 0);
|
||||
currentEntityKey = ReadFieldString(ref reader, fields, 10, "");
|
||||
}
|
||||
|
||||
return new AetheriaRuntimeRunCheckpointCommit
|
||||
{
|
||||
RunId = runId,
|
||||
IsTutorial = isTutorial,
|
||||
EntranceZoneIndex = entranceZoneIndex,
|
||||
ExitZoneIndex = exitZoneIndex,
|
||||
CurrentZoneIndex = currentZoneIndex,
|
||||
DiscoveredZoneIndices = discoveredZoneIndices,
|
||||
Zones = zones,
|
||||
ActionBarBindings = actionBarBindings,
|
||||
FactionRelationships = factionRelationships,
|
||||
GenerationSeed = generationSeed,
|
||||
CurrentEntityKey = currentEntityKey
|
||||
};
|
||||
}
|
||||
|
||||
private static string[] ReadSchemaCatalog(ref MessagePackReader reader)
|
||||
{
|
||||
var count = reader.ReadArrayHeader();
|
||||
var schemaIds = new string[count];
|
||||
for (var index = 0; index < count; index++)
|
||||
{
|
||||
var fieldCount = reader.ReadArrayHeader();
|
||||
schemaIds[index] = fieldCount > 0 ? reader.ReadString() ?? "" : "";
|
||||
for (var field = 1; field < fieldCount; field++)
|
||||
{
|
||||
reader.Skip();
|
||||
}
|
||||
}
|
||||
|
||||
return schemaIds;
|
||||
}
|
||||
|
||||
private static void WriteSchemaCatalogEntry(
|
||||
ref MessagePackWriter writer,
|
||||
string schemaId,
|
||||
string schemaName,
|
||||
string schemaVersion,
|
||||
byte[] payload)
|
||||
{
|
||||
writer.WriteArrayHeader(SchemaCatalogEntryFieldCount);
|
||||
writer.Write(schemaId);
|
||||
writer.Write(schemaName);
|
||||
writer.Write(schemaVersion);
|
||||
writer.Write(ContentHash(payload));
|
||||
writer.Write("");
|
||||
writer.WriteArrayHeader(0);
|
||||
writer.WriteArrayHeader(0);
|
||||
}
|
||||
|
||||
private static void WritePersistedRecord(
|
||||
ref MessagePackWriter writer,
|
||||
string key,
|
||||
string schemaId,
|
||||
string storedAt,
|
||||
byte[] payload)
|
||||
{
|
||||
writer.WriteArrayHeader(PersistedRecordFieldCount);
|
||||
writer.Write(key);
|
||||
writer.Write(schemaId);
|
||||
writer.Write(storedAt ?? "");
|
||||
writer.Write(payload);
|
||||
}
|
||||
|
||||
private static string ReadFieldString(ref MessagePackReader reader, int fields, int index, string fallback)
|
||||
{
|
||||
return index >= fields ? fallback : reader.ReadString() ?? fallback;
|
||||
}
|
||||
|
||||
private static int ReadFieldInt32(ref MessagePackReader reader, int fields, int index, int fallback)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return reader.ReadInt32();
|
||||
}
|
||||
|
||||
private static uint ReadFieldUInt32(ref MessagePackReader reader, int fields, int index, uint fallback)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return reader.ReadUInt32();
|
||||
}
|
||||
|
||||
private static bool ReadFieldBool(ref MessagePackReader reader, int fields, int index, bool fallback)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return fallback;
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return fallback;
|
||||
}
|
||||
|
||||
return reader.ReadBoolean();
|
||||
}
|
||||
|
||||
private static T[] ReadFieldArray<T>(ref MessagePackReader reader, int fields, int index)
|
||||
{
|
||||
if (index >= fields)
|
||||
{
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
|
||||
if (reader.NextMessagePackType == MessagePackType.Nil)
|
||||
{
|
||||
reader.ReadNil();
|
||||
return Array.Empty<T>();
|
||||
}
|
||||
|
||||
return MessagePackSerializer.Deserialize<T[]>(ReadRawBytes(ref reader)) ?? Array.Empty<T>();
|
||||
}
|
||||
|
||||
private static byte[] ReadRawBytes(ref MessagePackReader reader)
|
||||
{
|
||||
return reader.ReadRaw().ToArray();
|
||||
}
|
||||
|
||||
private static string LegacyCurrentEntityKey(string runId, int zoneIndex, int entityIndex)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(runId) || zoneIndex < 0 || entityIndex < 0)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
return $"global:aetheria.run_state.{runId}.zone.{zoneIndex}.entity.{entityIndex}.v1";
|
||||
}
|
||||
|
||||
private static string ContentHash(byte[] payload)
|
||||
{
|
||||
using var sha256 = SHA256.Create();
|
||||
return BitConverter.ToString(sha256.ComputeHash(payload)).Replace("-", "").ToLowerInvariant();
|
||||
}
|
||||
|
||||
private static void WriteFileAtomically(string path, byte[] payload)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(path);
|
||||
if (!string.IsNullOrWhiteSpace(directory))
|
||||
{
|
||||
Directory.CreateDirectory(directory);
|
||||
}
|
||||
|
||||
var tempPath = path + ".tmp";
|
||||
File.WriteAllBytes(tempPath, payload);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
|
||||
File.Move(tempPath, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cb5e0eb28b9776c4aad9f237dce09945
|
||||
|
|
@ -192,7 +192,7 @@ namespace GameCult.Aetheria.State.Unity
|
|||
("activeRun", settings.ActiveRunKey)),
|
||||
Text(
|
||||
"playerSettings.summary.note",
|
||||
"Input remapping lowers through the runtime Eve input screen and queues typed player-settings commits.")),
|
||||
"Input remapping lowers through the runtime Eve input screen and sends typed input-setting requests.")),
|
||||
Node(
|
||||
"aetheria.playerSettings.gameplay",
|
||||
"card",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7c8e6757ad932d94aa990bebad419106
|
||||
|
|
@ -0,0 +1,175 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeShipSettingsSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeShipSettingsSurfaceState(
|
||||
string shipName,
|
||||
string shutdownPerformance,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
ShipName = shipName ?? "";
|
||||
ShutdownPerformance = shutdownPerformance ?? "";
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string ShipName { get; }
|
||||
public string ShutdownPerformance { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeShipSettingsSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.inventory.current_ship_settings";
|
||||
public const string DecrementShutdownThreshold = "aetheria.inventory.current_ship_settings.shutdown.decrement";
|
||||
public const string IncrementShutdownThreshold = "aetheria.inventory.current_ship_settings.shutdown.increment";
|
||||
public const string ResetShutdownThreshold = "aetheria.inventory.current_ship_settings.shutdown.reset";
|
||||
public const string Close = "aetheria.inventory.current_ship_settings.close";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeShipSettingsSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeShipSettingsSurfaceState("", "", "");
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "inventory.menu",
|
||||
title: "Current Ship Settings",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Card(
|
||||
$"{SurfaceId}.card",
|
||||
state.ShipName,
|
||||
Metric(
|
||||
$"{SurfaceId}.shutdown.metric",
|
||||
"Shutdown Threshold",
|
||||
state.ShutdownPerformance),
|
||||
Text(
|
||||
$"{SurfaceId}.note",
|
||||
"Unity projects selected ship state; shutdown changes are sent as daemon operations."),
|
||||
ButtonRow(
|
||||
$"{SurfaceId}.shutdown.buttons",
|
||||
Button($"{SurfaceId}.shutdown.decrement", "Threshold -", DecrementShutdownThreshold),
|
||||
Button($"{SurfaceId}.shutdown.increment", "Threshold +", IncrementShutdownThreshold),
|
||||
Button($"{SurfaceId}.shutdown.reset", "Default", ResetShutdownThreshold),
|
||||
Button($"{SurfaceId}.close", "Close", Close)))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(DecrementShutdownThreshold, "Threshold -", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(IncrementShutdownThreshold, "Threshold +", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(ResetShutdownThreshold, "Default", "unity-uitoolkit"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit")
|
||||
});
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "control.row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeShipSettingsCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
DecrementShutdownThreshold = 1,
|
||||
IncrementShutdownThreshold = 2,
|
||||
ResetShutdownThreshold = 3,
|
||||
Close = 4
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeShipSettingsCommand
|
||||
{
|
||||
public AetheriaRuntimeShipSettingsCommand(AetheriaRuntimeShipSettingsCommandKind kind)
|
||||
{
|
||||
Kind = kind;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeShipSettingsCommandKind Kind { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeShipSettingsSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeShipSettingsCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeShipSettingsSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
switch (request.Command ?? "")
|
||||
{
|
||||
case AetheriaRuntimeShipSettingsSurfaceBuilder.DecrementShutdownThreshold:
|
||||
command = new AetheriaRuntimeShipSettingsCommand(
|
||||
AetheriaRuntimeShipSettingsCommandKind.DecrementShutdownThreshold);
|
||||
return true;
|
||||
case AetheriaRuntimeShipSettingsSurfaceBuilder.IncrementShutdownThreshold:
|
||||
command = new AetheriaRuntimeShipSettingsCommand(
|
||||
AetheriaRuntimeShipSettingsCommandKind.IncrementShutdownThreshold);
|
||||
return true;
|
||||
case AetheriaRuntimeShipSettingsSurfaceBuilder.ResetShutdownThreshold:
|
||||
command = new AetheriaRuntimeShipSettingsCommand(
|
||||
AetheriaRuntimeShipSettingsCommandKind.ResetShutdownThreshold);
|
||||
return true;
|
||||
case AetheriaRuntimeShipSettingsSurfaceBuilder.Close:
|
||||
command = new AetheriaRuntimeShipSettingsCommand(
|
||||
AetheriaRuntimeShipSettingsCommandKind.Close);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -5,65 +5,7 @@ using MessagePack;
|
|||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public enum AetheriaRuntimeCommitKind
|
||||
{
|
||||
PlayerSettings,
|
||||
LoadoutTemplate,
|
||||
RunCheckpoint
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeCommitEnvelope
|
||||
{
|
||||
public AetheriaRuntimeCommitEnvelope(
|
||||
string schema,
|
||||
AetheriaRuntimeCommitKind kind,
|
||||
string commandId,
|
||||
string createdAtUtc,
|
||||
string path)
|
||||
{
|
||||
Schema = schema;
|
||||
Kind = kind;
|
||||
CommandId = commandId;
|
||||
CreatedAtUtc = createdAtUtc;
|
||||
Path = path;
|
||||
}
|
||||
|
||||
public string Schema { get; }
|
||||
public AetheriaRuntimeCommitKind Kind { get; }
|
||||
public string CommandId { get; }
|
||||
public string CreatedAtUtc { get; }
|
||||
public string Path { get; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
public sealed class AetheriaRuntimeStateCommitDocument
|
||||
{
|
||||
public const string SchemaId = "gamecult.aetheria.runtime_commit.v1";
|
||||
|
||||
[Key(0)]
|
||||
public string Schema { get; set; } = SchemaId;
|
||||
|
||||
[Key(1)]
|
||||
public string Kind { get; set; } = "";
|
||||
|
||||
[Key(2)]
|
||||
public string CommandId { get; set; } = "";
|
||||
|
||||
[Key(3)]
|
||||
public string CreatedAtUtc { get; set; } = "";
|
||||
|
||||
[Key(4)]
|
||||
public AetheriaRuntimePlayerSettingsCommit? PlayerSettings { get; set; }
|
||||
|
||||
[Key(5)]
|
||||
public AetheriaRuntimeLoadoutTemplateCommit? LoadoutTemplate { get; set; }
|
||||
|
||||
[Key(6)]
|
||||
public AetheriaRuntimeRunCheckpointCommit? RunCheckpoint { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
{ [MessagePackObject]
|
||||
public sealed class AetheriaRuntimePlayerSettingsCommit
|
||||
{
|
||||
[Key(0)]
|
||||
|
|
@ -247,6 +189,9 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
[Key(10)]
|
||||
public string CurrentEntityKey { get; set; } = "";
|
||||
|
||||
[Key(11)]
|
||||
public int Credits { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
@ -644,6 +589,9 @@ namespace GameCult.Aetheria.State.Unity
|
|||
|
||||
[Key(36)]
|
||||
public string FactionKey { get; set; } = "";
|
||||
|
||||
[Key(37)]
|
||||
public double ShutdownPerformance { get; set; }
|
||||
}
|
||||
|
||||
[MessagePackObject]
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4f6e72cdd4fa40c498f05485e125efa2
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeStatRecipeCommands
|
||||
{
|
||||
public const string SurfaceId = "aetheria.statRecipes";
|
||||
|
||||
public const string Refresh = "aetheria.stat_recipes.refresh";
|
||||
public const string SelectStat = "aetheria.stat_recipes.select_stat";
|
||||
public const string AddStat = "aetheria.stat_recipes.add_stat";
|
||||
public const string RemoveStat = "aetheria.stat_recipes.remove_stat";
|
||||
public const string SetStatName = "aetheria.stat_recipes.set_stat_name";
|
||||
public const string SetBaseValue = "aetheria.stat_recipes.set_base_value";
|
||||
public const string ToggleCondition = "aetheria.stat_recipes.toggle_condition";
|
||||
public const string CycleInfluenceOperation = "aetheria.stat_recipes.cycle_influence_operation";
|
||||
public const string SetInfluenceAmount = "aetheria.stat_recipes.set_influence_amount";
|
||||
public const string SetInfluenceCurve = "aetheria.stat_recipes.set_influence_curve";
|
||||
public const string SetPreviewCondition = "aetheria.stat_recipes.set_preview_condition";
|
||||
|
||||
public static bool IsKnown(string command)
|
||||
{
|
||||
switch (command ?? "")
|
||||
{
|
||||
case Refresh:
|
||||
case SelectStat:
|
||||
case AddStat:
|
||||
case RemoveStat:
|
||||
case SetStatName:
|
||||
case SetBaseValue:
|
||||
case ToggleCondition:
|
||||
case CycleInfluenceOperation:
|
||||
case SetInfluenceAmount:
|
||||
case SetInfluenceCurve:
|
||||
case SetPreviewCondition:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8acd5987bf00dc44abaa44e90634c4d4
|
||||
|
|
@ -0,0 +1,713 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeStatRecipeSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeStatRecipeSurfaceState(
|
||||
IReadOnlyList<AetheriaRuntimeStatRecipeState> recipes,
|
||||
string selectedStatName,
|
||||
AetheriaRuntimeStatRecipePreviewState preview,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
Recipes = recipes ?? Array.Empty<AetheriaRuntimeStatRecipeState>();
|
||||
SelectedStatName = selectedStatName ?? "";
|
||||
Preview = preview ?? AetheriaRuntimeStatRecipePreviewState.Default;
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public IReadOnlyList<AetheriaRuntimeStatRecipeState> Recipes { get; }
|
||||
|
||||
public string SelectedStatName { get; }
|
||||
|
||||
public AetheriaRuntimeStatRecipePreviewState Preview { get; }
|
||||
|
||||
public string UpdatedAtUtc { get; }
|
||||
|
||||
public AetheriaRuntimeStatRecipeState SelectedRecipe =>
|
||||
Recipes.FirstOrDefault(recipe => string.Equals(recipe.StatName, SelectedStatName, StringComparison.Ordinal)) ??
|
||||
Recipes.FirstOrDefault();
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeStatRecipeState
|
||||
{
|
||||
public AetheriaRuntimeStatRecipeState(
|
||||
string recipeKey,
|
||||
string statName,
|
||||
double baseValue,
|
||||
IReadOnlyList<AetheriaRuntimeStatInfluenceState> influences)
|
||||
{
|
||||
RecipeKey = recipeKey ?? "";
|
||||
StatName = statName ?? "";
|
||||
BaseValue = baseValue;
|
||||
Influences = influences ?? Array.Empty<AetheriaRuntimeStatInfluenceState>();
|
||||
}
|
||||
|
||||
public string RecipeKey { get; }
|
||||
|
||||
public string StatName { get; }
|
||||
|
||||
public double BaseValue { get; }
|
||||
|
||||
public IReadOnlyList<AetheriaRuntimeStatInfluenceState> Influences { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeStatInfluenceState
|
||||
{
|
||||
public AetheriaRuntimeStatInfluenceState(
|
||||
string condition,
|
||||
string operation,
|
||||
double amount,
|
||||
string curveLabel,
|
||||
double previewSample,
|
||||
bool enabled)
|
||||
{
|
||||
Condition = condition ?? "";
|
||||
Operation = operation ?? AetheriaRuntimeStatRecipeOperations.Add;
|
||||
Amount = amount;
|
||||
CurveLabel = curveLabel ?? "";
|
||||
PreviewSample = previewSample;
|
||||
Enabled = enabled;
|
||||
}
|
||||
|
||||
public string Condition { get; }
|
||||
|
||||
public string Operation { get; }
|
||||
|
||||
public double Amount { get; }
|
||||
|
||||
public string CurveLabel { get; }
|
||||
|
||||
public double PreviewSample { get; }
|
||||
|
||||
public bool Enabled { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeStatRecipePreviewState
|
||||
{
|
||||
public static readonly AetheriaRuntimeStatRecipePreviewState Default =
|
||||
new AetheriaRuntimeStatRecipePreviewState(
|
||||
quality: 1,
|
||||
durability: 1,
|
||||
heat: 0,
|
||||
charge: 1,
|
||||
ammo: 1,
|
||||
range: 1,
|
||||
integrity: 1,
|
||||
pilotSkill: 0,
|
||||
environment: 0);
|
||||
|
||||
public AetheriaRuntimeStatRecipePreviewState(
|
||||
double quality,
|
||||
double durability,
|
||||
double heat,
|
||||
double charge,
|
||||
double ammo,
|
||||
double range,
|
||||
double integrity,
|
||||
double pilotSkill,
|
||||
double environment)
|
||||
{
|
||||
Quality = quality;
|
||||
Durability = durability;
|
||||
Heat = heat;
|
||||
Charge = charge;
|
||||
Ammo = ammo;
|
||||
Range = range;
|
||||
Integrity = integrity;
|
||||
PilotSkill = pilotSkill;
|
||||
Environment = environment;
|
||||
}
|
||||
|
||||
public double Quality { get; }
|
||||
|
||||
public double Durability { get; }
|
||||
|
||||
public double Heat { get; }
|
||||
|
||||
public double Charge { get; }
|
||||
|
||||
public double Ammo { get; }
|
||||
|
||||
public double Range { get; }
|
||||
|
||||
public double Integrity { get; }
|
||||
|
||||
public double PilotSkill { get; }
|
||||
|
||||
public double Environment { get; }
|
||||
|
||||
public double GetConditionValue(string condition)
|
||||
{
|
||||
switch (condition ?? "")
|
||||
{
|
||||
case AetheriaRuntimeStatRecipeConditions.Quality:
|
||||
return Quality;
|
||||
case AetheriaRuntimeStatRecipeConditions.Durability:
|
||||
return Durability;
|
||||
case AetheriaRuntimeStatRecipeConditions.Heat:
|
||||
return Heat;
|
||||
case AetheriaRuntimeStatRecipeConditions.Charge:
|
||||
return Charge;
|
||||
case AetheriaRuntimeStatRecipeConditions.Ammo:
|
||||
return Ammo;
|
||||
case AetheriaRuntimeStatRecipeConditions.Range:
|
||||
return Range;
|
||||
case AetheriaRuntimeStatRecipeConditions.Integrity:
|
||||
return Integrity;
|
||||
case AetheriaRuntimeStatRecipeConditions.PilotSkill:
|
||||
return PilotSkill;
|
||||
case AetheriaRuntimeStatRecipeConditions.Environment:
|
||||
return Environment;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeStatRecipeConditions
|
||||
{
|
||||
public const string Quality = "quality";
|
||||
public const string Durability = "durability";
|
||||
public const string Heat = "heat";
|
||||
public const string Charge = "charge";
|
||||
public const string Ammo = "ammo";
|
||||
public const string Range = "range";
|
||||
public const string Integrity = "integrity";
|
||||
public const string PilotSkill = "pilotSkill";
|
||||
public const string Environment = "environment";
|
||||
|
||||
public static readonly IReadOnlyList<string> All = new[]
|
||||
{
|
||||
Quality,
|
||||
Durability,
|
||||
Heat,
|
||||
Charge,
|
||||
Ammo,
|
||||
Range,
|
||||
Integrity,
|
||||
PilotSkill,
|
||||
Environment
|
||||
};
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeStatRecipeOperations
|
||||
{
|
||||
public const string Add = "add";
|
||||
public const string Multiply = "multiply";
|
||||
public const string Override = "override";
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeStatRecipeSurfaceBuilder
|
||||
{
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeStatRecipeSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeStatRecipeSurfaceState(
|
||||
Array.Empty<AetheriaRuntimeStatRecipeState>(),
|
||||
"",
|
||||
AetheriaRuntimeStatRecipePreviewState.Default,
|
||||
"");
|
||||
|
||||
var selected = state.SelectedRecipe;
|
||||
var previewValue = selected == null ? 0 : EvaluatePreview(selected, state.Preview);
|
||||
var enabledInfluenceCount = selected?.Influences.Count(influence => influence.Enabled) ?? 0;
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "game.design",
|
||||
title: "Aetheria Stat Recipes",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
AetheriaRuntimeStatRecipeCommands.SurfaceId,
|
||||
Node(
|
||||
"aetheria.statRecipes.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
BuildSummaryCard(selected, previewValue, enabledInfluenceCount),
|
||||
BuildRecipeList(state, selected),
|
||||
BuildSelectedRecipeCard(selected),
|
||||
BuildConditionPalette(selected),
|
||||
BuildInfluenceList(selected, state.Preview),
|
||||
BuildPreviewCard(state.Preview)),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: BuildCommandTemplates());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildSummaryCard(
|
||||
AetheriaRuntimeStatRecipeState selected,
|
||||
double previewValue,
|
||||
int enabledInfluenceCount)
|
||||
{
|
||||
var statName = string.IsNullOrWhiteSpace(selected?.StatName) ? "No stat selected" : selected.StatName;
|
||||
|
||||
return Node(
|
||||
"aetheria.statRecipes.summary",
|
||||
"card",
|
||||
new[] { ("title", "Stat Recipe") },
|
||||
Metric("aetheria.statRecipes.summary.stat", "Selected Stat", statName),
|
||||
Metric("aetheria.statRecipes.summary.base", "Base", Format(selected?.BaseValue ?? 0)),
|
||||
Metric("aetheria.statRecipes.summary.preview", "Preview", Format(previewValue)),
|
||||
Metric("aetheria.statRecipes.summary.influences", "Active Conditions", enabledInfluenceCount.ToString()),
|
||||
Text(
|
||||
"aetheria.statRecipes.summary.note",
|
||||
"Each recipe owns only the conditions it actually cares about; runtime evaluation can sample those modifiers instead of walking every global performance axis."));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildRecipeList(
|
||||
AetheriaRuntimeStatRecipeSurfaceState state,
|
||||
AetheriaRuntimeStatRecipeState selected)
|
||||
{
|
||||
var children = state.Recipes
|
||||
.Select((recipe, index) => Button(
|
||||
$"aetheria.statRecipes.recipe.{index}.select",
|
||||
string.Equals(recipe.StatName, selected?.StatName, StringComparison.Ordinal) ? $"{recipe.StatName} (Selected)" : recipe.StatName,
|
||||
AetheriaRuntimeStatRecipeCommands.SelectStat,
|
||||
("recipeKey", recipe.RecipeKey),
|
||||
("statName", recipe.StatName)))
|
||||
.Concat(new[]
|
||||
{
|
||||
Button(
|
||||
"aetheria.statRecipes.recipe.add",
|
||||
"Add Stat",
|
||||
AetheriaRuntimeStatRecipeCommands.AddStat)
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return Node(
|
||||
"aetheria.statRecipes.recipes",
|
||||
"card",
|
||||
new[] { ("title", "Recipes") },
|
||||
Node("aetheria.statRecipes.recipes.list", "grid", Array.Empty<(string Key, string Value)>(), children));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildSelectedRecipeCard(AetheriaRuntimeStatRecipeState selected)
|
||||
{
|
||||
if (selected == null)
|
||||
{
|
||||
return Node(
|
||||
"aetheria.statRecipes.selected",
|
||||
"card",
|
||||
new[] { ("title", "Selected Recipe") },
|
||||
Text("aetheria.statRecipes.selected.empty", "Add or select a stat recipe to start authoring modifiers."));
|
||||
}
|
||||
|
||||
return Node(
|
||||
"aetheria.statRecipes.selected",
|
||||
"card",
|
||||
new[] { ("title", "Selected Recipe") },
|
||||
TextInput(
|
||||
"aetheria.statRecipes.selected.name",
|
||||
"Stat Name",
|
||||
selected.StatName,
|
||||
AetheriaRuntimeStatRecipeCommands.SetStatName,
|
||||
("recipeKey", selected.RecipeKey),
|
||||
("statName", selected.StatName)),
|
||||
NumberInput(
|
||||
"aetheria.statRecipes.selected.base",
|
||||
"Base Value",
|
||||
selected.BaseValue,
|
||||
AetheriaRuntimeStatRecipeCommands.SetBaseValue,
|
||||
("recipeKey", selected.RecipeKey),
|
||||
("statName", selected.StatName)),
|
||||
ButtonRow(
|
||||
"aetheria.statRecipes.selected.actions",
|
||||
Button(
|
||||
"aetheria.statRecipes.selected.remove",
|
||||
"Remove Stat",
|
||||
AetheriaRuntimeStatRecipeCommands.RemoveStat,
|
||||
("recipeKey", selected.RecipeKey),
|
||||
("statName", selected.StatName)),
|
||||
Button(
|
||||
"aetheria.statRecipes.selected.refresh",
|
||||
"Refresh",
|
||||
AetheriaRuntimeStatRecipeCommands.Refresh)));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildConditionPalette(AetheriaRuntimeStatRecipeState selected)
|
||||
{
|
||||
var children = AetheriaRuntimeStatRecipeConditions.All
|
||||
.Select(condition =>
|
||||
{
|
||||
var influence = selected?.Influences.FirstOrDefault(candidate => string.Equals(candidate.Condition, condition, StringComparison.Ordinal));
|
||||
var enabled = influence?.Enabled ?? false;
|
||||
|
||||
return Toggle(
|
||||
$"aetheria.statRecipes.conditions.{condition}",
|
||||
ConditionLabel(condition),
|
||||
enabled,
|
||||
AetheriaRuntimeStatRecipeCommands.ToggleCondition,
|
||||
("recipeKey", selected?.RecipeKey ?? ""),
|
||||
("statName", selected?.StatName ?? ""),
|
||||
("condition", condition),
|
||||
("enabled", enabled ? "false" : "true"));
|
||||
})
|
||||
.ToArray();
|
||||
|
||||
return Node(
|
||||
"aetheria.statRecipes.conditions",
|
||||
"card",
|
||||
new[] { ("title", "Affected By") },
|
||||
Node("aetheria.statRecipes.conditions.grid", "grid", Array.Empty<(string Key, string Value)>(), children));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildInfluenceList(
|
||||
AetheriaRuntimeStatRecipeState selected,
|
||||
AetheriaRuntimeStatRecipePreviewState preview)
|
||||
{
|
||||
if (selected == null || selected.Influences.Count == 0)
|
||||
{
|
||||
return Node(
|
||||
"aetheria.statRecipes.influences",
|
||||
"card",
|
||||
new[] { ("title", "Modifiers") },
|
||||
Text("aetheria.statRecipes.influences.empty", "Choose a condition above to create the first modifier for this stat."));
|
||||
}
|
||||
|
||||
return Node(
|
||||
"aetheria.statRecipes.influences",
|
||||
"card",
|
||||
new[] { ("title", "Modifiers") },
|
||||
Node(
|
||||
"aetheria.statRecipes.influences.grid",
|
||||
"grid",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
selected.Influences.Select(influence => BuildInfluenceCard(selected, influence, preview)).ToArray()));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildInfluenceCard(
|
||||
AetheriaRuntimeStatRecipeState recipe,
|
||||
AetheriaRuntimeStatInfluenceState influence,
|
||||
AetheriaRuntimeStatRecipePreviewState preview)
|
||||
{
|
||||
var conditionValue = preview.GetConditionValue(influence.Condition);
|
||||
var sample = ResolvePreviewSample(influence, conditionValue);
|
||||
|
||||
return Node(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}",
|
||||
"card",
|
||||
new[] { ("title", ConditionLabel(influence.Condition)) },
|
||||
Metric(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}.operation",
|
||||
"Operation",
|
||||
OperationLabel(influence.Operation)),
|
||||
NumberInput(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}.amount",
|
||||
"Amount",
|
||||
influence.Amount,
|
||||
AetheriaRuntimeStatRecipeCommands.SetInfluenceAmount,
|
||||
("recipeKey", recipe.RecipeKey),
|
||||
("statName", recipe.StatName),
|
||||
("condition", influence.Condition)),
|
||||
TextInput(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}.curve",
|
||||
"Curve",
|
||||
influence.CurveLabel,
|
||||
AetheriaRuntimeStatRecipeCommands.SetInfluenceCurve,
|
||||
("recipeKey", recipe.RecipeKey),
|
||||
("statName", recipe.StatName),
|
||||
("condition", influence.Condition)),
|
||||
Metric(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}.sample",
|
||||
"Preview Sample",
|
||||
Format(sample)),
|
||||
ButtonRow(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}.actions",
|
||||
Button(
|
||||
$"aetheria.statRecipes.influence.{StableToken(recipe.RecipeKey)}.{influence.Condition}.operation.cycle",
|
||||
"Cycle Operation",
|
||||
AetheriaRuntimeStatRecipeCommands.CycleInfluenceOperation,
|
||||
("recipeKey", recipe.RecipeKey),
|
||||
("statName", recipe.StatName),
|
||||
("condition", influence.Condition))));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent BuildPreviewCard(AetheriaRuntimeStatRecipePreviewState preview)
|
||||
{
|
||||
return Node(
|
||||
"aetheria.statRecipes.preview",
|
||||
"card",
|
||||
new[] { ("title", "Preview Context") },
|
||||
Node(
|
||||
"aetheria.statRecipes.preview.grid",
|
||||
"grid",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
AetheriaRuntimeStatRecipeConditions.All
|
||||
.Select(condition => Slider(
|
||||
$"aetheria.statRecipes.preview.{condition}",
|
||||
ConditionLabel(condition),
|
||||
preview.GetConditionValue(condition),
|
||||
0,
|
||||
1,
|
||||
AetheriaRuntimeStatRecipeCommands.SetPreviewCondition,
|
||||
("condition", condition)))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
private static IReadOnlyList<AetheriaRuntimeSurfaceCommandTemplate> BuildCommandTemplates()
|
||||
{
|
||||
return new[]
|
||||
{
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.Refresh, "Refresh", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.SelectStat, "Select Stat", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.AddStat, "Add Stat", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.RemoveStat, "Remove Stat", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.SetStatName, "Set Stat Name", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.SetBaseValue, "Set Base Value", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.ToggleCondition, "Toggle Condition", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.CycleInfluenceOperation, "Cycle Operation", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.SetInfluenceAmount, "Set Influence Amount", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.SetInfluenceCurve, "Set Influence Curve", "cultmesh"),
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(AetheriaRuntimeStatRecipeCommands.SetPreviewCondition, "Set Preview Condition", "cultmesh")
|
||||
};
|
||||
}
|
||||
|
||||
private static double EvaluatePreview(
|
||||
AetheriaRuntimeStatRecipeState recipe,
|
||||
AetheriaRuntimeStatRecipePreviewState preview)
|
||||
{
|
||||
var value = recipe.BaseValue;
|
||||
|
||||
foreach (var influence in recipe.Influences.Where(influence => influence.Enabled))
|
||||
{
|
||||
var sample = ResolvePreviewSample(influence, preview.GetConditionValue(influence.Condition));
|
||||
switch (influence.Operation)
|
||||
{
|
||||
case AetheriaRuntimeStatRecipeOperations.Multiply:
|
||||
value *= 1 + ((influence.Amount - 1) * sample);
|
||||
break;
|
||||
case AetheriaRuntimeStatRecipeOperations.Override:
|
||||
value = Lerp(value, influence.Amount, sample);
|
||||
break;
|
||||
default:
|
||||
value += influence.Amount * sample;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
private static double ResolvePreviewSample(
|
||||
AetheriaRuntimeStatInfluenceState influence,
|
||||
double conditionValue)
|
||||
{
|
||||
if (influence.PreviewSample > 0)
|
||||
return Clamp01(influence.PreviewSample);
|
||||
|
||||
return Clamp01(conditionValue);
|
||||
}
|
||||
|
||||
private static double Clamp01(double value)
|
||||
{
|
||||
if (value < 0)
|
||||
return 0;
|
||||
if (value > 1)
|
||||
return 1;
|
||||
return value;
|
||||
}
|
||||
|
||||
private static double Lerp(double from, double to, double sample)
|
||||
{
|
||||
return from + ((to - from) * Clamp01(sample));
|
||||
}
|
||||
|
||||
private static string Format(double value)
|
||||
{
|
||||
return value.ToString("0.###", CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private static string ConditionLabel(string condition)
|
||||
{
|
||||
switch (condition ?? "")
|
||||
{
|
||||
case AetheriaRuntimeStatRecipeConditions.Quality:
|
||||
return "Quality";
|
||||
case AetheriaRuntimeStatRecipeConditions.Durability:
|
||||
return "Durability";
|
||||
case AetheriaRuntimeStatRecipeConditions.Heat:
|
||||
return "Heat";
|
||||
case AetheriaRuntimeStatRecipeConditions.Charge:
|
||||
return "Charge";
|
||||
case AetheriaRuntimeStatRecipeConditions.Ammo:
|
||||
return "Ammo";
|
||||
case AetheriaRuntimeStatRecipeConditions.Range:
|
||||
return "Range";
|
||||
case AetheriaRuntimeStatRecipeConditions.Integrity:
|
||||
return "Integrity";
|
||||
case AetheriaRuntimeStatRecipeConditions.PilotSkill:
|
||||
return "Pilot Skill";
|
||||
case AetheriaRuntimeStatRecipeConditions.Environment:
|
||||
return "Environment";
|
||||
default:
|
||||
return condition ?? "";
|
||||
}
|
||||
}
|
||||
|
||||
private static string OperationLabel(string operation)
|
||||
{
|
||||
switch (operation ?? "")
|
||||
{
|
||||
case AetheriaRuntimeStatRecipeOperations.Multiply:
|
||||
return "Multiply";
|
||||
case AetheriaRuntimeStatRecipeOperations.Override:
|
||||
return "Override";
|
||||
default:
|
||||
return "Add";
|
||||
}
|
||||
}
|
||||
|
||||
private static string StableToken(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "none";
|
||||
|
||||
return new string(value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? character : '_')
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(
|
||||
string id,
|
||||
string label,
|
||||
string command,
|
||||
params (string Key, string Value)[] extraProps)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("command", command ?? "")
|
||||
};
|
||||
if (extraProps != null)
|
||||
{
|
||||
props.AddRange(extraProps);
|
||||
}
|
||||
|
||||
return Node(id, "control.button", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Toggle(
|
||||
string id,
|
||||
string label,
|
||||
bool value,
|
||||
string command,
|
||||
params (string Key, string Value)[] extraProps)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("value", value ? "true" : "false"),
|
||||
("command", command ?? "")
|
||||
};
|
||||
if (extraProps != null)
|
||||
{
|
||||
props.AddRange(extraProps);
|
||||
}
|
||||
|
||||
return Node(id, "control.toggle", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Slider(
|
||||
string id,
|
||||
string label,
|
||||
double value,
|
||||
double min,
|
||||
double max,
|
||||
string command,
|
||||
params (string Key, string Value)[] extraProps)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("value", Format(value)),
|
||||
("min", Format(min)),
|
||||
("max", Format(max)),
|
||||
("command", command ?? "")
|
||||
};
|
||||
if (extraProps != null)
|
||||
{
|
||||
props.AddRange(extraProps);
|
||||
}
|
||||
|
||||
return Node(id, "control.slider", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent NumberInput(
|
||||
string id,
|
||||
string label,
|
||||
double value,
|
||||
string command,
|
||||
params (string Key, string Value)[] extraProps)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("value", Format(value)),
|
||||
("command", command ?? ""),
|
||||
("valueKind", "number")
|
||||
};
|
||||
if (extraProps != null)
|
||||
{
|
||||
props.AddRange(extraProps);
|
||||
}
|
||||
|
||||
return Node(id, "control.text", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent TextInput(
|
||||
string id,
|
||||
string label,
|
||||
string value,
|
||||
string command,
|
||||
params (string Key, string Value)[] extraProps)
|
||||
{
|
||||
var props = new List<(string Key, string Value)>
|
||||
{
|
||||
("label", label ?? ""),
|
||||
("value", value ?? ""),
|
||||
("command", command ?? "")
|
||||
};
|
||||
if (extraProps != null)
|
||||
{
|
||||
props.AddRange(extraProps);
|
||||
}
|
||||
|
||||
return Node(id, "control.text", props);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id,
|
||||
kind,
|
||||
props.ToDictionary(prop => prop.Key, prop => prop.Value, StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c630337961a252149a6e9db3d7513ee0
|
||||
|
|
@ -0,0 +1,363 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeStatRecipes
|
||||
{
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState Refresh(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
return With(state, state.Recipes, state.SelectedStatName, state.Preview, Stamp(updatedAtUtc));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SelectStat(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
var recipe = FindRecipe(state, recipeKey, statName);
|
||||
return recipe == null
|
||||
? state
|
||||
: With(state, state.Recipes, recipe.StatName, state.Preview, Stamp(updatedAtUtc));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState AddStat(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string statName,
|
||||
string recipeKey = "",
|
||||
double baseValue = 0,
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
recipeKey = string.IsNullOrWhiteSpace(recipeKey) ? $"design:{Guid.NewGuid():N}" : recipeKey;
|
||||
var recipe = new AetheriaRuntimeStatRecipeState(
|
||||
recipeKey,
|
||||
string.IsNullOrWhiteSpace(statName) ? "New Stat Recipe" : statName,
|
||||
baseValue,
|
||||
Array.Empty<AetheriaRuntimeStatInfluenceState>());
|
||||
|
||||
return With(
|
||||
state,
|
||||
state.Recipes.Concat(new[] { recipe }).ToArray(),
|
||||
recipe.StatName,
|
||||
state.Preview,
|
||||
Stamp(updatedAtUtc));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState RemoveStat(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
var recipe = FindRecipe(state, recipeKey, statName);
|
||||
if (recipe == null)
|
||||
return state;
|
||||
|
||||
var remaining = state.Recipes
|
||||
.Where(candidate => !SameRecipe(candidate, recipe))
|
||||
.ToArray();
|
||||
return With(
|
||||
state,
|
||||
remaining,
|
||||
remaining.FirstOrDefault()?.StatName ?? "",
|
||||
state.Preview,
|
||||
Stamp(updatedAtUtc));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SetStatName(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string statName,
|
||||
string? currentStatName = null,
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
return UpdateRecipe(state, recipeKey, currentStatName ?? "", Stamp(updatedAtUtc), recipe =>
|
||||
new AetheriaRuntimeStatRecipeState(
|
||||
recipe.RecipeKey,
|
||||
statName ?? "",
|
||||
recipe.BaseValue,
|
||||
recipe.Influences));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SetBaseValue(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
double baseValue,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
return UpdateRecipe(state, recipeKey, statName, Stamp(updatedAtUtc), recipe =>
|
||||
new AetheriaRuntimeStatRecipeState(
|
||||
recipe.RecipeKey,
|
||||
recipe.StatName,
|
||||
baseValue,
|
||||
recipe.Influences));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SetConditionEnabled(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string condition,
|
||||
bool enabled,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
return UpsertInfluence(
|
||||
state,
|
||||
recipeKey,
|
||||
statName,
|
||||
condition,
|
||||
Stamp(updatedAtUtc),
|
||||
influence => new AetheriaRuntimeStatInfluenceState(
|
||||
influence.Condition,
|
||||
influence.Operation,
|
||||
influence.Amount,
|
||||
influence.CurveLabel,
|
||||
influence.PreviewSample,
|
||||
enabled),
|
||||
enabled);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState ToggleCondition(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string condition,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
var recipe = FindRecipe(state, recipeKey, statName);
|
||||
var current = recipe?.Influences.FirstOrDefault(influence =>
|
||||
string.Equals(influence.Condition, NormalizeCondition(condition), StringComparison.Ordinal));
|
||||
return SetConditionEnabled(
|
||||
state,
|
||||
recipeKey,
|
||||
condition,
|
||||
current == null || !current.Enabled,
|
||||
statName,
|
||||
updatedAtUtc);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState CycleInfluenceOperation(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string condition,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
return UpsertInfluence(state, recipeKey, statName, condition, Stamp(updatedAtUtc), influence =>
|
||||
new AetheriaRuntimeStatInfluenceState(
|
||||
influence.Condition,
|
||||
NextOperation(influence.Operation),
|
||||
influence.Amount,
|
||||
influence.CurveLabel,
|
||||
influence.PreviewSample,
|
||||
influence.Enabled));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SetInfluenceAmount(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string condition,
|
||||
double amount,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
return UpsertInfluence(state, recipeKey, statName, condition, Stamp(updatedAtUtc), influence =>
|
||||
new AetheriaRuntimeStatInfluenceState(
|
||||
influence.Condition,
|
||||
influence.Operation,
|
||||
amount,
|
||||
influence.CurveLabel,
|
||||
influence.PreviewSample,
|
||||
influence.Enabled));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SetInfluenceCurve(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string condition,
|
||||
string curveLabel,
|
||||
string statName = "",
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
return UpsertInfluence(state, recipeKey, statName, condition, Stamp(updatedAtUtc), influence =>
|
||||
new AetheriaRuntimeStatInfluenceState(
|
||||
influence.Condition,
|
||||
influence.Operation,
|
||||
influence.Amount,
|
||||
curveLabel ?? "",
|
||||
influence.PreviewSample,
|
||||
influence.Enabled));
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStatRecipeSurfaceState SetPreviewCondition(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string condition,
|
||||
double value,
|
||||
string? updatedAtUtc = null)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
condition = NormalizeCondition(condition);
|
||||
if (string.IsNullOrWhiteSpace(condition))
|
||||
return state;
|
||||
|
||||
var preview = state.Preview;
|
||||
var next = condition switch
|
||||
{
|
||||
AetheriaRuntimeStatRecipeConditions.Quality => new AetheriaRuntimeStatRecipePreviewState(value, preview.Durability, preview.Heat, preview.Charge, preview.Ammo, preview.Range, preview.Integrity, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Durability => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, value, preview.Heat, preview.Charge, preview.Ammo, preview.Range, preview.Integrity, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Heat => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, value, preview.Charge, preview.Ammo, preview.Range, preview.Integrity, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Charge => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, preview.Heat, value, preview.Ammo, preview.Range, preview.Integrity, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Ammo => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, preview.Heat, preview.Charge, value, preview.Range, preview.Integrity, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Range => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, preview.Heat, preview.Charge, preview.Ammo, value, preview.Integrity, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Integrity => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, preview.Heat, preview.Charge, preview.Ammo, preview.Range, value, preview.PilotSkill, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.PilotSkill => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, preview.Heat, preview.Charge, preview.Ammo, preview.Range, preview.Integrity, value, preview.Environment),
|
||||
AetheriaRuntimeStatRecipeConditions.Environment => new AetheriaRuntimeStatRecipePreviewState(preview.Quality, preview.Durability, preview.Heat, preview.Charge, preview.Ammo, preview.Range, preview.Integrity, preview.PilotSkill, value),
|
||||
_ => preview
|
||||
};
|
||||
|
||||
return With(state, state.Recipes, state.SelectedStatName, next, Stamp(updatedAtUtc));
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeSurfaceState UpsertInfluence(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string statName,
|
||||
string condition,
|
||||
string updatedAtUtc,
|
||||
Func<AetheriaRuntimeStatInfluenceState, AetheriaRuntimeStatInfluenceState> update,
|
||||
bool defaultEnabled = true)
|
||||
{
|
||||
condition = NormalizeCondition(condition);
|
||||
if (string.IsNullOrWhiteSpace(condition))
|
||||
return state ?? EmptyState();
|
||||
|
||||
return UpdateRecipe(state, recipeKey, statName, updatedAtUtc, recipe =>
|
||||
{
|
||||
var influences = recipe.Influences.ToList();
|
||||
var index = influences.FindIndex(influence => string.Equals(influence.Condition, condition, StringComparison.Ordinal));
|
||||
var current = index >= 0
|
||||
? influences[index]
|
||||
: new AetheriaRuntimeStatInfluenceState(
|
||||
condition,
|
||||
AetheriaRuntimeStatRecipeOperations.Add,
|
||||
0,
|
||||
"linear",
|
||||
0,
|
||||
defaultEnabled);
|
||||
var next = update(current);
|
||||
|
||||
if (index >= 0)
|
||||
influences[index] = next;
|
||||
else
|
||||
influences.Add(next);
|
||||
|
||||
return new AetheriaRuntimeStatRecipeState(recipe.RecipeKey, recipe.StatName, recipe.BaseValue, influences);
|
||||
});
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeSurfaceState UpdateRecipe(
|
||||
AetheriaRuntimeStatRecipeSurfaceState? state,
|
||||
string recipeKey,
|
||||
string statName,
|
||||
string updatedAtUtc,
|
||||
Func<AetheriaRuntimeStatRecipeState, AetheriaRuntimeStatRecipeState> update)
|
||||
{
|
||||
state ??= EmptyState();
|
||||
var target = FindRecipe(state, recipeKey, statName);
|
||||
if (target == null)
|
||||
return state;
|
||||
|
||||
var recipes = state.Recipes
|
||||
.Select(recipe => SameRecipe(recipe, target) ? update(recipe) : recipe)
|
||||
.ToArray();
|
||||
var selected = recipes.FirstOrDefault(recipe => string.Equals(recipe.RecipeKey, target.RecipeKey, StringComparison.Ordinal))
|
||||
?? recipes.FirstOrDefault(recipe => string.Equals(recipe.StatName, target.StatName, StringComparison.Ordinal));
|
||||
|
||||
return With(state, recipes, selected?.StatName ?? state.SelectedStatName, state.Preview, updatedAtUtc);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeSurfaceState With(
|
||||
AetheriaRuntimeStatRecipeSurfaceState state,
|
||||
IReadOnlyList<AetheriaRuntimeStatRecipeState> recipes,
|
||||
string selectedStatName,
|
||||
AetheriaRuntimeStatRecipePreviewState preview,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
return new AetheriaRuntimeStatRecipeSurfaceState(
|
||||
recipes,
|
||||
selectedStatName,
|
||||
preview ?? state.Preview,
|
||||
updatedAtUtc);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeState? FindRecipe(
|
||||
AetheriaRuntimeStatRecipeSurfaceState state,
|
||||
string recipeKey,
|
||||
string statName)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(recipeKey))
|
||||
{
|
||||
var byKey = state.Recipes.FirstOrDefault(recipe => string.Equals(recipe.RecipeKey, recipeKey, StringComparison.Ordinal));
|
||||
if (byKey != null)
|
||||
return byKey;
|
||||
}
|
||||
|
||||
statName = string.IsNullOrWhiteSpace(statName) ? state.SelectedStatName : statName;
|
||||
return state.Recipes.FirstOrDefault(recipe => string.Equals(recipe.StatName, statName, StringComparison.Ordinal))
|
||||
?? state.SelectedRecipe;
|
||||
}
|
||||
|
||||
private static bool SameRecipe(AetheriaRuntimeStatRecipeState left, AetheriaRuntimeStatRecipeState right)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(left.RecipeKey) || !string.IsNullOrWhiteSpace(right.RecipeKey))
|
||||
return string.Equals(left.RecipeKey, right.RecipeKey, StringComparison.Ordinal);
|
||||
|
||||
return string.Equals(left.StatName, right.StatName, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static string NormalizeCondition(string condition)
|
||||
{
|
||||
return AetheriaRuntimeStatRecipeConditions.All.FirstOrDefault(candidate =>
|
||||
string.Equals(candidate, condition, StringComparison.OrdinalIgnoreCase)) ?? "";
|
||||
}
|
||||
|
||||
private static string NextOperation(string operation)
|
||||
{
|
||||
switch (operation ?? "")
|
||||
{
|
||||
case AetheriaRuntimeStatRecipeOperations.Add:
|
||||
return AetheriaRuntimeStatRecipeOperations.Multiply;
|
||||
case AetheriaRuntimeStatRecipeOperations.Multiply:
|
||||
return AetheriaRuntimeStatRecipeOperations.Override;
|
||||
default:
|
||||
return AetheriaRuntimeStatRecipeOperations.Add;
|
||||
}
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeStatRecipeSurfaceState EmptyState()
|
||||
{
|
||||
return new AetheriaRuntimeStatRecipeSurfaceState(
|
||||
Array.Empty<AetheriaRuntimeStatRecipeState>(),
|
||||
"",
|
||||
AetheriaRuntimeStatRecipePreviewState.Default,
|
||||
"");
|
||||
}
|
||||
|
||||
private static string Stamp(string? updatedAtUtc)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(updatedAtUtc) ? DateTime.UtcNow.ToString("O") : updatedAtUtc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 2c0bbe678cc85f44abfef1c7c2ab4cfb
|
||||
|
|
@ -8,6 +8,15 @@ namespace GameCult.Aetheria.State.Unity
|
|||
public const string RuntimeStateFileName = "aetheria-world.cc";
|
||||
public const string RuntimeClientTargetFileName = "aetheria-client.cc";
|
||||
public const string RuntimeReplicaDirectoryName = "Verses";
|
||||
public const string RuntimeDaemonFrameFileSuffix = ".daemon.frame.cc";
|
||||
public const string RuntimeDaemonSoaViewFileSuffix = ".daemon.soa.cc";
|
||||
public const string RuntimeDaemonProviderFileSuffix = ".daemon.provider.cc";
|
||||
public const string RuntimeDaemonHealthFileSuffix = ".daemon.health.cc";
|
||||
public const string RuntimeDaemonCommandBoundaryFileSuffix = ".daemon.commands.cc";
|
||||
public const string RuntimeDaemonGameSurfaceFileSuffix = ".daemon.game.eve.cc";
|
||||
public const string RuntimeDaemonGameTuiSurfaceFileSuffix = ".daemon.game.tui.cc";
|
||||
public const string RuntimeDaemonEditorSurfaceFileSuffix = ".daemon.editor.eve.cc";
|
||||
public const string RuntimeDaemonEditorTuiSurfaceFileSuffix = ".daemon.editor.tui.cc";
|
||||
public const string RuntimeStatePathOverrideEnvironmentVariable = "AETHERIA_STATE_PATH";
|
||||
public const string LegacyRuntimeStatePathOverrideEnvironmentVariable = "AETHERIA_EVE_STATE_PATH";
|
||||
|
||||
|
|
@ -21,6 +30,51 @@ namespace GameCult.Aetheria.State.Unity
|
|||
return Path.Combine(gameDataDirectory.FullName, RuntimeClientTargetFileName);
|
||||
}
|
||||
|
||||
public static string GetDaemonFramePath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonFrameFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonSoaViewPath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonSoaViewFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonProviderPath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonProviderFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonHealthPath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonHealthFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonCommandBoundaryPath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonCommandBoundaryFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonGameSurfacePath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonGameSurfaceFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonGameTuiSurfacePath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonGameTuiSurfaceFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonEditorSurfacePath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonEditorSurfaceFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetDaemonEditorTuiSurfacePath(string stateFilePath)
|
||||
{
|
||||
return stateFilePath + RuntimeDaemonEditorTuiSurfaceFileSuffix;
|
||||
}
|
||||
|
||||
public static string GetReplicaStateFilePath(DirectoryInfo gameDataDirectory, string verseId)
|
||||
{
|
||||
var safeVerseId = string.IsNullOrWhiteSpace(verseId)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7efc611cb12d9944592855511d71ea9a
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3a889a3c5631c5f41ad856f8563395f7
|
||||
|
|
@ -1,125 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public static class AetheriaRuntimeStateCommitLog
|
||||
{
|
||||
public const string CommitSchema = AetheriaRuntimeStateCommitDocument.SchemaId;
|
||||
|
||||
public static string GetPendingDirectory(string stateFilePath)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(stateFilePath))
|
||||
throw new ArgumentException("State file path must be non-empty.", nameof(stateFilePath));
|
||||
|
||||
return stateFilePath + ".pending";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeCommitEnvelope QueuePlayerSettings(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimePlayerSettingsCommit settings)
|
||||
{
|
||||
if (settings == null) throw new ArgumentNullException(nameof(settings));
|
||||
return WriteCommit(stateFilePath, AetheriaRuntimeCommitKind.PlayerSettings, document => document.PlayerSettings = settings);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeCommitEnvelope QueueLoadoutTemplate(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeLoadoutTemplateCommit loadout)
|
||||
{
|
||||
if (loadout == null) throw new ArgumentNullException(nameof(loadout));
|
||||
return WriteCommit(stateFilePath, AetheriaRuntimeCommitKind.LoadoutTemplate, document => document.LoadoutTemplate = loadout);
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeCommitEnvelope QueueRunCheckpoint(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeRunCheckpointCommit run)
|
||||
{
|
||||
if (run == null) throw new ArgumentNullException(nameof(run));
|
||||
return WriteCommit(stateFilePath, AetheriaRuntimeCommitKind.RunCheckpoint, document => document.RunCheckpoint = run);
|
||||
}
|
||||
|
||||
public static IReadOnlyList<AetheriaRuntimeCommitEnvelope> ReadPending(string stateFilePath)
|
||||
{
|
||||
var pendingDirectory = GetPendingDirectory(stateFilePath);
|
||||
if (!Directory.Exists(pendingDirectory))
|
||||
return Array.Empty<AetheriaRuntimeCommitEnvelope>();
|
||||
|
||||
return Directory
|
||||
.EnumerateFiles(pendingDirectory, "*.cc")
|
||||
.OrderBy(path => path, StringComparer.Ordinal)
|
||||
.Select(ReadEnvelope)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeStateCommitDocument ReadDocument(string path)
|
||||
{
|
||||
return AetheriaRuntimePendingCultCacheStore.ReadStateCommit(path);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCommitEnvelope WriteCommit(
|
||||
string stateFilePath,
|
||||
AetheriaRuntimeCommitKind kind,
|
||||
Action<AetheriaRuntimeStateCommitDocument> attachPayload)
|
||||
{
|
||||
var commandId = Guid.NewGuid().ToString("N");
|
||||
var createdAtUtc = DateTime.UtcNow.ToString("O");
|
||||
var pendingDirectory = GetPendingDirectory(stateFilePath);
|
||||
Directory.CreateDirectory(pendingDirectory);
|
||||
|
||||
var finalPath = Path.Combine(
|
||||
pendingDirectory,
|
||||
$"{createdAtUtc.Replace(':', '-')}.{KindToken(kind)}.{commandId}.cc");
|
||||
var document = new AetheriaRuntimeStateCommitDocument
|
||||
{
|
||||
Schema = CommitSchema,
|
||||
Kind = KindToken(kind),
|
||||
CommandId = commandId,
|
||||
CreatedAtUtc = createdAtUtc
|
||||
};
|
||||
attachPayload(document);
|
||||
|
||||
AetheriaRuntimePendingCultCacheStore.WriteStateCommit(finalPath, document);
|
||||
|
||||
return new AetheriaRuntimeCommitEnvelope(CommitSchema, kind, commandId, createdAtUtc, finalPath);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCommitEnvelope ReadEnvelope(string path)
|
||||
{
|
||||
var document = ReadDocument(path);
|
||||
return new AetheriaRuntimeCommitEnvelope(
|
||||
document.Schema ?? "",
|
||||
ParseKind(document.Kind ?? ""),
|
||||
document.CommandId ?? "",
|
||||
document.CreatedAtUtc ?? "",
|
||||
path);
|
||||
}
|
||||
|
||||
private static string KindToken(AetheriaRuntimeCommitKind kind)
|
||||
{
|
||||
return kind switch
|
||||
{
|
||||
AetheriaRuntimeCommitKind.PlayerSettings => "player_settings",
|
||||
AetheriaRuntimeCommitKind.LoadoutTemplate => "loadout_template",
|
||||
AetheriaRuntimeCommitKind.RunCheckpoint => "run_checkpoint",
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(kind), kind, null)
|
||||
};
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeCommitKind ParseKind(string token)
|
||||
{
|
||||
return token switch
|
||||
{
|
||||
"player_settings" => AetheriaRuntimeCommitKind.PlayerSettings,
|
||||
"loadout_template" => AetheriaRuntimeCommitKind.LoadoutTemplate,
|
||||
"run_checkpoint" => AetheriaRuntimeCommitKind.RunCheckpoint,
|
||||
_ => throw new InvalidDataException($"Unknown Aetheria runtime commit kind '{token}'.")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f3d6eef59b606fb4abb54b258a977a76
|
||||
|
|
@ -45,10 +45,128 @@ namespace GameCult.Aetheria.State.Unity
|
|||
return AetheriaRuntimeCatalogStore.ReadEntitySnapshots(stateFilePath);
|
||||
}
|
||||
|
||||
public static bool TryReadDaemonFrame(string stateFilePath, out AetheriaRuntimeDaemonFrameDocument frame)
|
||||
{
|
||||
return AetheriaRuntimeDaemonFrameStore.TryReadFrame(stateFilePath, out frame);
|
||||
}
|
||||
|
||||
public static bool TryReadDaemonSoaView(string stateFilePath, out AetheriaRuntimeDaemonSoaViewDocument view)
|
||||
{
|
||||
return AetheriaRuntimeDaemonSoaViewStore.TryReadView(stateFilePath, out view);
|
||||
}
|
||||
|
||||
public static bool TryReadObservedDaemonState(
|
||||
string stateFilePath,
|
||||
out AetheriaRuntimeObservedDaemonState observed)
|
||||
{
|
||||
if (!AetheriaRuntimeDaemonFrameStore.TryReadFrame(stateFilePath, out var frame))
|
||||
{
|
||||
observed = new AetheriaRuntimeObservedDaemonState(
|
||||
new AetheriaRuntimeDaemonFrameDocument { IsAuthoritative = false, StateSource = "missing" },
|
||||
null,
|
||||
AetheriaRuntimeDaemonFrameStore.GetFramePath(stateFilePath),
|
||||
AetheriaRuntimeDaemonSoaViewStore.GetViewPath(stateFilePath));
|
||||
return false;
|
||||
}
|
||||
|
||||
AetheriaRuntimeDaemonSoaViewStore.TryReadView(stateFilePath, out var soaView);
|
||||
observed = new AetheriaRuntimeObservedDaemonState(
|
||||
frame,
|
||||
string.Equals(soaView.Schema, AetheriaRuntimeDaemonSchemas.SoaView, StringComparison.Ordinal) ? soaView : null,
|
||||
AetheriaRuntimeDaemonFrameStore.GetFramePath(stateFilePath),
|
||||
AetheriaRuntimeDaemonSoaViewStore.GetViewPath(stateFilePath));
|
||||
return true;
|
||||
}
|
||||
|
||||
public static EveSurfaceDocument? ReadEveSurface(string stateFilePath, string surfaceId)
|
||||
{
|
||||
if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId, StringComparison.Ordinal) &&
|
||||
TryReadDaemonGameSurface(stateFilePath, out var gameSurface))
|
||||
{
|
||||
return gameSurface;
|
||||
}
|
||||
|
||||
if (string.Equals(surfaceId, AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal) &&
|
||||
TryReadDaemonGameTuiSurface(stateFilePath, out var gameTuiSurface))
|
||||
{
|
||||
return gameTuiSurface;
|
||||
}
|
||||
|
||||
if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId, StringComparison.Ordinal) &&
|
||||
TryReadDaemonEditorSurface(stateFilePath, out var editorSurface))
|
||||
{
|
||||
return editorSurface;
|
||||
}
|
||||
|
||||
if (string.Equals(surfaceId, AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId, StringComparison.Ordinal) &&
|
||||
TryReadDaemonEditorTuiSurface(stateFilePath, out var editorTuiSurface))
|
||||
{
|
||||
return editorTuiSurface;
|
||||
}
|
||||
|
||||
return AetheriaRuntimeCatalogStore.ReadEveSurfaces(stateFilePath)
|
||||
.FirstOrDefault(candidate => string.Equals(candidate.Surface.Id, surfaceId, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
public static bool TryReadDaemonGameSurface(
|
||||
string stateFilePath,
|
||||
out EveSurfaceDocument document)
|
||||
{
|
||||
if (!AetheriaRuntimeDaemonPublicationStore.TryReadGameSurface(stateFilePath, out var surface))
|
||||
{
|
||||
document = EmptySurface(AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId);
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadDaemonGameTuiSurface(
|
||||
string stateFilePath,
|
||||
out EveSurfaceDocument document)
|
||||
{
|
||||
if (!AetheriaRuntimeDaemonPublicationStore.TryReadGameTuiSurface(stateFilePath, out var surface))
|
||||
{
|
||||
document = EmptySurface(AetheriaRuntimeDaemonGameSurfaceBuilder.TuiSurfaceId);
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadDaemonEditorSurface(
|
||||
string stateFilePath,
|
||||
out EveSurfaceDocument document)
|
||||
{
|
||||
if (!AetheriaRuntimeDaemonPublicationStore.TryReadEditorSurface(stateFilePath, out var surface))
|
||||
{
|
||||
document = EmptySurface(AetheriaRuntimeDaemonEditorSurfaceBuilder.SurfaceId);
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool TryReadDaemonEditorTuiSurface(
|
||||
string stateFilePath,
|
||||
out EveSurfaceDocument document)
|
||||
{
|
||||
if (!AetheriaRuntimeDaemonPublicationStore.TryReadEditorTuiSurface(stateFilePath, out var surface))
|
||||
{
|
||||
document = EmptySurface(AetheriaRuntimeDaemonEditorSurfaceBuilder.TuiSurfaceId);
|
||||
return false;
|
||||
}
|
||||
|
||||
document = AetheriaRuntimeEveSurfaceAdapter.ToEveSurfaceDocument(surface);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static EveSurfaceDocument EmptySurface(string surfaceId)
|
||||
{
|
||||
return AetheriaRuntimeEveSurfaceAdapter.EmptySurface(surfaceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f7c024a72ddd924419a46ca748527ab2
|
||||
|
|
@ -0,0 +1,199 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeTradeCargoTargetOption
|
||||
{
|
||||
public AetheriaRuntimeTradeCargoTargetOption(string id, string label, string command)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Command { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeCargoSelectorSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeTradeCargoSelectorSurfaceState(
|
||||
string currentTarget,
|
||||
IReadOnlyList<AetheriaRuntimeTradeCargoTargetOption> targets,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
CurrentTarget = currentTarget ?? "";
|
||||
Targets = targets ?? Array.Empty<AetheriaRuntimeTradeCargoTargetOption>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string CurrentTarget { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeTradeCargoTargetOption> Targets { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeCargoSelectorSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.trade.target_cargo_selector";
|
||||
public const string Close = "aetheria.trade.target_cargo_selector.close";
|
||||
public const string DockingBay = "aetheria.trade.target_cargo_selector.docking_bay";
|
||||
|
||||
public static string ShipBayCommand(int shipIndex, int bayIndex)
|
||||
{
|
||||
return $"{SurfaceId}.ship_{shipIndex}_bay_{bayIndex}";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeTradeCargoSelectorSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeTradeCargoSelectorSurfaceState(
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeTradeCargoTargetOption>(),
|
||||
"");
|
||||
|
||||
var targets = state.Targets
|
||||
.OrderBy(target => target.Label, StringComparer.Ordinal)
|
||||
.ToArray();
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "trade.menu",
|
||||
title: "Trade Target Cargo Selector",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Card(
|
||||
$"{SurfaceId}.card",
|
||||
"Target Cargo",
|
||||
Metric($"{SurfaceId}.current", "Current", state.CurrentTarget),
|
||||
Text(
|
||||
$"{SurfaceId}.note",
|
||||
"Unity projects available cargo targets; the shared runtime surface owns the cargo selector contract."),
|
||||
ButtonColumn(
|
||||
$"{SurfaceId}.options",
|
||||
targets
|
||||
.Select(target => Button(target.Id, target.Label, target.Command))
|
||||
.ToArray()),
|
||||
ButtonRow(
|
||||
$"{SurfaceId}.actions",
|
||||
Button($"{SurfaceId}.close", "Close", Close)))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: targets
|
||||
.Select(target => new AetheriaRuntimeSurfaceCommandTemplate(target.Command, target.Label, "unity-uitoolkit"))
|
||||
.Append(new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit"))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonColumn(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "column", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeTradeCargoSelectorCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1,
|
||||
Select = 2
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeTradeCargoSelectorCommand
|
||||
{
|
||||
public AetheriaRuntimeTradeCargoSelectorCommand(
|
||||
AetheriaRuntimeTradeCargoSelectorCommandKind kind,
|
||||
string command)
|
||||
{
|
||||
Kind = kind;
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeTradeCargoSelectorCommandKind Kind { get; }
|
||||
public string Command { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeCargoSelectorSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeTradeCargoSelectorCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeTradeCargoSelectorSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
var commandText = request.Command ?? "";
|
||||
if (string.Equals(commandText, AetheriaRuntimeTradeCargoSelectorSurfaceBuilder.Close, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeTradeCargoSelectorCommand(
|
||||
AetheriaRuntimeTradeCargoSelectorCommandKind.Close,
|
||||
commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(commandText))
|
||||
return false;
|
||||
|
||||
command = new AetheriaRuntimeTradeCargoSelectorCommand(
|
||||
AetheriaRuntimeTradeCargoSelectorCommandKind.Select,
|
||||
commandText);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,340 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeTradeSurfaceOption
|
||||
{
|
||||
public AetheriaRuntimeTradeSurfaceOption(string id, string label, string command)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Command { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeSurfaceGroup
|
||||
{
|
||||
public AetheriaRuntimeTradeSurfaceGroup(
|
||||
string id,
|
||||
string title,
|
||||
IReadOnlyList<AetheriaRuntimeTradeSurfaceOption> options)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Title = title ?? "";
|
||||
Options = options ?? Array.Empty<AetheriaRuntimeTradeSurfaceOption>();
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Title { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeTradeSurfaceOption> Options { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeFilterSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeTradeFilterSurfaceState(
|
||||
string filterSummary,
|
||||
IReadOnlyList<AetheriaRuntimeTradeSurfaceGroup> groups,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
FilterSummary = filterSummary ?? "";
|
||||
Groups = groups ?? Array.Empty<AetheriaRuntimeTradeSurfaceGroup>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string FilterSummary { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeTradeSurfaceGroup> Groups { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeRowActionSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeTradeRowActionSurfaceState(
|
||||
string title,
|
||||
IReadOnlyList<AetheriaRuntimeTradeSurfaceOption> actions,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
Title = title ?? "";
|
||||
Actions = actions ?? Array.Empty<AetheriaRuntimeTradeSurfaceOption>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string Title { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeTradeSurfaceOption> Actions { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeInteractionSurfaceBuilder
|
||||
{
|
||||
public const string FilterSurfaceId = "aetheria.trade.filter_selector";
|
||||
public const string CloseFilter = "aetheria.trade.filter_selector.close";
|
||||
public const string RowActionSurfaceId = "aetheria.trade.row_actions";
|
||||
public const string CloseRowAction = "aetheria.trade.row_actions.close";
|
||||
|
||||
public static string HardpointFilterCommand(string hardpointType)
|
||||
{
|
||||
return $"{FilterSurfaceId}.hardpoint.{hardpointType ?? ""}";
|
||||
}
|
||||
|
||||
public static string SimpleCommodityFilterCommand(string commodityType)
|
||||
{
|
||||
return $"{FilterSurfaceId}.simple.{commodityType ?? ""}";
|
||||
}
|
||||
|
||||
public static string CompoundCommodityFilterCommand(string commodityType)
|
||||
{
|
||||
return $"{FilterSurfaceId}.compound.{commodityType ?? ""}";
|
||||
}
|
||||
|
||||
public static string BehaviorFilterCommand(string behaviorKind)
|
||||
{
|
||||
return $"{FilterSurfaceId}.behavior.{behaviorKind ?? ""}";
|
||||
}
|
||||
|
||||
public static string MinimumSizeFilterCommand()
|
||||
{
|
||||
return $"{FilterSurfaceId}.size.minimum";
|
||||
}
|
||||
|
||||
public static string MaximumSizeFilterCommand()
|
||||
{
|
||||
return $"{FilterSurfaceId}.size.maximum";
|
||||
}
|
||||
|
||||
public static string RowActionCommand(int index)
|
||||
{
|
||||
return $"{RowActionSurfaceId}.action_{index}";
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument BuildFilter(
|
||||
AetheriaRuntimeTradeFilterSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeTradeFilterSurfaceState(
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeTradeSurfaceGroup>(),
|
||||
"");
|
||||
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{FilterSurfaceId}.summary",
|
||||
"Trade Filters",
|
||||
Text(
|
||||
$"{FilterSurfaceId}.note",
|
||||
"Unity projects available trade filters; the shared runtime surface owns the filter selector contract."),
|
||||
Text($"{FilterSurfaceId}.active", state.FilterSummary))
|
||||
};
|
||||
|
||||
foreach (var group in state.Groups)
|
||||
{
|
||||
if (group?.Options == null || group.Options.Count == 0)
|
||||
continue;
|
||||
|
||||
children.Add(Card(
|
||||
group.Id,
|
||||
group.Title,
|
||||
ButtonColumn(
|
||||
$"{group.Id}.options",
|
||||
group.Options
|
||||
.Select(option => Button(option.Id, option.Label, option.Command))
|
||||
.ToArray())));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{FilterSurfaceId}.actions",
|
||||
Button($"{FilterSurfaceId}.close", "Close", CloseFilter)));
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "trade.menu",
|
||||
title: "Trade Filter Selector",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
FilterSurfaceId,
|
||||
Node(
|
||||
$"{FilterSurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: state.Groups
|
||||
.Where(group => group?.Options != null)
|
||||
.SelectMany(group => group.Options)
|
||||
.Select(option => new AetheriaRuntimeSurfaceCommandTemplate(option.Command, option.Label, "unity-uitoolkit"))
|
||||
.Append(new AetheriaRuntimeSurfaceCommandTemplate(CloseFilter, "Close", "unity-uitoolkit"))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument BuildRowActions(
|
||||
AetheriaRuntimeTradeRowActionSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeTradeRowActionSurfaceState(
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeTradeSurfaceOption>(),
|
||||
"");
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "trade.menu",
|
||||
title: "Trade Row Actions",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
RowActionSurfaceId,
|
||||
Node(
|
||||
$"{RowActionSurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
Card(
|
||||
$"{RowActionSurfaceId}.card",
|
||||
"Trade Action",
|
||||
Text($"{RowActionSurfaceId}.title", state.Title),
|
||||
Text(
|
||||
$"{RowActionSurfaceId}.note",
|
||||
"Unity projects available row actions; the shared runtime surface owns the row action contract."),
|
||||
ButtonColumn(
|
||||
$"{RowActionSurfaceId}.options",
|
||||
state.Actions
|
||||
.Select(action => Button(action.Id, action.Label, action.Command))
|
||||
.ToArray()),
|
||||
ButtonRow(
|
||||
$"{RowActionSurfaceId}.actions",
|
||||
Button($"{RowActionSurfaceId}.close", "Close", CloseRowAction)))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: state.Actions
|
||||
.Select(action => new AetheriaRuntimeSurfaceCommandTemplate(action.Command, action.Label, "unity-uitoolkit"))
|
||||
.Append(new AetheriaRuntimeSurfaceCommandTemplate(CloseRowAction, "Close", "unity-uitoolkit"))
|
||||
.ToArray());
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonColumn(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "column", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeTradeInteractionCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1,
|
||||
Select = 2
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeTradeInteractionCommand
|
||||
{
|
||||
public AetheriaRuntimeTradeInteractionCommand(
|
||||
AetheriaRuntimeTradeInteractionCommandKind kind,
|
||||
string command)
|
||||
{
|
||||
Kind = kind;
|
||||
Command = command ?? "";
|
||||
}
|
||||
|
||||
public AetheriaRuntimeTradeInteractionCommandKind Kind { get; }
|
||||
public string Command { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeInteractionSurfaceCommands
|
||||
{
|
||||
public static bool TryReadFilter(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeTradeInteractionCommand command)
|
||||
{
|
||||
return TryRead(
|
||||
request,
|
||||
AetheriaRuntimeTradeInteractionSurfaceBuilder.FilterSurfaceId,
|
||||
AetheriaRuntimeTradeInteractionSurfaceBuilder.CloseFilter,
|
||||
out command);
|
||||
}
|
||||
|
||||
public static bool TryReadRowAction(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeTradeInteractionCommand command)
|
||||
{
|
||||
return TryRead(
|
||||
request,
|
||||
AetheriaRuntimeTradeInteractionSurfaceBuilder.RowActionSurfaceId,
|
||||
AetheriaRuntimeTradeInteractionSurfaceBuilder.CloseRowAction,
|
||||
out command);
|
||||
}
|
||||
|
||||
private static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
string surfaceId,
|
||||
string closeCommand,
|
||||
out AetheriaRuntimeTradeInteractionCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, surfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
var commandText = request.Command ?? "";
|
||||
if (string.Equals(commandText, closeCommand, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeTradeInteractionCommand(
|
||||
AetheriaRuntimeTradeInteractionCommandKind.Close,
|
||||
commandText);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(commandText))
|
||||
return false;
|
||||
|
||||
command = new AetheriaRuntimeTradeInteractionCommand(
|
||||
AetheriaRuntimeTradeInteractionCommandKind.Select,
|
||||
commandText);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,254 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeTradeItemMetric
|
||||
{
|
||||
public AetheriaRuntimeTradeItemMetric(string id, string label, string value)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Label = label ?? "";
|
||||
Value = value ?? "";
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Label { get; }
|
||||
public string Value { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeItemSection
|
||||
{
|
||||
public AetheriaRuntimeTradeItemSection(
|
||||
string id,
|
||||
string title,
|
||||
IReadOnlyList<AetheriaRuntimeTradeItemMetric> metrics)
|
||||
{
|
||||
Id = id ?? "";
|
||||
Title = title ?? "";
|
||||
Metrics = metrics ?? Array.Empty<AetheriaRuntimeTradeItemMetric>();
|
||||
}
|
||||
|
||||
public string Id { get; }
|
||||
public string Title { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeTradeItemMetric> Metrics { get; }
|
||||
}
|
||||
|
||||
public sealed class AetheriaRuntimeTradeItemDetailsSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeTradeItemDetailsSurfaceState(
|
||||
string itemName,
|
||||
string description,
|
||||
string manufacturer,
|
||||
string mass,
|
||||
int price,
|
||||
string durability,
|
||||
string thermalRange,
|
||||
IReadOnlyList<AetheriaRuntimeTradeItemSection> behaviorSections,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
ItemName = itemName ?? "";
|
||||
Description = description ?? "";
|
||||
Manufacturer = manufacturer ?? "";
|
||||
Mass = mass ?? "";
|
||||
Price = price;
|
||||
Durability = durability ?? "";
|
||||
ThermalRange = thermalRange ?? "";
|
||||
BehaviorSections = behaviorSections ?? Array.Empty<AetheriaRuntimeTradeItemSection>();
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string ItemName { get; }
|
||||
public string Description { get; }
|
||||
public string Manufacturer { get; }
|
||||
public string Mass { get; }
|
||||
public int Price { get; }
|
||||
public string Durability { get; }
|
||||
public string ThermalRange { get; }
|
||||
public IReadOnlyList<AetheriaRuntimeTradeItemSection> BehaviorSections { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
public bool HasEquipmentStatus => !string.IsNullOrWhiteSpace(Durability) ||
|
||||
!string.IsNullOrWhiteSpace(ThermalRange) ||
|
||||
BehaviorSections.Count > 0;
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeItemDetailsSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.trade.item_details";
|
||||
public const string Close = "aetheria.trade.item_details.close";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeTradeItemDetailsSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeTradeItemDetailsSurfaceState(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
0,
|
||||
"",
|
||||
"",
|
||||
Array.Empty<AetheriaRuntimeTradeItemSection>(),
|
||||
"");
|
||||
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{SurfaceId}.summary",
|
||||
state.ItemName,
|
||||
Text(
|
||||
$"{SurfaceId}.description",
|
||||
string.IsNullOrWhiteSpace(state.Description)
|
||||
? "No typed item description is available."
|
||||
: state.Description),
|
||||
Text(
|
||||
$"{SurfaceId}.note",
|
||||
"Unity supplies the selected market row; the shared runtime surface owns trade item inspection layout."),
|
||||
Metric($"{SurfaceId}.manufacturer", "Manufacturer", state.Manufacturer),
|
||||
Metric($"{SurfaceId}.mass", "Mass", state.Mass),
|
||||
Metric($"{SurfaceId}.price", "Price", state.Price.ToString("N0")))
|
||||
};
|
||||
|
||||
if (state.HasEquipmentStatus)
|
||||
{
|
||||
children.Add(Card(
|
||||
$"{SurfaceId}.durability.card",
|
||||
"Durability",
|
||||
Metric($"{SurfaceId}.durability", "Max Durability", state.Durability),
|
||||
Metric($"{SurfaceId}.temperature_range", "Thermal Range", state.ThermalRange)));
|
||||
}
|
||||
|
||||
foreach (var section in state.BehaviorSections)
|
||||
{
|
||||
if (section?.Metrics == null || section.Metrics.Count == 0)
|
||||
continue;
|
||||
|
||||
children.Add(Card(
|
||||
string.IsNullOrWhiteSpace(section.Id)
|
||||
? $"{SurfaceId}.behavior.{SafeId(section.Title)}"
|
||||
: section.Id,
|
||||
section.Title,
|
||||
section.Metrics
|
||||
.Select(metric => Metric(metric.Id, metric.Label, metric.Value))
|
||||
.ToArray()));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{SurfaceId}.actions",
|
||||
Button($"{SurfaceId}.close", "Close", Close)));
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "trade.menu",
|
||||
title: "Trade Item Details",
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit")
|
||||
});
|
||||
}
|
||||
|
||||
private static string SafeId(string value)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(value))
|
||||
return "empty";
|
||||
|
||||
return new string(value
|
||||
.Select(character => char.IsLetterOrDigit(character) ? char.ToLowerInvariant(character) : '-')
|
||||
.ToArray()).Trim('-');
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeTradeItemDetailsCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeTradeItemDetailsCommand
|
||||
{
|
||||
public AetheriaRuntimeTradeItemDetailsCommand(AetheriaRuntimeTradeItemDetailsCommandKind kind)
|
||||
{
|
||||
Kind = kind;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeTradeItemDetailsCommandKind Kind { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeTradeItemDetailsSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeTradeItemDetailsCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeTradeItemDetailsSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
if (string.Equals(request.Command, AetheriaRuntimeTradeItemDetailsSurfaceBuilder.Close, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeTradeItemDetailsCommand(AetheriaRuntimeTradeItemDetailsCommandKind.Close);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7ed50a9bfc7a42d409cf7f7df931cf55
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b7f9743297bcb0248a79b8d6c8b776e9
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7fd2760f2901e4e4a8e5b86f2c6d9e3b
|
||||
|
|
@ -0,0 +1,225 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using GameCult.Eve.Surface;
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public sealed class AetheriaRuntimeZoneDetailsSurfaceState
|
||||
{
|
||||
public AetheriaRuntimeZoneDetailsSurfaceState(
|
||||
string zoneName,
|
||||
string ownerName,
|
||||
string mass,
|
||||
string radius,
|
||||
IReadOnlyList<string> otherFactions,
|
||||
bool hasContents,
|
||||
string planets,
|
||||
string asteroidBelts,
|
||||
string gasGiants,
|
||||
string stars,
|
||||
string stations,
|
||||
string turrets,
|
||||
string ships,
|
||||
string updatedAtUtc)
|
||||
{
|
||||
ZoneName = zoneName ?? "";
|
||||
OwnerName = ownerName ?? "";
|
||||
Mass = mass ?? "";
|
||||
Radius = radius ?? "";
|
||||
OtherFactions = otherFactions ?? Array.Empty<string>();
|
||||
HasContents = hasContents;
|
||||
Planets = planets ?? "";
|
||||
AsteroidBelts = asteroidBelts ?? "";
|
||||
GasGiants = gasGiants ?? "";
|
||||
Stars = stars ?? "";
|
||||
Stations = stations ?? "";
|
||||
Turrets = turrets ?? "";
|
||||
Ships = ships ?? "";
|
||||
UpdatedAtUtc = updatedAtUtc ?? "";
|
||||
}
|
||||
|
||||
public string ZoneName { get; }
|
||||
public string OwnerName { get; }
|
||||
public string Mass { get; }
|
||||
public string Radius { get; }
|
||||
public IReadOnlyList<string> OtherFactions { get; }
|
||||
public bool HasContents { get; }
|
||||
public string Planets { get; }
|
||||
public string AsteroidBelts { get; }
|
||||
public string GasGiants { get; }
|
||||
public string Stars { get; }
|
||||
public string Stations { get; }
|
||||
public string Turrets { get; }
|
||||
public string Ships { get; }
|
||||
public string UpdatedAtUtc { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeZoneDetailsSurfaceBuilder
|
||||
{
|
||||
public const string SurfaceId = "aetheria.sector_map.zone_details";
|
||||
public const string Close = "aetheria.sector_map.zone_details.close";
|
||||
|
||||
public static AetheriaRuntimeSurfaceDocument Build(
|
||||
AetheriaRuntimeZoneDetailsSurfaceState state,
|
||||
long version = 1)
|
||||
{
|
||||
state ??= new AetheriaRuntimeZoneDetailsSurfaceState(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
Array.Empty<string>(),
|
||||
false,
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"");
|
||||
|
||||
var children = new List<AetheriaRuntimeSurfaceComponent>
|
||||
{
|
||||
Card(
|
||||
$"{SurfaceId}.card",
|
||||
state.ZoneName,
|
||||
Metric($"{SurfaceId}.owner", "Owner", string.IsNullOrWhiteSpace(state.OwnerName) ? "None" : state.OwnerName),
|
||||
Metric($"{SurfaceId}.mass", "Mass", state.Mass),
|
||||
Metric($"{SurfaceId}.radius", "Radius", state.Radius))
|
||||
};
|
||||
|
||||
if (state.OtherFactions.Count > 0)
|
||||
{
|
||||
children.Add(Text(
|
||||
$"{SurfaceId}.factions",
|
||||
$"Factions Present: {string.Join(", ", state.OtherFactions)}"));
|
||||
}
|
||||
|
||||
if (!state.HasContents)
|
||||
{
|
||||
children.Add(Text(
|
||||
$"{SurfaceId}.unvisited",
|
||||
"Has not been visited."));
|
||||
}
|
||||
else
|
||||
{
|
||||
children.Add(Card(
|
||||
$"{SurfaceId}.contents",
|
||||
"Contents",
|
||||
Metric($"{SurfaceId}.planets", "Planets", state.Planets),
|
||||
Metric($"{SurfaceId}.belts", "Asteroid Belts", state.AsteroidBelts),
|
||||
Metric($"{SurfaceId}.giants", "Gas Giants", state.GasGiants),
|
||||
Metric($"{SurfaceId}.stars", "Stars", state.Stars),
|
||||
Metric($"{SurfaceId}.stations", "Stations", state.Stations),
|
||||
Metric($"{SurfaceId}.turrets", "Turrets", state.Turrets),
|
||||
Metric($"{SurfaceId}.ships", "Ships", state.Ships)));
|
||||
}
|
||||
|
||||
children.Add(ButtonRow(
|
||||
$"{SurfaceId}.actions",
|
||||
Button($"{SurfaceId}.close", "Close", Close)));
|
||||
|
||||
return new AetheriaRuntimeSurfaceDocument(
|
||||
providerId: "aetheria",
|
||||
providerKind: "sector.map",
|
||||
title: state.ZoneName,
|
||||
version: version,
|
||||
updatedAtUtc: state.UpdatedAtUtc,
|
||||
surface: new AetheriaRuntimeSurfaceTree(
|
||||
SurfaceId,
|
||||
Node(
|
||||
$"{SurfaceId}.root",
|
||||
"surface",
|
||||
Array.Empty<(string Key, string Value)>(),
|
||||
children.ToArray()),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
commands: new[]
|
||||
{
|
||||
new AetheriaRuntimeSurfaceCommandTemplate(Close, "Close", "unity-uitoolkit")
|
||||
});
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Card(
|
||||
string id,
|
||||
string title,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "card", new[] { ("title", title ?? "") }, children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Metric(string id, string label, string value)
|
||||
{
|
||||
return Node(id, "metric", new[] { ("label", label ?? ""), ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Text(string id, string value)
|
||||
{
|
||||
return Node(id, "text", new[] { ("value", value ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Button(string id, string label, string command)
|
||||
{
|
||||
return Node(id, "control.button", new[] { ("label", label ?? ""), ("command", command ?? "") });
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent ButtonRow(
|
||||
string id,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return Node(id, "row", Array.Empty<(string Key, string Value)>(), children);
|
||||
}
|
||||
|
||||
private static AetheriaRuntimeSurfaceComponent Node(
|
||||
string id,
|
||||
string kind,
|
||||
IEnumerable<(string Key, string Value)> props,
|
||||
params AetheriaRuntimeSurfaceComponent[] children)
|
||||
{
|
||||
return new AetheriaRuntimeSurfaceComponent(
|
||||
id ?? "",
|
||||
kind ?? "",
|
||||
(props ?? Array.Empty<(string Key, string Value)>())
|
||||
.ToDictionary(prop => prop.Key, prop => prop.Value ?? "", StringComparer.Ordinal),
|
||||
children ?? Array.Empty<AetheriaRuntimeSurfaceComponent>());
|
||||
}
|
||||
}
|
||||
|
||||
public enum AetheriaRuntimeZoneDetailsCommandKind
|
||||
{
|
||||
Unknown = 0,
|
||||
Close = 1
|
||||
}
|
||||
|
||||
public readonly struct AetheriaRuntimeZoneDetailsCommand
|
||||
{
|
||||
public AetheriaRuntimeZoneDetailsCommand(AetheriaRuntimeZoneDetailsCommandKind kind)
|
||||
{
|
||||
Kind = kind;
|
||||
}
|
||||
|
||||
public AetheriaRuntimeZoneDetailsCommandKind Kind { get; }
|
||||
}
|
||||
|
||||
public static class AetheriaRuntimeZoneDetailsSurfaceCommands
|
||||
{
|
||||
public static bool TryRead(
|
||||
EveSurfaceCommandRequest request,
|
||||
out AetheriaRuntimeZoneDetailsCommand command)
|
||||
{
|
||||
command = default;
|
||||
if (request == null ||
|
||||
!string.Equals(request.SurfaceId, AetheriaRuntimeZoneDetailsSurfaceBuilder.SurfaceId, StringComparison.Ordinal))
|
||||
return false;
|
||||
|
||||
if (string.Equals(request.Command, AetheriaRuntimeZoneDetailsSurfaceBuilder.Close, StringComparison.Ordinal))
|
||||
{
|
||||
command = new AetheriaRuntimeZoneDetailsCommand(AetheriaRuntimeZoneDetailsCommandKind.Close);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
212
Packages/org.gamecult.aetheria.state/Runtime/AetheriaState.cs
Normal file
212
Packages/org.gamecult.aetheria.state/Runtime/AetheriaState.cs
Normal file
|
|
@ -0,0 +1,212 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace GameCult.Aetheria.State.Unity
|
||||
{
|
||||
public readonly struct AetheriaState
|
||||
{
|
||||
private readonly DirectoryInfo _gameDataDirectory;
|
||||
|
||||
private AetheriaState(DirectoryInfo gameDataDirectory)
|
||||
{
|
||||
_gameDataDirectory = gameDataDirectory ?? throw new ArgumentNullException(nameof(gameDataDirectory));
|
||||
}
|
||||
|
||||
public static AetheriaState At(DirectoryInfo gameDataDirectory)
|
||||
{
|
||||
return new AetheriaState(gameDataDirectory);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeStateBootReport Boot =>
|
||||
AetheriaRuntimeStateBoot.Inspect(_gameDataDirectory);
|
||||
|
||||
public AetheriaClientTarget ClientTarget =>
|
||||
new AetheriaClientTarget(_gameDataDirectory);
|
||||
|
||||
public bool TryReadDaemonFrame(out AetheriaRuntimeDaemonFrameDocument? frame)
|
||||
{
|
||||
var boot = Boot;
|
||||
return AetheriaRuntimeStateReader.TryReadDaemonFrame(boot.StateFilePath, out frame);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeVerseHostSettingsSnapshot ReadVerseHostSettings()
|
||||
{
|
||||
var boot = Boot;
|
||||
return AetheriaRuntimeStateReader.ReadVerseHostSettings(boot.StateFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
public readonly struct AetheriaClientTarget
|
||||
{
|
||||
private readonly DirectoryInfo _gameDataDirectory;
|
||||
|
||||
internal AetheriaClientTarget(DirectoryInfo gameDataDirectory)
|
||||
{
|
||||
_gameDataDirectory = gameDataDirectory ?? throw new ArgumentNullException(nameof(gameDataDirectory));
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument Refresh()
|
||||
{
|
||||
var paths = Paths();
|
||||
return AetheriaRuntimeClientTargetStore.ReadOrInitialize(paths.ClientTargetPath, paths.DefaultStateFilePath);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument DiscoverVerses()
|
||||
{
|
||||
var paths = Paths();
|
||||
return AetheriaRuntimeVerseDiscovery.RefreshClientTarget(paths.ClientTargetPath, paths.DefaultStateFilePath);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument SyncReplica()
|
||||
{
|
||||
var paths = Paths();
|
||||
return SyncReplica(paths.ClientTargetPath, paths.DefaultStateFilePath);
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument CycleTransport()
|
||||
{
|
||||
return Edit(document =>
|
||||
{
|
||||
document.TargetKind = string.Equals(document.TargetKind, AetheriaRuntimeClientTargetKinds.CultMeshVerse, StringComparison.Ordinal)
|
||||
? AetheriaRuntimeClientTargetKinds.StateFile
|
||||
: AetheriaRuntimeClientTargetKinds.CultMeshVerse;
|
||||
document.LastReplicaSyncError = "";
|
||||
});
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument RequestTitle(string title)
|
||||
{
|
||||
return Edit(document => document.Title = title ?? "");
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument RequestVerseId(string verseId)
|
||||
{
|
||||
var gameDataDirectory = _gameDataDirectory;
|
||||
return Edit(document =>
|
||||
{
|
||||
document.VerseId = verseId ?? "";
|
||||
document.ReplicaStateFilePath = AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(gameDataDirectory, document.VerseId);
|
||||
document.LastReplicaSyncError = "";
|
||||
});
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument RequestCultMeshAddress(string cultMeshAddress)
|
||||
{
|
||||
return Edit(document =>
|
||||
{
|
||||
document.CultMeshAddress = cultMeshAddress ?? "";
|
||||
document.LastReplicaSyncError = "";
|
||||
});
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument RequestStateFilePath(string stateFilePath)
|
||||
{
|
||||
return Edit(document => document.StateFilePath = stateFilePath ?? "");
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument RequestDiscoveryEndpoints(IEnumerable<string>? discoveryEndpoints)
|
||||
{
|
||||
return Edit(document =>
|
||||
{
|
||||
document.DiscoveryEndpoints = NormalizeDiscoveryEndpoints(discoveryEndpoints);
|
||||
document.LastDiscoveryError = "";
|
||||
});
|
||||
}
|
||||
|
||||
public AetheriaRuntimeClientTargetDocument SelectDiscoveredVerse(
|
||||
string verseId,
|
||||
string title,
|
||||
string cultMeshAddress,
|
||||
IEnumerable<string>? discoveryEndpoints)
|
||||
{
|
||||
var gameDataDirectory = _gameDataDirectory;
|
||||
return Edit(document =>
|
||||
{
|
||||
document.TargetKind = AetheriaRuntimeClientTargetKinds.CultMeshVerse;
|
||||
document.Title = title ?? "";
|
||||
document.VerseId = verseId ?? "";
|
||||
document.CultMeshAddress = cultMeshAddress ?? "";
|
||||
document.ReplicaStateFilePath = AetheriaRuntimeStateBoundary.GetReplicaStateFilePath(gameDataDirectory, document.VerseId);
|
||||
document.DiscoveryEndpoints = NormalizeDiscoveryEndpoints(discoveryEndpoints);
|
||||
document.LastDiscoveryError = "";
|
||||
document.LastReplicaSyncError = "";
|
||||
});
|
||||
}
|
||||
|
||||
private AetheriaRuntimeClientTargetDocument Edit(Action<AetheriaRuntimeClientTargetDocument> mutate)
|
||||
{
|
||||
if (mutate == null) throw new ArgumentNullException(nameof(mutate));
|
||||
|
||||
var paths = Paths();
|
||||
return AetheriaRuntimeClientTargetStore.Update(
|
||||
paths.ClientTargetPath,
|
||||
paths.DefaultStateFilePath,
|
||||
document =>
|
||||
{
|
||||
mutate(document);
|
||||
if (string.IsNullOrWhiteSpace(document.TargetKind))
|
||||
document.TargetKind = AetheriaRuntimeClientTargetKinds.StateFile;
|
||||
if (string.IsNullOrWhiteSpace(document.StateFilePath))
|
||||
document.StateFilePath = paths.DefaultStateFilePath;
|
||||
document.UpdatedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
});
|
||||
}
|
||||
|
||||
private AetheriaRuntimeClientTargetDocument SyncReplica(
|
||||
string clientTargetPath,
|
||||
string defaultStateFilePath)
|
||||
{
|
||||
var target = AetheriaRuntimeClientTargetStore.ReadOrInitialize(clientTargetPath, defaultStateFilePath);
|
||||
var syncedAtUtc = DateTime.UtcNow.ToString("O");
|
||||
try
|
||||
{
|
||||
var result = AetheriaRuntimeVerseReplicaBridge.Sync(_gameDataDirectory, target);
|
||||
return AetheriaRuntimeClientTargetStore.Update(
|
||||
clientTargetPath,
|
||||
defaultStateFilePath,
|
||||
document =>
|
||||
{
|
||||
document.ReplicaStateFilePath = result.ReplicaStateFilePath;
|
||||
document.LastReplicaSyncAtUtc = syncedAtUtc;
|
||||
document.LastReplicaSyncError = "";
|
||||
document.UpdatedAtUtc = syncedAtUtc;
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
AetheriaRuntimeClientTargetStore.Update(
|
||||
clientTargetPath,
|
||||
defaultStateFilePath,
|
||||
document =>
|
||||
{
|
||||
document.LastReplicaSyncAtUtc = syncedAtUtc;
|
||||
document.LastReplicaSyncError = ex.Message ?? ex.GetType().Name;
|
||||
document.UpdatedAtUtc = syncedAtUtc;
|
||||
});
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
private (string ClientTargetPath, string DefaultStateFilePath) Paths()
|
||||
{
|
||||
return (
|
||||
AetheriaRuntimeStateBoundary.GetClientTargetPath(_gameDataDirectory),
|
||||
AetheriaRuntimeStateBoundary.GetStateFilePath(_gameDataDirectory));
|
||||
}
|
||||
|
||||
private static string[] NormalizeDiscoveryEndpoints(IEnumerable<string>? discoveryEndpoints)
|
||||
{
|
||||
return discoveryEndpoints?
|
||||
.Select(endpoint => endpoint?.Trim() ?? "")
|
||||
.Where(endpoint => !string.IsNullOrWhiteSpace(endpoint))
|
||||
.Distinct(StringComparer.Ordinal)
|
||||
.ToArray()
|
||||
?? Array.Empty<string>();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -3,13 +3,36 @@
|
|||
"rootNamespace": "GameCult.Aetheria.State.Unity",
|
||||
"references": [
|
||||
"GameCult.Eve.Surface",
|
||||
"GameCult.Mesh",
|
||||
"MessagePack"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"ConcurrentCollections.dll",
|
||||
"GameCult.Caching.MessagePack.dll",
|
||||
"GameCult.Caching.dll",
|
||||
"GameCult.Logging.dll",
|
||||
"GameCult.Mesh.dll",
|
||||
"GameCult.Networking.dll",
|
||||
"Isopoh.Cryptography.Argon2.dll",
|
||||
"Isopoh.Cryptography.Blake2b.dll",
|
||||
"Isopoh.Cryptography.SecureArray.dll",
|
||||
"LiteNetLib.dll",
|
||||
"Microsoft.Bcl.AsyncInterfaces.dll",
|
||||
"Microsoft.Bcl.TimeProvider.dll",
|
||||
"Microsoft.NET.StringTools.dll",
|
||||
"MessagePack.Annotations.dll",
|
||||
"MessagePack.CultMesh.dll",
|
||||
"R3.dll",
|
||||
"System.Collections.Immutable.dll",
|
||||
"System.IO.Pipelines.dll",
|
||||
"System.Text.Encodings.Web.dll",
|
||||
"System.Text.Json.dll",
|
||||
"System.Threading.Channels.dll"
|
||||
],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue