Pasaeta de linters

This commit is contained in:
2025-08-06 13:05:04 +02:00
parent 8ed2dbcd4f
commit 1224af2a9b
40 changed files with 623 additions and 592 deletions

View File

@@ -1,15 +1,15 @@
#pragma once
#include <SDL3/SDL.h>
#include <SDL3/SDL.h> // Para SDL_Scancode, SDL_GamepadButton, SDL_JoystickID, SDL_CloseGamepad, SDL_Gamepad, SDL_GetGamepadJoystick, SDL_GetGamepadName, SDL_GetGamepadPath, SDL_GetJoystickID, Uint8, SDL_Event, Sint16
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
#include <array> // Para array
#include <memory> // Para shared_ptr, allocator
#include <string> // Para string
#include <unordered_map> // Para unordered_map
#include <vector> // Para vector
#include "gamepad_config_manager.h"
#include "input_types.h"
#include "gamepad_config_manager.h" // Para GamepadConfig (ptr only), GamepadConfigs
#include "input_types.h" // Para InputAction
// Clase Input: gestiona la entrada de teclado y mandos (singleton)
class Input {
@@ -121,7 +121,7 @@ class Input {
{Action::SM_BACK, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)}} {}
~Gamepad() {
if (pad) {
if (pad != nullptr) {
SDL_CloseGamepad(pad);
}
}
@@ -140,28 +140,28 @@ class Input {
static auto get() -> Input *;
// --- Métodos de configuración de controles ---
void bindKey(Action input, SDL_Scancode code);
void bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action input, SDL_GamepadButton button);
void bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action input_target, Action input_source);
void bindKey(Action action, SDL_Scancode code);
static void bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action action, SDL_GamepadButton button);
static void bindGameControllerButton(std::shared_ptr<Gamepad> gamepad, Action action_target, Action action_source);
// --- Métodos de consulta de entrada ---
void update();
auto checkAction(Action input, bool repeat = true, bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool;
auto checkAction(Action action, bool repeat = true, bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool;
auto checkAnyInput(bool check_keyboard = true, std::shared_ptr<Gamepad> gamepad = nullptr) -> bool;
auto checkAnyButton(bool repeat = DO_NOT_ALLOW_REPEAT) -> bool;
// --- Métodos de gestión de mandos ---
[[nodiscard]] auto gameControllerFound() const -> bool;
auto getControllerName(std::shared_ptr<Gamepad> gamepad) const -> std::string;
static auto getControllerName(std::shared_ptr<Gamepad> gamepad) -> std::string;
auto getControllerNames() const -> std::vector<std::string>;
[[nodiscard]] auto getNumGamepads() const -> int;
std::shared_ptr<Gamepad> getGamepad(SDL_JoystickID id) const;
std::shared_ptr<Input::Gamepad> getGamepadByName(const std::string &name) const;
const Gamepads &getGamepads() const { return gamepads_; }
auto getGamepad(SDL_JoystickID id) const -> std::shared_ptr<Gamepad>;
auto getGamepadByName(const std::string &name) const -> std::shared_ptr<Input::Gamepad>;
auto getGamepads() const -> const Gamepads & { return gamepads_; }
// --- Métodos de consulta y utilidades ---
[[nodiscard]] auto getControllerBinding(std::shared_ptr<Gamepad> gamepad, Action input) const -> SDL_GamepadButton;
[[nodiscard]] static auto inputToString(Action input) -> std::string;
[[nodiscard]] static auto getControllerBinding(std::shared_ptr<Gamepad> gamepad, Action action) -> SDL_GamepadButton;
[[nodiscard]] static auto inputToString(Action action) -> std::string;
[[nodiscard]] static auto stringToInput(const std::string &name) -> Action;
// --- Métodos de reseteo de estado de entrada ---
@@ -172,26 +172,26 @@ class Input {
void printConnectedGamepads() const;
std::shared_ptr<Gamepad> findAvailableGamepadByName(const std::string &gamepad_name);
auto findAvailableGamepadByName(const std::string &gamepad_name) -> std::shared_ptr<Gamepad>;
void saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad);
private:
// --- Constantes ---
static constexpr Sint16 AXIS_THRESHOLD = 30000;
static constexpr std::array<Action, 4> BUTTON_INPUTS = {Action::FIRE_LEFT, Action::FIRE_CENTER, Action::FIRE_RIGHT, Action::START}; // Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
// --- Variables internas ---
Gamepads gamepads_;
Keyboard keyboard_;
std::vector<Action> button_inputs_;
std::string gamepad_mappings_file_;
std::string gamepad_configs_file_;
GamepadConfigs gamepad_configs_;
// --- Métodos internos ---
void initSDLGamePad();
auto checkAxisInput(Action input, std::shared_ptr<Gamepad> gamepad, bool repeat) -> bool;
void add_gamepad(int device_index);
void remove_gamepad(SDL_JoystickID id);
static auto checkAxisInput(Action action, std::shared_ptr<Gamepad> gamepad, bool repeat) -> bool;
void addGamepad(int device_index);
void removeGamepad(SDL_JoystickID id);
void addGamepadMappingsFromFile();
void discoverGamepads();
@@ -202,8 +202,8 @@ class Input {
// Métodos auxiliares opcionales
void setGamepadConfigsFile(const std::string &filename);
GamepadConfig *getGamepadConfig(const std::string &gamepadName);
bool removeGamepadConfig(const std::string &gamepadName);
auto getGamepadConfig(const std::string &gamepad_name) -> GamepadConfig *;
auto removeGamepadConfig(const std::string &gamepad_name) -> bool;
// --- Constructor y destructor ---
explicit Input(std::string game_controller_db_path, std::string gamepad_configs_file);