desacoplament de Player i Options
Player: canviat id de int a enum migrant input: eliminat Device, keyboard separat de la llista de mandos, llig i guarda configuracions de mandos falta: definir botons, asignar mandos a jugadors i guardar la asignació
This commit is contained in:
@@ -49,54 +49,54 @@ class Input {
|
||||
};
|
||||
|
||||
struct Keyboard {
|
||||
std::unordered_map<InputAction, KeyState> bindings;
|
||||
std::unordered_map<Action, KeyState> bindings;
|
||||
|
||||
Keyboard()
|
||||
: bindings{
|
||||
// Teclado - Movimiento del jugador
|
||||
{InputAction::UP, KeyState(SDL_SCANCODE_UP)},
|
||||
{InputAction::DOWN, KeyState(SDL_SCANCODE_DOWN)},
|
||||
{InputAction::LEFT, KeyState(SDL_SCANCODE_LEFT)},
|
||||
{InputAction::RIGHT, KeyState(SDL_SCANCODE_RIGHT)},
|
||||
{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
|
||||
{InputAction::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)},
|
||||
{InputAction::FIRE_CENTER, KeyState(SDL_SCANCODE_W)},
|
||||
{InputAction::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)},
|
||||
{Action::FIRE_LEFT, KeyState(SDL_SCANCODE_Q)},
|
||||
{Action::FIRE_CENTER, KeyState(SDL_SCANCODE_W)},
|
||||
{Action::FIRE_RIGHT, KeyState(SDL_SCANCODE_E)},
|
||||
|
||||
// Teclado - Interfaz
|
||||
{InputAction::START, KeyState(SDL_SCANCODE_RETURN)},
|
||||
{Action::START, KeyState(SDL_SCANCODE_RETURN)},
|
||||
|
||||
// Teclado - Menu de servicio
|
||||
{InputAction::SERVICE, KeyState(SDL_SCANCODE_0)},
|
||||
{InputAction::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)},
|
||||
{InputAction::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||
{Action::SERVICE, KeyState(SDL_SCANCODE_0)},
|
||||
{Action::SM_SELECT, KeyState(SDL_SCANCODE_RETURN)},
|
||||
{Action::SM_BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||
|
||||
// Teclado - Control del programa
|
||||
{InputAction::EXIT, KeyState(SDL_SCANCODE_ESCAPE)},
|
||||
{InputAction::PAUSE, KeyState(SDL_SCANCODE_P)},
|
||||
{InputAction::BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||
{Action::EXIT, KeyState(SDL_SCANCODE_ESCAPE)},
|
||||
{Action::PAUSE, KeyState(SDL_SCANCODE_P)},
|
||||
{Action::BACK, KeyState(SDL_SCANCODE_BACKSPACE)},
|
||||
|
||||
{InputAction::WINDOW_DEC_SIZE, KeyState(SDL_SCANCODE_F1)},
|
||||
{InputAction::WINDOW_INC_SIZE, KeyState(SDL_SCANCODE_F2)},
|
||||
{InputAction::WINDOW_FULLSCREEN, KeyState(SDL_SCANCODE_F3)},
|
||||
{InputAction::TOGGLE_VIDEO_SHADERS, KeyState(SDL_SCANCODE_F4)},
|
||||
{InputAction::TOGGLE_VIDEO_INTEGER_SCALE, KeyState(SDL_SCANCODE_F5)},
|
||||
{InputAction::TOGGLE_VIDEO_VSYNC, KeyState(SDL_SCANCODE_F6)},
|
||||
{Action::WINDOW_DEC_SIZE, KeyState(SDL_SCANCODE_F1)},
|
||||
{Action::WINDOW_INC_SIZE, KeyState(SDL_SCANCODE_F2)},
|
||||
{Action::WINDOW_FULLSCREEN, KeyState(SDL_SCANCODE_F3)},
|
||||
{Action::TOGGLE_VIDEO_SHADERS, KeyState(SDL_SCANCODE_F4)},
|
||||
{Action::TOGGLE_VIDEO_INTEGER_SCALE, KeyState(SDL_SCANCODE_F5)},
|
||||
{Action::TOGGLE_VIDEO_VSYNC, KeyState(SDL_SCANCODE_F6)},
|
||||
|
||||
{InputAction::TOGGLE_AUDIO, KeyState(SDL_SCANCODE_F7)},
|
||||
{InputAction::TOGGLE_AUTO_FIRE, KeyState(SDL_SCANCODE_F8)},
|
||||
{InputAction::CHANGE_LANG, KeyState(SDL_SCANCODE_F9)},
|
||||
{Action::TOGGLE_AUDIO, KeyState(SDL_SCANCODE_F7)},
|
||||
{Action::TOGGLE_AUTO_FIRE, KeyState(SDL_SCANCODE_F8)},
|
||||
{Action::CHANGE_LANG, KeyState(SDL_SCANCODE_F9)},
|
||||
|
||||
{InputAction::RESET, KeyState(SDL_SCANCODE_F10)},
|
||||
{InputAction::SHOW_INFO, KeyState(SDL_SCANCODE_F12)}} {}
|
||||
{Action::RESET, KeyState(SDL_SCANCODE_F10)},
|
||||
{Action::SHOW_INFO, KeyState(SDL_SCANCODE_F12)}} {}
|
||||
};
|
||||
|
||||
struct Gamepad {
|
||||
SDL_Gamepad *pad;
|
||||
SDL_JoystickID instance_id;
|
||||
std::string name;
|
||||
std::unordered_map<InputAction, ButtonState> bindings;
|
||||
std::unordered_map<Action, ButtonState> bindings;
|
||||
|
||||
Gamepad(SDL_Gamepad *gamepad)
|
||||
: pad(gamepad),
|
||||
@@ -104,19 +104,19 @@ class Input {
|
||||
name(std::string(SDL_GetGamepadName(gamepad))),
|
||||
bindings{
|
||||
// Mando - Movimiento del jugador
|
||||
{InputAction::UP, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_UP)},
|
||||
{InputAction::DOWN, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_DOWN)},
|
||||
{InputAction::LEFT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_LEFT)},
|
||||
{InputAction::RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_DPAD_RIGHT)},
|
||||
{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
|
||||
{InputAction::FIRE_LEFT, ButtonState(SDL_GAMEPAD_BUTTON_WEST)},
|
||||
{InputAction::FIRE_CENTER, ButtonState(SDL_GAMEPAD_BUTTON_NORTH)},
|
||||
{InputAction::FIRE_RIGHT, ButtonState(SDL_GAMEPAD_BUTTON_EAST)},
|
||||
{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
|
||||
{InputAction::START, ButtonState(SDL_GAMEPAD_BUTTON_START)},
|
||||
{InputAction::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {}
|
||||
{Action::START, ButtonState(SDL_GAMEPAD_BUTTON_START)},
|
||||
{Action::SERVICE, ButtonState(SDL_GAMEPAD_BUTTON_BACK)}} {}
|
||||
|
||||
~Gamepad() {
|
||||
if (pad) {
|
||||
@@ -125,7 +125,7 @@ class Input {
|
||||
}
|
||||
|
||||
// Reasigna un botón a una acción
|
||||
void rebindAction(InputAction action, SDL_GamepadButton new_button) {
|
||||
void rebindAction(Action action, SDL_GamepadButton new_button) {
|
||||
bindings[action] = new_button;
|
||||
}
|
||||
};
|
||||
@@ -149,7 +149,7 @@ class Input {
|
||||
// --- Métodos de gestión de mandos ---
|
||||
[[nodiscard]] auto gameControllerFound() const -> bool;
|
||||
auto getControllerName(std::shared_ptr<Gamepad> gamepad) const -> std::string;
|
||||
[[nodiscard]] auto getNumControllers() const -> int;
|
||||
[[nodiscard]] auto getNumGamepads() const -> int;
|
||||
[[nodiscard]] auto getJoyIndex(SDL_JoystickID id) const -> int;
|
||||
|
||||
// --- Métodos de consulta y utilidades ---
|
||||
@@ -175,7 +175,7 @@ class Input {
|
||||
std::vector<std::shared_ptr<Gamepad>> gamepads_;
|
||||
Keyboard keyboard_;
|
||||
std::vector<Action> button_inputs_;
|
||||
std::string game_controller_db_path_;
|
||||
std::string gamepad_mappings_file_;
|
||||
std::string gamepad_configs_file_;
|
||||
GamepadConfigs gamepad_configs_;
|
||||
|
||||
@@ -186,17 +186,17 @@ class Input {
|
||||
void remove_gamepad(SDL_JoystickID id);
|
||||
void addGamepadMappingsFromFile();
|
||||
void discoverGamepads();
|
||||
|
||||
|
||||
// --- Métodos para integración con GamepadConfigManager ---
|
||||
void loadGamepadConfigs();
|
||||
void saveGamepadConfigs();
|
||||
void applyGamepadConfig(std::shared_ptr<Gamepad> gamepad);
|
||||
void saveGamepadConfigFromGamepad(std::shared_ptr<Gamepad> gamepad);
|
||||
|
||||
|
||||
// Métodos auxiliares opcionales
|
||||
void setGamepadConfigsFile(const std::string& filename);
|
||||
GamepadConfig* getGamepadConfig(const std::string& gamepadName);
|
||||
bool removeGamepadConfig(const std::string& gamepadName);
|
||||
void setGamepadConfigsFile(const std::string &filename);
|
||||
GamepadConfig *getGamepadConfig(const std::string &gamepadName);
|
||||
bool removeGamepadConfig(const std::string &gamepadName);
|
||||
|
||||
// --- Constructor y destructor ---
|
||||
explicit Input(std::string game_controller_db_path, std::string gamepad_configs_file);
|
||||
|
||||
Reference in New Issue
Block a user