Route daemon surface commands through typed operations
This commit is contained in:
parent
b8179c6093
commit
039d3676f7
5 changed files with 81 additions and 21 deletions
|
|
@ -2212,7 +2212,8 @@ static void RequireEveRuntimeBootstrap(string root)
|
|||
"request.ProviderId, \"aetheria.daemon\"",
|
||||
"AetheriaRuntimeStateReader.TryReadObservedDaemonState(stateFilePath, out var observed)",
|
||||
"new AetheriaRuntimeDaemonOperationClient(",
|
||||
"client.TrySendCommandKind(kind, observed, out envelope, out _)"
|
||||
"TrySubmitKnownCommand(client, observed, kind, out envelope)",
|
||||
"AetheriaRuntimeDaemonCommandKinds.SensorPing => client.SensorPing(observed)"
|
||||
};
|
||||
var missingDaemonSurfaceCommandSymbols = requiredDaemonSurfaceCommandSymbols
|
||||
.Where(symbol => !daemonSurfaceCommands.Contains(symbol, StringComparison.Ordinal))
|
||||
|
|
@ -2248,6 +2249,12 @@ static void RequireEveRuntimeBootstrap(string root)
|
|||
throw new InvalidOperationException(
|
||||
"Daemon Eve surface command routing still calls the generic daemon submitter instead of the typed daemon operation client.");
|
||||
}
|
||||
|
||||
if (daemonSurfaceCommands.Contains("TrySendCommandKind(", StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Daemon Eve surface command routing still uses a generic command-kind submission back door instead of explicit typed operations.");
|
||||
}
|
||||
}
|
||||
|
||||
static void RequireNoRendererLocalConsole(string root)
|
||||
|
|
@ -5907,7 +5914,7 @@ static void RequireTypedDaemonCommandPayloads(string root)
|
|||
|
||||
var requiredClientSymbols = new[]
|
||||
{
|
||||
"public bool TrySendCommandKind(",
|
||||
"private AetheriaRuntimeDaemonCommandEnvelope Send(AetheriaRuntimeDaemonCommandDocument command)",
|
||||
"ReadObservedDaemonCommands()",
|
||||
"Func<AetheriaRuntimeDaemonOperationClient, AetheriaRuntimeObservedDaemonState, AetheriaRuntimeDaemonCommandEnvelope> submit",
|
||||
"return Send((client, observed) => client.SetTarget(observed, targetEntityKey));",
|
||||
|
|
@ -6019,6 +6026,7 @@ static void RequireTypedDaemonCommandPayloads(string root)
|
|||
|
||||
var forbiddenClientDocumentBuilderSymbols = new[]
|
||||
{
|
||||
"TrySendCommandKind(",
|
||||
"Action<AetheriaRuntimeDaemonCommandDocument>",
|
||||
"configure?.Invoke(command)",
|
||||
"Send(AetheriaRuntimeDaemonCommandKinds"
|
||||
|
|
|
|||
|
|
@ -1032,6 +1032,37 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.IsEmpty(envelope.Path);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonEveSurfaceCommandRejectsUnsupportedArgumentlessOperation()
|
||||
{
|
||||
var statePath = Path.Combine(
|
||||
Path.GetTempPath(),
|
||||
"aetheria-daemon-surface-command-tests",
|
||||
Path.GetRandomFileName(),
|
||||
"state.cc");
|
||||
var frame = AetheriaRuntimeDaemonFrameDocument.Create(
|
||||
new AetheriaRuntimeRunCheckpointCommit
|
||||
{
|
||||
CurrentEntityKey = "entity:surface-player"
|
||||
},
|
||||
"aetheria-daemon",
|
||||
"session-surface-command",
|
||||
78,
|
||||
1.5,
|
||||
0.02);
|
||||
AetheriaRuntimeDaemonFrameStore.PublishFrame(statePath, frame);
|
||||
var request = new EveSurfaceCommandRequest(
|
||||
"aetheria.daemon",
|
||||
AetheriaRuntimeDaemonGameSurfaceBuilder.SurfaceId,
|
||||
"aetheria.daemon.commands.TransferCargoItem",
|
||||
new Dictionary<string, string>(StringComparer.Ordinal),
|
||||
DateTimeOffset.UtcNow,
|
||||
"unity-uitoolkit");
|
||||
|
||||
Assert.IsFalse(AetheriaRuntimeDaemonSurfaceCommands.TrySubmit(statePath, request, out var envelope));
|
||||
Assert.IsNull(envelope);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsMovesTargetSelectionIntoDaemonState()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ namespace GameCult.Aetheria.State.Verse
|
|||
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.target", "Target Nearest", AetheriaRuntimeDaemonCommandKinds.TargetNearest),
|
||||
CommandButton("aetheria.daemon.game.commands.fire", "Fire", AetheriaRuntimeDaemonCommandKinds.FireWeaponGroup),
|
||||
CommandButton("aetheria.daemon.game.commands.ping", "Sensor Ping", AetheriaRuntimeDaemonCommandKinds.SensorPing)))),
|
||||
Array.Empty<AetheriaRuntimeSurfaceStyleToken>()),
|
||||
|
|
|
|||
|
|
@ -23,20 +23,6 @@ namespace GameCult.Aetheria.State.Verse
|
|||
public string ClientId { get; }
|
||||
public string SessionId { get; }
|
||||
|
||||
public bool TrySendCommandKind(
|
||||
AetheriaRuntimeDaemonCommandKinds kind,
|
||||
AetheriaRuntimeObservedDaemonState? observed,
|
||||
out AetheriaRuntimeDaemonCommandEnvelope? envelope,
|
||||
out string error)
|
||||
{
|
||||
var command = Create(kind, observed);
|
||||
if (TrySend(command, out envelope, out error))
|
||||
return true;
|
||||
|
||||
envelope = ToEnvelope(command);
|
||||
return false;
|
||||
}
|
||||
|
||||
private AetheriaRuntimeDaemonCommandEnvelope Send(AetheriaRuntimeDaemonCommandDocument command)
|
||||
{
|
||||
if (!TrySend(command, out var envelope, out var error))
|
||||
|
|
|
|||
|
|
@ -27,12 +27,47 @@ namespace GameCult.Aetheria.State.Verse
|
|||
stateFilePath,
|
||||
string.IsNullOrWhiteSpace(request.ClientId) ? "unity-uitoolkit" : request.ClientId,
|
||||
observed?.Frame.SessionId ?? "local");
|
||||
if (client.TrySendCommandKind(kind, observed, out envelope, out _))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return TrySubmitKnownCommand(client, observed, kind, out envelope);
|
||||
}
|
||||
|
||||
return true;
|
||||
private static bool TrySubmitKnownCommand(
|
||||
AetheriaRuntimeDaemonOperationClient client,
|
||||
AetheriaRuntimeObservedDaemonState? observed,
|
||||
AetheriaRuntimeDaemonCommandKinds kind,
|
||||
out AetheriaRuntimeDaemonCommandEnvelope? envelope)
|
||||
{
|
||||
envelope = null;
|
||||
if (client == null)
|
||||
return false;
|
||||
|
||||
try
|
||||
{
|
||||
envelope = kind switch
|
||||
{
|
||||
AetheriaRuntimeDaemonCommandKinds.ClearTarget => client.ClearTarget(observed),
|
||||
AetheriaRuntimeDaemonCommandKinds.TargetNearest => client.TargetNearest(observed),
|
||||
AetheriaRuntimeDaemonCommandKinds.TargetNext => client.TargetNext(observed),
|
||||
AetheriaRuntimeDaemonCommandKinds.TargetPrevious => client.TargetPrevious(observed),
|
||||
AetheriaRuntimeDaemonCommandKinds.SetMoveVector => client.SetMoveVector(observed, 0.0, 1.0),
|
||||
AetheriaRuntimeDaemonCommandKinds.SetLookDirection => client.SetLookDirection(observed, 0.0, 1.0, 0.0),
|
||||
AetheriaRuntimeDaemonCommandKinds.SetTractorPower => client.SetTractorPower(observed, 1.0),
|
||||
AetheriaRuntimeDaemonCommandKinds.FireWeaponGroup => client.FireWeaponGroup(observed, 0),
|
||||
AetheriaRuntimeDaemonCommandKinds.SetWeaponGroupActive => client.SetWeaponGroupActive(observed, 0, true),
|
||||
AetheriaRuntimeDaemonCommandKinds.SensorPing => client.SensorPing(observed),
|
||||
AetheriaRuntimeDaemonCommandKinds.SetHeatsinksEnabled => client.SetHeatsinksEnabled(observed, true),
|
||||
AetheriaRuntimeDaemonCommandKinds.SetOverrideShutdown => client.SetOverrideShutdown(observed, true),
|
||||
AetheriaRuntimeDaemonCommandKinds.ToggleShieldEnabled => client.ToggleShieldEnabled(observed),
|
||||
AetheriaRuntimeDaemonCommandKinds.DockNearest => client.DockNearest(observed, 0.0),
|
||||
AetheriaRuntimeDaemonCommandKinds.Undock => client.Undock(observed),
|
||||
_ => null
|
||||
};
|
||||
return envelope != null;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
envelope = null;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool TryResolveKind(EveSurfaceCommandRequest request, out AetheriaRuntimeDaemonCommandKinds kind)
|
||||
|
|
|
|||
Loading…
Reference in a new issue