go into command manager
Signed-off-by: Aleksey Selihov <faumaray@gmail.com>
This commit is contained in:
1 parent
b94b634a87
commit
1153721546
19 files changed
+752
-229
No files matched your search
@@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <Command/Interface.hpp>
|
||||
#include <PluginInterface.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
class CommandManager
|
||||
{
|
||||
public:
|
||||
|
||||
explicit CommandManager(std::shared_ptr<TS3Functions> ts3);
|
||||
|
||||
/**
|
||||
* @brief Registers a command class.
|
||||
* @tparam T The command class (must inherit ICommand).
|
||||
* @param names List of triggers (e.g., {"play", "p"}).
|
||||
*/
|
||||
template <typename T>
|
||||
void registerCommand(const std::string& primaryName)
|
||||
{
|
||||
auto cmd = std::make_shared<T>();
|
||||
|
||||
// Register primary
|
||||
m_commands[primaryName] = cmd;
|
||||
m_uniqueCommands.push_back({primaryName, cmd});
|
||||
|
||||
// Register aliases automatically from the class itself
|
||||
for (auto alias : cmd->getAliases()) {
|
||||
m_commands[std::string(alias)] = cmd;
|
||||
}
|
||||
}
|
||||
|
||||
bool dispatch(uint64 scHandlerID, anyID clientID,
|
||||
std::string_view invokerName, std::string_view message,
|
||||
std::weak_ptr<MusicManager> musicManager);
|
||||
|
||||
private:
|
||||
|
||||
struct CommandEntry {
|
||||
std::string primaryName;
|
||||
std::shared_ptr<Command> instance;
|
||||
};
|
||||
void registerAllDefaults();
|
||||
|
||||
// Internal Help Command (defined inside manager to access registry)
|
||||
class HelpCommand;
|
||||
|
||||
std::shared_ptr<TS3Functions> m_ts3;
|
||||
|
||||
// Map for fast lookup: "play" -> PlayCommand*
|
||||
std::unordered_map<std::string, std::shared_ptr<Command>> m_commands;
|
||||
|
||||
// List for generating help: {"play", PlayCommand*}
|
||||
std::vector<CommandEntry> m_uniqueCommands;
|
||||
};
|
||||
Reference in new issue
Block a user