migrant input: controllers.json guarda ara el path
migrant input: define_buttons no agarra inputs del mando que no toca falta: Options ha de comprovar que el gamepad que te en la configuracio estiga o no estiga conectat
This commit is contained in:
@@ -8,22 +8,24 @@
|
||||
#include "input_types.h" // Solo incluimos los tipos compartidos
|
||||
|
||||
struct GamepadConfig {
|
||||
std::string name; // Nombre del dispositivo
|
||||
std::unordered_map<InputAction, SDL_GamepadButton> bindings; // Asociación acción-botón
|
||||
std::string name; // Nombre del dispositivo
|
||||
std::string path; // Ruta física del dispositivo
|
||||
std::unordered_map<InputAction, SDL_GamepadButton> bindings; // Asociación acción-botón
|
||||
|
||||
GamepadConfig(std::string name = "")
|
||||
: name(name),
|
||||
bindings{
|
||||
{InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST},
|
||||
{InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH},
|
||||
{InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST},
|
||||
{InputAction::START, SDL_GAMEPAD_BUTTON_START},
|
||||
{InputAction::SERVICE, SDL_GAMEPAD_BUTTON_BACK}} {}
|
||||
GamepadConfig(const std::string& name, const std::string& path)
|
||||
: name(name),
|
||||
path(path),
|
||||
bindings{
|
||||
{InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_WEST},
|
||||
{InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_NORTH},
|
||||
{InputAction::FIRE_RIGHT, SDL_GAMEPAD_BUTTON_EAST},
|
||||
{InputAction::START, SDL_GAMEPAD_BUTTON_START},
|
||||
{InputAction::SERVICE, SDL_GAMEPAD_BUTTON_BACK}} {}
|
||||
|
||||
// Reasigna un botón a una acción
|
||||
void rebindAction(InputAction action, SDL_GamepadButton new_button) {
|
||||
bindings[action] = new_button;
|
||||
}
|
||||
// Reasigna un botón a una acción
|
||||
void rebindAction(InputAction action, SDL_GamepadButton new_button) {
|
||||
bindings[action] = new_button;
|
||||
}
|
||||
};
|
||||
|
||||
using GamepadConfigs = std::vector<GamepadConfig>;
|
||||
@@ -39,13 +41,14 @@ class GamepadConfigManager {
|
||||
for (const auto& config : configs) {
|
||||
nlohmann::json gamepadJson;
|
||||
gamepadJson["name"] = config.name;
|
||||
gamepadJson["path"] = config.path;
|
||||
gamepadJson["bindings"] = nlohmann::json::object();
|
||||
|
||||
// Convertir bindings a JSON
|
||||
for (const auto& [action, button] : config.bindings) {
|
||||
auto actionIt = actionToString.find(action);
|
||||
auto buttonIt = buttonToString.find(button);
|
||||
|
||||
|
||||
if (actionIt != actionToString.end() && buttonIt != buttonToString.end()) {
|
||||
gamepadJson["bindings"][actionIt->second] = buttonIt->second;
|
||||
}
|
||||
@@ -93,7 +96,9 @@ class GamepadConfigManager {
|
||||
continue; // Saltar configuraciones malformadas
|
||||
}
|
||||
|
||||
GamepadConfig config(gamepadJson["name"]);
|
||||
// Leer el campo path si existe, si no dejarlo vacío
|
||||
std::string path = gamepadJson.contains("path") ? gamepadJson["path"].get<std::string>() : "";
|
||||
GamepadConfig config(gamepadJson["name"], path);
|
||||
|
||||
// Limpiar bindings por defecto para cargar los del archivo
|
||||
config.bindings.clear();
|
||||
|
||||
Reference in New Issue
Block a user