refactor(battle-node): add frame-handler contract, context, and empty registry shim
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user