refactor(runtime): own canonical action state

Move selection, combat, and interaction target mode under one Runtime owner; make plugins, retained UI, session routing, and typed runtime views borrow its exact children; and add failure-safe reset, instance isolation, source ownership, and normalized checkpoint coverage without changing retail ordering.

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-26 10:44:09 +02:00
parent bb45afef33
commit b298f99f91
38 changed files with 711 additions and 93 deletions

View file

@ -154,6 +154,7 @@ public sealed class CursorFeedbackControllerTests
var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -190,6 +191,7 @@ public sealed class CursorFeedbackControllerTests
var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -229,6 +231,7 @@ public sealed class CursorFeedbackControllerTests
var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -258,6 +261,7 @@ public sealed class CursorFeedbackControllerTests
var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,

View file

@ -1,59 +0,0 @@
using AcDream.App.UI;
namespace AcDream.App.Tests.UI;
public sealed class InteractionStateTests
{
[Fact]
public void Modes_HaveOneOwnerAndOneDeduplicatedTransitionStream()
{
var state = new InteractionState();
var changes = new List<InteractionModeTransition>();
state.Changed += changes.Add;
Assert.True(state.EnterUse());
Assert.False(state.EnterUse());
Assert.True(state.EnterExamine());
Assert.True(state.EnterUseItemOnTarget(0x100u));
Assert.True(state.Clear());
Assert.Equal(4, changes.Count);
Assert.Equal(InteractionModeKind.None, state.Current.Kind);
Assert.Equal(0x100u, changes[2].Current.SourceObjectId);
}
[Fact]
public void UseItemOnTarget_RejectsMissingSource()
{
var state = new InteractionState();
Assert.Throws<ArgumentOutOfRangeException>(() => state.EnterUseItemOnTarget(0));
Assert.Equal(InteractionMode.None, state.Current);
}
[Fact]
public void ResetSession_RetryRepublishesAndOneObserverCannotStarveAnother()
{
var state = new InteractionState();
state.EnterExamine();
bool fail = true;
int delivered = 0;
state.Changed += _ =>
{
if (fail)
{
fail = false;
throw new InvalidOperationException("transient");
}
};
state.Changed += transition =>
{
Assert.Equal(InteractionMode.None, transition.Current);
delivered++;
};
Assert.Throws<AggregateException>(state.ResetSession);
Assert.Equal(1, delivered);
state.ResetSession();
Assert.Equal(2, delivered);
}
}

View file

@ -60,6 +60,7 @@ public sealed class ItemInteractionControllerTests
Controller = new ItemInteractionController(
Objects,
SharedTransactions,
new InteractionState(),
playerGuid: () => Player,
sendUse: requestUse is null ? Uses.Add : null,
sendExamine: Examines.Add,
@ -341,6 +342,7 @@ public sealed class ItemInteractionControllerTests
Assert.Throws<ArgumentException>(() => new ItemInteractionController(
objects,
transactions,
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,

View file

@ -859,6 +859,7 @@ public sealed class AppraisalUiControllerTests
=> new(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => 0x50000002u,
sendUse: null,
sendUseWithTarget: null,

View file

@ -107,6 +107,7 @@ public sealed class ExternalContainerControllerTests
Interaction = new ItemInteractionController(
Objects,
new InventoryTransactionState(Objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: Uses.Add,
sendUseWithTarget: null,

View file

@ -509,6 +509,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -546,6 +547,7 @@ public class InventoryControllerTests
var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -715,6 +717,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -760,6 +763,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -812,6 +816,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -870,6 +875,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -939,6 +945,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -1002,6 +1009,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -1062,6 +1070,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -1109,6 +1118,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -1149,6 +1159,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,
@ -1188,6 +1199,7 @@ public class InventoryControllerTests
using var interaction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: null,
sendUseWithTarget: null,

View file

@ -53,6 +53,7 @@ public class PaperdollControllerTests
var itemInteraction = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
() => Player,
sendUse: null,
sendUseWithTarget: null,

View file

@ -266,6 +266,7 @@ public class ToolbarControllerTests
var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
playerGuid: () => player,
sendUse: null,
sendUseWithTarget: (source, target) => useWithTarget.Add((source, target)),
@ -332,6 +333,7 @@ public class ToolbarControllerTests
using var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
playerGuid: () => player,
sendUse: null,
sendUseWithTarget: null,
@ -381,6 +383,7 @@ public class ToolbarControllerTests
using var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
playerGuid: () => player,
sendUse: null,
sendUseWithTarget: null,
@ -510,6 +513,7 @@ public class ToolbarControllerTests
var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
() => player,
sendUse: uses.Add,
sendUseWithTarget: null,
@ -568,6 +572,7 @@ public class ToolbarControllerTests
using var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
() => player,
sendUse: null,
sendUseWithTarget: null,
@ -633,6 +638,7 @@ public class ToolbarControllerTests
using var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
() => player,
sendUse: null,
sendUseWithTarget: null,
@ -799,6 +805,7 @@ public class ToolbarControllerTests
using var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
playerGuid: () => player,
sendUse: null,
sendUseWithTarget: null,
@ -848,6 +855,7 @@ public class ToolbarControllerTests
var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
() => player,
sendUse: null,
sendUseWithTarget: (s, t) => (sentSource, sentTarget) = (s, t),
@ -890,6 +898,7 @@ public class ToolbarControllerTests
var interaction = new ItemInteractionController(
repo,
new InventoryTransactionState(repo),
new InteractionState(),
() => player,
sendUse: null,
sendUseWithTarget: null,

View file

@ -19,6 +19,7 @@ public sealed class RetailItemConfirmationControllerTests
var items = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: uses.Add,
sendUseWithTarget: null,
@ -54,6 +55,7 @@ public sealed class RetailItemConfirmationControllerTests
var items = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: uses.Add,
sendUseWithTarget: null,
@ -83,6 +85,7 @@ public sealed class RetailItemConfirmationControllerTests
var items = new ItemInteractionController(
objects,
new InventoryTransactionState(objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: uses.Add,
sendUseWithTarget: null,

View file

@ -164,6 +164,7 @@ public sealed class RetailUiInteractionFlowTests
var interaction = new ItemInteractionController(
Objects,
new InventoryTransactionState(Objects),
new InteractionState(),
playerGuid: () => Player,
sendUse: Uses.Add,
sendUseWithTarget: (source, target) => UseWithTarget.Add((source, target)),
@ -199,6 +200,7 @@ public sealed class RetailUiInteractionFlowTests
itemInteraction ??= new ItemInteractionController(
Objects,
new InventoryTransactionState(Objects),
new InteractionState(),
() => Player,
sendUse: null,
sendUseWithTarget: null,