Kelsidavis-WoWee/include/ui/chat/chat_command_registry.hpp
Pavel Okhlopkov 42f1bb98ea refactor(chat): decompose into modular architecture, add GM commands, fix protocol
- Extract ChatPanel monolith into 15+ focused modules under ui/chat/
  (ChatInput, ChatTabManager, ChatTabCompleter, ChatMarkupParser,
  ChatMarkupRenderer, ChatCommandRegistry, ChatBubbleManager,
  ChatSettings, MacroEvaluator, GameStateAdapter, InputModifierAdapter)
- Split 2700-line chat_panel_commands.cpp into 11 command modules
- Add GM command handling: 190-command data table, dot-prefix interception,
  tab-completion, /gmhelp with category filter
- Fix ChatType enum to match WoW wire protocol (SAY=0x01 not 0x00);
  values 0x00-0x1B shared across Vanilla/TBC/WotLK
- Fix BG_SYSTEM_* values from 82-84 (UB in bitmask shifts) to 0x24-0x26
- Fix infinite Enter key loop after teleport (disable TOGGLE_CHAT repeat,
  add 2-frame input cooldown)
- Add tests: chat_markup_parser, chat_tab_completer, gm_commands,
  macro_evaluator

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
2026-04-12 14:59:56 +03:00

50 lines
1.7 KiB
C++

// ChatCommandRegistry — command registration + dispatch.
// Replaces the 500-line if/else chain in sendChatMessage() (Phase 3.1).
#pragma once
#include "ui/chat/i_chat_command.hpp"
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
namespace wowee {
namespace ui {
/**
* Registry of all slash commands.
*
* dispatch() looks up the command by alias and calls execute().
* getCompletions() provides tab-completion for /command prefixes.
*/
class ChatCommandRegistry {
public:
/** Register a command (takes ownership). All aliases are mapped. */
void registerCommand(std::unique_ptr<IChatCommand> cmd);
/**
* Dispatch a slash command.
* @param cmdLower lowercase command name (e.g. "cast", "whisper")
* @param ctx context with args, gameHandler, services, etc.
* @return result indicating if handled and whether to clear input
*/
ChatCommandResult dispatch(const std::string& cmdLower, ChatCommandContext& ctx);
/** Get all command aliases matching a prefix (for tab completion). */
std::vector<std::string> getCompletions(const std::string& prefix) const;
/** Get help entries: (alias, helpText) for all registered commands. */
std::vector<std::pair<std::string, std::string>> getHelpEntries() const;
/** Check if a command alias is registered. */
bool hasCommand(const std::string& alias) const;
private:
// alias → raw pointer (non-owning, commands_ owns the objects)
std::unordered_map<std::string, IChatCommand*> commandMap_;
// Ownership of all registered commands
std::vector<std::unique_ptr<IChatCommand>> commands_;
};
} // namespace ui
} // namespace wowee