mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-01-17 14:28:30 +01:00
Deduplicate console command function list
This commit is contained in:
parent
01a6bf15be
commit
7a2d8f6aaf
@ -87,27 +87,34 @@ int CommandInterface::PlainCommand(String command)
|
|||||||
return retCode;
|
return retCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct Function
|
||||||
|
{
|
||||||
|
const char32_t *name;
|
||||||
|
AnyType (CommandInterface::*member)(std::deque<String> *);
|
||||||
|
};
|
||||||
|
static const std::vector<Function> functions = {
|
||||||
|
{ U"set" , &CommandInterface::tptS_set },
|
||||||
|
{ U"create", &CommandInterface::tptS_create },
|
||||||
|
{ U"delete", &CommandInterface::tptS_delete },
|
||||||
|
{ U"kill" , &CommandInterface::tptS_delete },
|
||||||
|
{ U"load" , &CommandInterface::tptS_load },
|
||||||
|
{ U"reset" , &CommandInterface::tptS_reset },
|
||||||
|
{ U"bubble", &CommandInterface::tptS_bubble },
|
||||||
|
{ U"quit" , &CommandInterface::tptS_quit },
|
||||||
|
};
|
||||||
|
|
||||||
ValueType CommandInterface::testType(String word)
|
ValueType CommandInterface::testType(String word)
|
||||||
{
|
{
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
String::value_type const *rawWord = word.c_str();
|
String::value_type const *rawWord = word.c_str();
|
||||||
//Function
|
//Function
|
||||||
if (word == "set")
|
for (auto &function : functions)
|
||||||
return TypeFunction;
|
{
|
||||||
else if (word == "create")
|
if (word == function.name)
|
||||||
return TypeFunction;
|
{
|
||||||
else if (word == "delete")
|
return TypeFunction;
|
||||||
return TypeFunction;
|
}
|
||||||
else if (word == "kill")
|
}
|
||||||
return TypeFunction;
|
|
||||||
else if (word == "load")
|
|
||||||
return TypeFunction;
|
|
||||||
else if (word == "reset")
|
|
||||||
return TypeFunction;
|
|
||||||
else if (word == "bubble")
|
|
||||||
return TypeFunction;
|
|
||||||
else if (word == "quit")
|
|
||||||
return TypeFunction;
|
|
||||||
|
|
||||||
//Basic type
|
//Basic type
|
||||||
for (i = 0; i < word.length(); i++)
|
for (i = 0; i < word.length(); i++)
|
||||||
@ -211,20 +218,12 @@ AnyType CommandInterface::eval(std::deque<String> * words)
|
|||||||
switch(wordType)
|
switch(wordType)
|
||||||
{
|
{
|
||||||
case TypeFunction:
|
case TypeFunction:
|
||||||
if(word == "set")
|
{
|
||||||
return tptS_set(words);
|
auto it = std::find_if(functions.begin(), functions.end(), [&word](auto &func) {
|
||||||
else if(word == "create")
|
return func.name == word;
|
||||||
return tptS_create(words);
|
});
|
||||||
else if(word == "delete" || word == "kill")
|
return (this->*(it->member))(words);
|
||||||
return tptS_delete(words);
|
}
|
||||||
else if(word == "load")
|
|
||||||
return tptS_load(words);
|
|
||||||
else if(word == "reset")
|
|
||||||
return tptS_reset(words);
|
|
||||||
else if(word == "bubble")
|
|
||||||
return tptS_bubble(words);
|
|
||||||
else if(word == "quit")
|
|
||||||
return tptS_quit(words);
|
|
||||||
break;
|
break;
|
||||||
case TypeNumber:
|
case TypeNumber:
|
||||||
return NumberType(parseNumber(word));
|
return NumberType(parseNumber(word));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user