/* +------------------------------------------------------+ ____/ \____ /| - Open source game framework licensed to freely use, | \ / / | copy, modify and sell without restriction | +--\ ^__^ /--+ | | | ~/ \~ | | - created for | | ~~~~~~~~~~~~ | +------------------------------------------------------+ | SPACE ~~~~~ | / | ~~~~~~~ BOX |/ +-------------*/ #pragma once #include #include #include #include #include "SDL.h" #include "Node.hpp" #include "Animation.hpp" struct KeyCombination { std::string command; int key; bool ctrl; bool shift; bool alt; }; class Input : public Node { private: std::map key_ids { {"up", SDLK_UP}, {"right", SDLK_RIGHT}, {"down", SDLK_DOWN}, {"left", SDLK_LEFT}, {"f1", SDLK_F1}, {"f2", SDLK_F2}, {"f3", SDLK_F3}, {"f4", SDLK_F4}, {"f5", SDLK_F5}, {"f6", SDLK_F6}, {"f7", SDLK_F7}, {"f8", SDLK_F8}, {"f9", SDLK_F9}, {"f10", SDLK_F10}, {"f11", SDLK_F11}, {"f12", SDLK_F11}, {"enter", SDLK_RETURN}, {"space", SDLK_SPACE}, {"escape", SDLK_ESCAPE} }; std::vector key_map; bool suppressed = false; KeyCombination parse_key(const std::string& command, const nlohmann::json& json) const; public: inline static std::string any = "any"; Animation unsuppress_animation = Animation(std::bind(&Input::unsuppress, this)); Input(Node*); void respond(SDL_Event&); void load_key_map(); SDL_Keycode get_key_code(const std::string&) const; void add_to_key_map(std::string, SDL_Keycode, bool = false, bool = false, bool = false); void print_key_combination(const KeyCombination&) const; void suppress(); void unsuppress(); bool is_suppressed(); virtual std::string class_name() const { return "Input"; } }; /* Add Input class to the sb namespace. This should be the default location, but Input is left in the global namespace * for backward compatibility. */ namespace sb { using ::Input; } #include "extension.hpp" #include "Configuration.hpp" #include "Delegate.hpp"