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 From 27137ec9d29c36df8117869773203b243849896c Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Fri, 26 May 2023 21:46:19 +1200 Subject: feat: Made keybinds work (I hope) Note: the config file reloading keybinds isn't quite working, though, need to ungrab the keys --- commands.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'commands.h') diff --git a/commands.h b/commands.h index f9a0999..2e364ac 100644 --- a/commands.h +++ b/commands.h @@ -18,7 +18,7 @@ enum CommandArgType { STR, NUM, - DIR, + MOVDIR, STR_REST, NUM_ARR_REST }; -- cgit v1.2.3 From 6b3dff404248bcf03e0bf0463a8c53d8918f7eec Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Wed, 31 May 2023 20:55:49 +1200 Subject: Added support for commands without a module Also made it easier to add commands by making the ~addCommand~ function accept a vector for ~argTypes~ and then convert it. --- commands.h | 73 +++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 29 deletions(-) (limited to 'commands.h') diff --git a/commands.h b/commands.h index 2e364ac..92801bd 100644 --- a/commands.h +++ b/commands.h @@ -8,20 +8,20 @@ #include enum MoveDir -{ - UP, - RIGHT, - DOWN, - LEFT -}; + { + UP, + RIGHT, + DOWN, + LEFT + }; enum CommandArgType -{ - STR, - NUM, - MOVDIR, - STR_REST, - NUM_ARR_REST -}; + { + STR, + NUM, + MOVDIR, + STR_REST, + NUM_ARR_REST + }; struct NumArr { @@ -40,27 +40,32 @@ struct Command { const std::string name; const std::function func; + const std::function staticFunc; 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); +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(std::string name, const void(*func)(const CommandArg*), const int argc, CommandArgType* argTypes); + template + void addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module); + void addCommand(std::string name, const void(*func)(const CommandArg*), const int argc, std::vector argTypes); + 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 @@ -68,6 +73,16 @@ class CommandsModule 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}; + Command c = {name, (const void*(std::any::*)(const CommandArg* argv)) func, nullptr, argc, argTypes, (std::any*)module}; addCommand(c); } +template +void CommandsModule::addCommand(std::string name, const void(T::*func)(const CommandArg*), const int argc, std::vector argTypes, T* module) +{ + CommandArgType* argTypesArr = new CommandArgType[argc]; + for(int i = 0; i < argc; i++) + { + argTypesArr[i] = argTypes[i]; + } + addCommand(name, func, argc, argTypesArr, module); +} -- cgit v1.2.3 From e9cc5756dbb0a2d079a7b5e3438d79945f819df5 Mon Sep 17 00:00:00 2001 From: BossCode45 Date: Sat, 3 Jun 2023 21:30:05 +1200 Subject: feat: Keybind updates Re added the ability to swap super and mod as a config parameter (the ~swapmods~) command). Finally fixed keybinds sometimes not working because of numlock, bitwise & with the modifiers I actually care about. --- commands.h | 2 -- 1 file changed, 2 deletions(-) (limited to 'commands.h') diff --git a/commands.h b/commands.h index 92801bd..d7f2351 100644 --- a/commands.h +++ b/commands.h @@ -51,8 +51,6 @@ 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(); -- cgit v1.2.3