refactor(battle-node): extract ForwardWhenBothReadyHandler; share handler instances via BuildHandlers
This commit is contained in:
@@ -33,8 +33,13 @@ public sealed class BattleSession
|
||||
|
||||
// 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 static readonly IReadOnlyDictionary<NetworkBattleUri, IFrameHandler> Handlers = BuildHandlers();
|
||||
|
||||
private static IReadOnlyDictionary<NetworkBattleUri, IFrameHandler> BuildHandlers()
|
||||
{
|
||||
var retireKill = new RetireKillHandler();
|
||||
var forwardWhenReady = new ForwardWhenBothReadyHandler();
|
||||
return new Dictionary<NetworkBattleUri, IFrameHandler>
|
||||
{
|
||||
[NetworkBattleUri.InitNetwork] = new InitNetworkHandler(),
|
||||
[NetworkBattleUri.InitBattle] = new InitBattleHandler(),
|
||||
@@ -42,11 +47,16 @@ public sealed class BattleSession
|
||||
[NetworkBattleUri.Swap] = new SwapHandler(),
|
||||
[NetworkBattleUri.TurnEnd] = new TurnEndHandler(),
|
||||
[NetworkBattleUri.TurnEndFinal] = new TurnEndFinalHandler(),
|
||||
[NetworkBattleUri.Retire] = new RetireKillHandler(),
|
||||
[NetworkBattleUri.Kill] = new RetireKillHandler(),
|
||||
[NetworkBattleUri.Retire] = retireKill,
|
||||
[NetworkBattleUri.Kill] = retireKill,
|
||||
[NetworkBattleUri.TurnStart] = new TurnStartHandler(),
|
||||
[NetworkBattleUri.Judge] = new JudgeHandler(),
|
||||
[NetworkBattleUri.PlayActions] = forwardWhenReady,
|
||||
[NetworkBattleUri.Echo] = forwardWhenReady,
|
||||
[NetworkBattleUri.TurnEndActions] = forwardWhenReady,
|
||||
[NetworkBattleUri.JudgeResult] = forwardWhenReady,
|
||||
};
|
||||
}
|
||||
|
||||
private FrameDispatchContext BuildContext(IBattleParticipant from, MsgEnvelope env) =>
|
||||
new()
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
using SVSim.BattleNode.Protocol;
|
||||
|
||||
namespace SVSim.BattleNode.Sessions.Dispatch.Handlers;
|
||||
|
||||
internal sealed class ForwardWhenBothReadyHandler : IFrameHandler
|
||||
{
|
||||
public IReadOnlyList<DispatchRoute> Handle(FrameDispatchContext ctx)
|
||||
{
|
||||
if (ctx.BothAfterReady())
|
||||
return new[] { new DispatchRoute(ctx.Other, ctx.Env, false) };
|
||||
return Array.Empty<DispatchRoute>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user