feat(ui+net): #16 LiveCommandBus + WorldSession.Send{Talk,Tell,Channel} + SendChatCmd wiring
Replaces NullCommandBus.Instance in PanelContext with a real LiveCommandBus when a live session is active. Panels publish SendChatCmd; the host routes it to the right wire opcode + emits a ChatLog.OnSelfSent local echo (optimistic; retail-equivalent for Talk). Pieces: - ChatChannelKind enum (UI.Abstractions) - mirrors holtburger's ChatChannelKind (references/holtburger/.../client/types.rs:35-49). - SendChatCmd record (UI.Abstractions) - (Channel, TargetName?, Text). - LiveCommandBus (UI.Abstractions) - single-handler-per-type; Register<T> throws on double-register; Publish<T> logs missing handler but does not throw. - ChannelResolver (UI.Abstractions) - port of holtburger's resolve_legacy_channel (client/commands.rs:50-62) mapping ChatChannelKind to legacy ChatChannel ids verbatim from holtburger-protocol/.../chat/types.rs:8-24 (Fellow=0x0800, AllegianceBroadcast=0x02000000, Vassals=0x1000, Patron=0x2000, Monarch=0x4000, CoVassals=0x01000000). - WorldSession.SendTalk / SendTell / SendChannel - 3-line wrappers around existing ChatRequests.Build* + SendGameAction. Internal GameActionCapture seam + InternalsVisibleTo for tests. - GameWindow registers SendChatCmd handler: Say -> SendTalk + ChatLog echo, Tell -> SendTell + echo, channel kinds -> ChannelResolver.Resolve -> SendChannel + echo. 12 new tests across SendChatCmd + LiveCommandBus + ChannelResolver + WorldSessionChat. NullCommandBus.Instance retained for back-compat when no live session. Solution total: 893 green (51 + 229 + 613). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ff5ed9ec0b
commit
8e6e5a0b61
10 changed files with 457 additions and 1 deletions
47
src/AcDream.UI.Abstractions/ChannelResolver.cs
Normal file
47
src/AcDream.UI.Abstractions/ChannelResolver.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
namespace AcDream.UI.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Maps a <see cref="ChatChannelKind"/> to the legacy <c>ChatChannel</c>
|
||||
/// bitflag id used by the 0x0147 ChatChannel GameAction. Ported from
|
||||
/// holtburger's <c>resolve_legacy_channel</c>
|
||||
/// (<c>references/holtburger/crates/holtburger-core/src/client/commands.rs</c>
|
||||
/// lines 50-62) cross-referenced against the <c>ChatChannel</c> enum
|
||||
/// (<c>references/holtburger/crates/holtburger-protocol/src/messages/chat/types.rs</c>
|
||||
/// lines 8-24) for the actual numeric ids.
|
||||
///
|
||||
/// <para>
|
||||
/// Returns <c>null</c> for non-legacy kinds (Say, Tell, Unknown, and the
|
||||
/// Turbine-routed General/Trade/etc.) — those callers handle dispatch
|
||||
/// themselves. <see cref="ChatChannelKind.Say"/> rides Talk (0x0015) and
|
||||
/// <see cref="ChatChannelKind.Tell"/> rides Tell (0x005D); the Turbine
|
||||
/// channels need TurbineChat wiring not yet in place (Phase I.6).
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public static class ChannelResolver
|
||||
{
|
||||
/// <summary>Result of a successful legacy-channel resolution.</summary>
|
||||
public readonly record struct Resolved(uint ChannelId, string DisplayName);
|
||||
|
||||
/// <summary>
|
||||
/// Resolve <paramref name="kind"/> to a legacy ChatChannel id + a
|
||||
/// human-readable display name for chat-log echo. Returns <c>null</c>
|
||||
/// for non-legacy kinds; the caller routes those separately.
|
||||
/// </summary>
|
||||
public static Resolved? Resolve(ChatChannelKind kind) => kind switch
|
||||
{
|
||||
// ChatChannel values from holtburger-protocol/src/messages/chat/types.rs:
|
||||
// Fellow = 0x00000800
|
||||
// Vassals = 0x00001000
|
||||
// Patron = 0x00002000
|
||||
// Monarch = 0x00004000
|
||||
// CoVassals = 0x01000000
|
||||
// AllegianceBroadcast = 0x02000000
|
||||
ChatChannelKind.Fellowship => new Resolved(0x00000800u, "Fellowship"),
|
||||
ChatChannelKind.Allegiance => new Resolved(0x02000000u, "Allegiance"),
|
||||
ChatChannelKind.Vassals => new Resolved(0x00001000u, "Vassals"),
|
||||
ChatChannelKind.Patron => new Resolved(0x00002000u, "Patron"),
|
||||
ChatChannelKind.Monarch => new Resolved(0x00004000u, "Monarch"),
|
||||
ChatChannelKind.CoVassals => new Resolved(0x01000000u, "CoVassals"),
|
||||
_ => null,
|
||||
};
|
||||
}
|
||||
40
src/AcDream.UI.Abstractions/ChatChannelKind.cs
Normal file
40
src/AcDream.UI.Abstractions/ChatChannelKind.cs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
namespace AcDream.UI.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Outbound chat channel selector. Mirrors holtburger's <c>ChatChannelKind</c>
|
||||
/// (<c>references/holtburger/crates/holtburger-core/src/client/types.rs</c>
|
||||
/// lines 35-49) plus a synthetic <see cref="Say"/> + <see cref="Tell"/> for
|
||||
/// the two non-channel cases — local speech and whispers — so a single
|
||||
/// <see cref="SendChatCmd"/> can carry every outbound flavour the chat
|
||||
/// panel emits.
|
||||
///
|
||||
/// <para>
|
||||
/// Channels split into:
|
||||
/// <list type="bullet">
|
||||
/// <item><b>Legacy</b> (Fellowship..CoVassals): map to a fixed <c>ChatChannel</c>
|
||||
/// bitflag id via <see cref="ChannelResolver"/> and ride 0x0147 ChatChannel.</item>
|
||||
/// <item><b>Turbine</b> (General..Olthoi): require a TurbineChat channel id
|
||||
/// resolved at runtime — not yet wired (Phase I.6 owns TurbineChat).</item>
|
||||
/// <item><b>Say</b> / <b>Tell</b>: route to the dedicated 0x0015 / 0x005D
|
||||
/// opcodes — no channel id needed.</item>
|
||||
/// </list>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public enum ChatChannelKind
|
||||
{
|
||||
Say,
|
||||
Tell,
|
||||
Fellowship,
|
||||
Allegiance,
|
||||
Vassals,
|
||||
Patron,
|
||||
Monarch,
|
||||
CoVassals,
|
||||
General,
|
||||
Trade,
|
||||
Lfg,
|
||||
Roleplay,
|
||||
Society,
|
||||
Olthoi,
|
||||
Unknown,
|
||||
}
|
||||
64
src/AcDream.UI.Abstractions/LiveCommandBus.cs
Normal file
64
src/AcDream.UI.Abstractions/LiveCommandBus.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AcDream.UI.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Real <see cref="ICommandBus"/> implementation — single-handler-per-type
|
||||
/// dispatch keyed by <c>typeof(T)</c>. Replaces <see cref="NullCommandBus"/>
|
||||
/// in live sessions; <see cref="NullCommandBus"/> persists for tests and
|
||||
/// non-live UI scenarios where no command flow is wanted.
|
||||
///
|
||||
/// <para>
|
||||
/// <b>Threading.</b> Both <see cref="Register{T}"/> and <see cref="Publish{T}"/>
|
||||
/// run on the render thread today (panels render on the render thread, and
|
||||
/// host wiring happens at startup). The internal handler dictionary is
|
||||
/// not synchronized — register all handlers during host setup before the
|
||||
/// panel host starts rendering.
|
||||
/// </para>
|
||||
///
|
||||
/// <para>
|
||||
/// Phase I.3 of the chat/UI consolidation plan
|
||||
/// (<c>~/.claude/plans/ticklish-conjuring-cake.md</c>): primary client of
|
||||
/// the bus is the <see cref="SendChatCmd"/> handler wired by GameWindow
|
||||
/// against <c>WorldSession.SendTalk/SendTell/SendChannel</c> + the local
|
||||
/// <c>ChatLog</c> echo.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed class LiveCommandBus : ICommandBus
|
||||
{
|
||||
private readonly Dictionary<Type, Delegate> _handlers = new();
|
||||
|
||||
/// <summary>
|
||||
/// Register a single handler for commands of type <typeparamref name="T"/>.
|
||||
/// Throws <see cref="InvalidOperationException"/> if a handler is already
|
||||
/// registered for this type — single-handler-per-type is intentional so
|
||||
/// command routing is unambiguous.
|
||||
/// </summary>
|
||||
public void Register<T>(Action<T> handler) where T : notnull
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(handler);
|
||||
if (_handlers.ContainsKey(typeof(T)))
|
||||
throw new InvalidOperationException(
|
||||
$"A handler for command type {typeof(T).FullName} is already registered.");
|
||||
_handlers[typeof(T)] = handler;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Publish<T>(T command) where T : notnull
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(command);
|
||||
if (_handlers.TryGetValue(typeof(T), out var handler))
|
||||
{
|
||||
((Action<T>)handler).Invoke(command);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Soft-warn: command published with no registered handler.
|
||||
// Don't throw — the host may publish optional commands a non-
|
||||
// live build doesn't wire (e.g. inventory pre-Phase I.7).
|
||||
Console.WriteLine(
|
||||
$"[LiveCommandBus] no handler registered for {typeof(T).FullName}; dropping.");
|
||||
}
|
||||
}
|
||||
}
|
||||
14
src/AcDream.UI.Abstractions/SendChatCmd.cs
Normal file
14
src/AcDream.UI.Abstractions/SendChatCmd.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
namespace AcDream.UI.Abstractions;
|
||||
|
||||
/// <summary>
|
||||
/// Command published by chat panels to send a message. The host resolves
|
||||
/// <see cref="Channel"/> + <see cref="TargetName"/> + <see cref="Text"/>
|
||||
/// into the right wire opcode (Talk, Tell, or ChatChannel) and echoes
|
||||
/// locally via <c>ChatLog.OnSelfSent</c>.
|
||||
///
|
||||
/// <para>
|
||||
/// <see cref="TargetName"/> is meaningful only for
|
||||
/// <see cref="ChatChannelKind.Tell"/>; ignored otherwise.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed record SendChatCmd(ChatChannelKind Channel, string? TargetName, string Text);
|
||||
Loading…
Add table
Add a link
Reference in a new issue