diff --git a/source/input.cpp b/source/input.cpp index 1fa9b15..48b0ed8 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -143,7 +143,7 @@ auto Input::getNumGamepads() const -> int { return gamepads_.size(); } // Obtiene el gamepad a partir de un event.id std::shared_ptr Input::getGamepad(SDL_JoystickID id) const { - for (const auto& gamepad : gamepads_) { + for (const auto &gamepad : gamepads_) { if (gamepad->instance_id == id) { return gamepad; } diff --git a/source/input.h b/source/input.h index 88ade8a..387cf8b 100644 --- a/source/input.h +++ b/source/input.h @@ -49,26 +49,26 @@ class Input { Keyboard() : bindings{ - // Teclado - Movimiento del jugador + // Movimiento del jugador {Action::UP, KeyState(SDL_SCANCODE_UP)}, {Action::DOWN, KeyState(SDL_SCANCODE_DOWN)}, {Action::LEFT, KeyState(SDL_SCANCODE_LEFT)}, {Action::RIGHT, KeyState(SDL_SCANCODE_RIGHT)}, - // Teclado - Disparo del jugador + // Disparo del jugador {Action::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)}, {Action::FIRE_CENTER, KeyState(SDL_SCANCODE_W)}, {Action::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)}, - // Teclado - Interfaz + // Interfaz {Action::START, KeyState(SDL_SCANCODE_RETURN)}, - // Teclado - Menu de servicio + // Menu de servicio {Action::SERVICE, KeyState(SDL_SCANCODE_0)}, {Action::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)}, {Action::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)}, - // Teclado - Control del programa + // Control del programa {Action::EXIT, KeyState(SDL_SCANCODE_ESCAPE)}, {Action::PAUSE, KeyState(SDL_SCANCODE_P)}, {Action::BACK, KeyState(SDL_SCANCODE_BACKSPACE)}, @@ -99,20 +99,24 @@ class Input { instance_id(SDL_GetJoystickID(SDL_GetGamepadJoystick(gamepad))), name(std::string(SDL_GetGamepadName(gamepad))), bindings{ - // Mando - Movimiento del jugador + // Movimiento del jugador {Action::UP, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_UP)}, {Action::DOWN, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_DOWN)}, {Action::LEFT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_LEFT)}, {Action::RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)}, - // Mando - Disparo del jugador + // Disparo del jugador {Action::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)}, {Action::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}, {Action::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)}, - // Mando - Interfaz + // Interfaz {Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)}, - {Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {} + {Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}, + + // Menu de servicio + {Action::SM_SELECT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)}, + {Action::SM_BACK, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}} {} ~Gamepad() { if (pad) { @@ -149,7 +153,7 @@ class Input { auto getControllerName(std::shared_ptr gamepad) const -> std::string; [[nodiscard]] auto getNumGamepads() const -> int; std::shared_ptr getGamepad(SDL_JoystickID id) const; - const Gamepads& getGamepads() const { return gamepads_; } + const Gamepads &getGamepads() const { return gamepads_; } // --- Métodos de consulta y utilidades --- [[nodiscard]] auto getControllerBinding(std::shared_ptr gamepad, Action input) const -> SDL_GamepadButton; diff --git a/source/input_types.cpp b/source/input_types.cpp index 5c61e1f..cfa3ef1 100644 --- a/source/input_types.cpp +++ b/source/input_types.cpp @@ -91,4 +91,9 @@ const std::unordered_map stringToButton = { {"DPAD_DOWN", SDL_GAMEPAD_BUTTON_DPAD_DOWN}, {"DPAD_LEFT", SDL_GAMEPAD_BUTTON_DPAD_LEFT}, {"DPAD_RIGHT", SDL_GAMEPAD_BUTTON_DPAD_RIGHT} +}; + +const std::unordered_map actionToAction = { + {InputAction::SM_SELECT, InputAction::FIRE_LEFT}, + {InputAction::SM_BACK, InputAction::FIRE_CENTER}, }; \ No newline at end of file diff --git a/source/input_types.h b/source/input_types.h index 5fccf93..8952cd4 100644 --- a/source/input_types.h +++ b/source/input_types.h @@ -50,4 +50,5 @@ enum class InputAction : int { extern const std::unordered_map actionToString; extern const std::unordered_map stringToAction; extern const std::unordered_map buttonToString; -extern const std::unordered_map stringToButton; \ No newline at end of file +extern const std::unordered_map stringToButton; +extern const std::unordered_map actionToAction; \ No newline at end of file