VR-Engage  2.2
Loading...
Searching...
No Matches
makVre::DtChatCommandsManager Class Reference

Detailed Description

DtChatCommandsManager provides a centralized registry of available chat commands. It handles command registration, execution, and help text generation. When a user enters a command in the chat window, this manager locates and executes the appropriate command handler.

#include <vreChatCommandsManager.h>

Public Member Functions

 DtChatCommandsManager (DtPlayerStationApp &app)
 
 ~DtChatCommandsManager ()
 
virtual bool addCommand (std::string commandString, std::shared_ptr< DtChatCommand > command, bool takeOwnership=false)
 
virtual void removeCommand (std::string commandString)
 
virtual bool runCommand (std::string consoleString)
 
virtual std::string helpText (const std::string &parameters) const
 
 DtChatCommandsManager (const DtChatCommandsManager &orig)=delete
 
DtChatCommandsManageroperator= (const DtChatCommandsManager &orig)=delete
 

Protected Attributes

std::unordered_map< std::string, std::weak_ptr< DtChatCommand > > myCommandMap
 
std::unordered_map< std::string, std::shared_ptr< DtChatCommand > > myOwnedCommandMap
 
DtPlayerStationAppmyApp
 

Constructor & Destructor Documentation

◆ DtChatCommandsManager() [1/2]

makVre::DtChatCommandsManager::DtChatCommandsManager ( DtPlayerStationApp & app)

Constructor.

Parameters
appReference to the player station application

Creates a new chat commands manager associated with the given application. The manager starts with no registered commands.

Referenced by DtChatCommandsManager(), and operator=().

◆ ~DtChatCommandsManager()

makVre::DtChatCommandsManager::~DtChatCommandsManager ( )

Destructor.

Cleans up resources, including any owned command objects.

◆ DtChatCommandsManager() [2/2]

makVre::DtChatCommandsManager::DtChatCommandsManager ( const DtChatCommandsManager & orig)
delete

Deleted copy constructor and assignment operatorThese operations are not supported for the command manager.

References DtChatCommandsManager().

Member Function Documentation

◆ operator=()

DtChatCommandsManager & makVre::DtChatCommandsManager::operator= ( const DtChatCommandsManager & orig)
delete

Deleted copy constructor and assignment operatorThese operations are not supported for the command manager.

References DtChatCommandsManager().

◆ addCommand()

virtual bool makVre::DtChatCommandsManager::addCommand ( std::string commandString,
std::shared_ptr< DtChatCommand > command,
bool takeOwnership = false )
virtual

Registers a new chat command.

Parameters
commandStringString that triggers this command (without the leading slash)
commandShared pointer to the command implementation
takeOwnershipIf true, the manager takes ownership of the command object
Returns
True if the command was successfully added, false otherwise

Adds a new command to the registry. If takeOwnership is true, the manager will maintain a strong reference to the command and handle its lifetime. If false, the manager only keeps a weak reference, and the caller must ensure the command object remains valid for as long as it's registered.

◆ removeCommand()

virtual void makVre::DtChatCommandsManager::removeCommand ( std::string commandString)
virtual

Unregisters a chat command.

Parameters
commandStringString that triggers the command to remove

Removes a command from the registry. The command string is case-insensitive, so commands with the same spelling but different capitalization will be treated as identical. If the manager owned the command, it will be released.

◆ runCommand()

virtual bool makVre::DtChatCommandsManager::runCommand ( std::string consoleString)
virtual

Executes a command from a console input string.

Parameters
consoleStringFull string entered in the chat/console
Returns
True if a valid command was found and executed, false otherwise

Parses the input string to extract the command and its parameters, then executes the command if found. Commands are case-insensitive. The expected format is "/command parameters", where the leading slash identifies it as a command rather than normal chat text.

◆ helpText()

virtual std::string makVre::DtChatCommandsManager::helpText ( const std::string & parameters) const
virtual

Generates help text for available commands.

Parameters
parametersOptional parameters to filter or customize help output
Returns
String containing help text for all visible commands

Creates a formatted string containing help information for all registered commands that have showInHelp() returning true. This is typically shown when the user enters "/help" in the chat.

Member Data Documentation

◆ myCommandMap

std::unordered_map<std::string, std::weak_ptr<DtChatCommand> > makVre::DtChatCommandsManager::myCommandMap
protected

Map of command strings to weak pointers to commands.

Contains all registered commands that are not owned by the manager. The weak pointers prevent circular references but require external lifetime management for the command objects.

◆ myOwnedCommandMap

std::unordered_map<std::string, std::shared_ptr<DtChatCommand> > makVre::DtChatCommandsManager::myOwnedCommandMap
protected

Map of command strings to shared pointers to commands.

Contains all registered commands that are owned by the manager. The shared pointers ensure the command objects remain valid as long as they are registered.

◆ myApp

DtPlayerStationApp& makVre::DtChatCommandsManager::myApp
protected

Reference to the player station application.

Provides access to application services and state needed by commands.


The documentation for this class was generated from the following file: