refactor(battle-node): extract ForwardWhenBothReadyHandler; share handler instances via BuildHandlers

This commit is contained in:
gamer147
2026-06-03 14:33:26 -04:00
parent db2f711894
commit 503c382646
2 changed files with 27 additions and 4 deletions

View File

@@ -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()