From da3b5b2131d2b4ff5cb127e92090fca568376835 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 24 May 2023 10:28:49 +1200 Subject: in-progress: Config refactor started, changed all existing keybind command args and added in the new files, still many errors --- commands.h | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 commands.h (limited to 'commands.h') diff --git a/commands.h b/commands.h new file mode 100644 index 0000000..f9a0999 --- /dev/null +++ b/commands.h @@ -0,0 +1,73 @@ +#pragma once + +#include "error.h" + +#include +#include +#include +#include + +enum MoveDir +{ + UP, + RIGHT, + DOWN, + LEFT +}; +enum CommandArgType +{ + STR, + NUM, + DIR, + STR_REST, + NUM_ARR_REST +}; + +struct NumArr +{ + int* arr; + int size; +}; +typedef union +{ + char* str; + int num; + NumArr numArr; + MoveDir dir; +} CommandArg; + +struct Command +{ + const std::string name; + const std::function func; + const int argc; + CommandArgType* argTypes; + std::any* module; +}; +class CommandsModule +{ + private: + std::vector commandList; + std::vector splitCommand(std::string command); + CommandArg* getCommandArgs(std::vector& args, const CommandArgType* argTypes, const int argc); + const void printHello(const CommandArg* argv); + const void echo(const CommandArg* argv); + public: + CommandsModule(); + ~CommandsModule(); + template + void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module); + void addCommand(Command c); + Command* lookupCommand(std::string name); + void runCommand(std::string command); + Err checkCommand(std::string command); +}; + +// YES I KNOW THIS IS BAD +// but it needs to be done this way +template +void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, CommandArgType* argTypes, T* module) +{ + Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, argc, argTypes, (std::any*)module}; + addCommand(c); +} -- cgit v1.2.3