2015-12-23 08:45:53 -05:00
|
|
|
#include "..\STDInclude.hpp"
|
|
|
|
|
|
|
|
namespace Components
|
|
|
|
{
|
|
|
|
std::vector<Game::cmd_function_t*> Command::Functions;
|
|
|
|
std::map<std::string, Command::Callback> Command::FunctionMap;
|
|
|
|
|
2015-12-23 16:21:03 -05:00
|
|
|
char* Command::Params::operator[](size_t index)
|
2015-12-23 08:45:53 -05:00
|
|
|
{
|
|
|
|
if (index >= this->Length())
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
return Game::cmd_argv[this->CommandId][index];
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Command::Params::Length()
|
|
|
|
{
|
|
|
|
return Game::cmd_argc[this->CommandId];
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::~Command()
|
|
|
|
{
|
|
|
|
for (auto command : Command::Functions)
|
|
|
|
{
|
|
|
|
delete command;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::Functions.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::Add(const char* name, Command::Callback callback)
|
|
|
|
{
|
|
|
|
Command::FunctionMap[Utils::StrToLower(name)] = callback;
|
|
|
|
Game::Cmd_AddCommand(name, Command::MainCallback, Command::Allocate(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Game::cmd_function_t* Command::Allocate()
|
|
|
|
{
|
|
|
|
Game::cmd_function_t* cmd = new Game::cmd_function_t;
|
|
|
|
Command::Functions.push_back(cmd);
|
|
|
|
|
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Command::MainCallback()
|
|
|
|
{
|
|
|
|
Command::Params params(*Game::cmd_id);
|
|
|
|
|
|
|
|
std::string command = Utils::StrToLower(params[0]);
|
|
|
|
|
|
|
|
if (Command::FunctionMap.find(command) != Command::FunctionMap.end())
|
|
|
|
{
|
|
|
|
Command::FunctionMap[command](params);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::Command()
|
|
|
|
{
|
|
|
|
// TODO: Add commands here?
|
|
|
|
}
|
|
|
|
}
|