integrada classe Input

This commit is contained in:
2025-12-11 12:41:03 +01:00
parent 087b8d346d
commit 0ceaa75862
16 changed files with 3437 additions and 124 deletions

View File

@@ -1,5 +1,7 @@
#pragma once
#include <SDL3/SDL.h> // Para SDL_Scancode
#include <string>
namespace Options {
@@ -48,6 +50,28 @@ struct Audio {
float volume{1.0f};
};
// Controles de jugadors
struct KeyboardControls {
SDL_Scancode key_left{SDL_SCANCODE_LEFT};
SDL_Scancode key_right{SDL_SCANCODE_RIGHT};
SDL_Scancode key_thrust{SDL_SCANCODE_UP};
SDL_Scancode key_shoot{SDL_SCANCODE_SPACE};
};
struct GamepadControls {
int button_left{SDL_GAMEPAD_BUTTON_DPAD_LEFT};
int button_right{SDL_GAMEPAD_BUTTON_DPAD_RIGHT};
int button_thrust{SDL_GAMEPAD_BUTTON_WEST}; // X button
int button_shoot{SDL_GAMEPAD_BUTTON_SOUTH}; // A button
};
struct PlayerControls {
KeyboardControls keyboard{};
GamepadControls gamepad{};
std::string gamepad_name{""}; // Buit = auto-assignar per índex
};
// Variables globals (inline per evitar ODR violations)
inline std::string version{}; // Versió del config per validació
@@ -58,6 +82,29 @@ inline Gameplay gameplay{};
inline Rendering rendering{};
inline Audio audio{};
// Controles per jugador
inline PlayerControls player1{
.keyboard =
{.key_left = SDL_SCANCODE_LEFT,
.key_right = SDL_SCANCODE_RIGHT,
.key_thrust = SDL_SCANCODE_UP,
.key_shoot = SDL_SCANCODE_SPACE},
.gamepad_name = "" // Primer gamepad disponible
};
inline PlayerControls player2{
.keyboard =
{.key_left = SDL_SCANCODE_A,
.key_right = SDL_SCANCODE_D,
.key_thrust = SDL_SCANCODE_W,
.key_shoot = SDL_SCANCODE_LSHIFT},
.gamepad_name = "" // Segon gamepad disponible
};
// Per compatibilitat amb pollo (no utilitzat en orni, però necessari per Input)
inline KeyboardControls keyboard_controls{};
inline GamepadControls gamepad_controls{};
inline std::string config_file_path{}; // Establert per setConfigFile()
// Funcions públiques