refactor(battle-node): add frame-handler contract, context, and empty registry shim

This commit is contained in:
gamer147
2026-06-03 13:59:02 -04:00
parent 57d91236a0
commit 73d2c4e1b8
3 changed files with 67 additions and 0 deletions

View File

@@ -30,6 +30,18 @@ public sealed class BattleSession
public IBattleParticipant B { get; }
public BattleSessionPhase Phase => _state.SessionPhase;
// Per-URI handlers consulted before the legacy switch. Populated incrementally (Tasks 5-14);
// each registered URI is served by its handler and its legacy switch arm goes dead.
private static readonly IReadOnlyDictionary<NetworkBattleUri, IFrameHandler> Handlers =
new Dictionary<NetworkBattleUri, IFrameHandler>();
private FrameDispatchContext BuildContext(IBattleParticipant from, MsgEnvelope env) =>
new()
{
A = A, B = B, From = from, Other = ReferenceEquals(from, A) ? B : A,
Env = env, Type = Type, BattleId = BattleId, State = _state,
};
public BattleSession(string battleId, BattleType type, IBattleParticipant a, IBattleParticipant b,
ILogger<BattleSession> log)
{
@@ -132,6 +144,10 @@ public sealed class BattleSession
internal IReadOnlyList<DispatchRoute> ComputeFrames(
IBattleParticipant from, MsgEnvelope env)
{
if (Handlers.TryGetValue(env.Uri, out var handler))
return handler.Handle(BuildContext(from, env));
// --- legacy switch (shrinking; deleted in the final task) ---
var result = new List<DispatchRoute>();
var other = ReferenceEquals(from, A) ? B : A;
var phaseFrom = from as IHasHandshakePhase;