style: renomenat InputType a InputActions
This commit is contained in:
@@ -38,21 +38,21 @@ Input::Input(const std::string &game_controller_db_path)
|
||||
discoverGameControllers();
|
||||
|
||||
// Inicializa los vectores
|
||||
key_bindings_.resize(static_cast<int>(InputType::NUMBER_OF_INPUTS), KeyBindings());
|
||||
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputType::NUMBER_OF_INPUTS), ControllerBindings()));
|
||||
key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings());
|
||||
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputAction::SIZE), ControllerBindings()));
|
||||
|
||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
||||
button_inputs_ = {InputType::FIRE_LEFT, InputType::FIRE_CENTER, InputType::FIRE_RIGHT, InputType::START};
|
||||
button_inputs_ = {InputAction::FIRE_LEFT, InputAction::FIRE_CENTER, InputAction::FIRE_RIGHT, InputAction::START};
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(InputType input, SDL_Scancode code)
|
||||
void Input::bindKey(InputAction input, SDL_Scancode code)
|
||||
{
|
||||
key_bindings_.at(static_cast<int>(input)).scancode = code;
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(int controller_index, InputType input, SDL_GameControllerButton button)
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input, SDL_GameControllerButton button)
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
@@ -61,7 +61,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input, SDL_
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(int controller_index, InputType input_target, InputType input_source)
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input_target, InputAction input_source)
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
@@ -70,7 +70,7 @@ void Input::bindGameControllerButton(int controller_index, InputType input_targe
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(InputType input, bool repeat, InputDeviceToUse device, int controller_index)
|
||||
bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
@@ -190,7 +190,7 @@ bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||
int Input::checkAnyButtonPressed(bool repeat)
|
||||
{
|
||||
// Si está pulsado el botón de servicio, ningún botón se puede considerar pulsado
|
||||
if (checkInput(InputType::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY))
|
||||
if (checkInput(InputAction::SERVICE, INPUT_ALLOW_REPEAT, InputDeviceToUse::ANY))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -335,7 +335,7 @@ void Input::printBindings(InputDeviceToUse device, int controller_index) const
|
||||
}
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputType input) const
|
||||
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputAction input) const
|
||||
{
|
||||
return controller_bindings_[controller_index][static_cast<int>(input)].button;
|
||||
}
|
||||
@@ -347,42 +347,42 @@ int Input::getIndexByName(const std::string &name) const
|
||||
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
|
||||
}
|
||||
|
||||
// Convierte un InputType a std::string
|
||||
std::string Input::to_string(InputType input) const
|
||||
// Convierte un InputAction a std::string
|
||||
std::string Input::to_string(InputAction input) const
|
||||
{
|
||||
switch (input)
|
||||
{
|
||||
case InputType::FIRE_LEFT:
|
||||
case InputAction::FIRE_LEFT:
|
||||
return "input_fire_left";
|
||||
case InputType::FIRE_CENTER:
|
||||
case InputAction::FIRE_CENTER:
|
||||
return "input_fire_center";
|
||||
case InputType::FIRE_RIGHT:
|
||||
case InputAction::FIRE_RIGHT:
|
||||
return "input_fire_right";
|
||||
case InputType::START:
|
||||
case InputAction::START:
|
||||
return "input_start";
|
||||
case InputType::SERVICE:
|
||||
case InputAction::SERVICE:
|
||||
return "input_service";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// Convierte un std::string a InputType
|
||||
InputType Input::to_inputs_e(const std::string &name) const
|
||||
// Convierte un std::string a InputAction
|
||||
InputAction Input::to_inputs_e(const std::string &name) const
|
||||
{
|
||||
static const std::unordered_map<std::string, InputType> inputMap = {
|
||||
{"input_fire_left", InputType::FIRE_LEFT},
|
||||
{"input_fire_center", InputType::FIRE_CENTER},
|
||||
{"input_fire_right", InputType::FIRE_RIGHT},
|
||||
{"input_start", InputType::START},
|
||||
{"input_service", InputType::SERVICE}};
|
||||
static const std::unordered_map<std::string, InputAction> inputMap = {
|
||||
{"input_fire_left", InputAction::FIRE_LEFT},
|
||||
{"input_fire_center", InputAction::FIRE_CENTER},
|
||||
{"input_fire_right", InputAction::FIRE_RIGHT},
|
||||
{"input_start", InputAction::START},
|
||||
{"input_service", InputAction::SERVICE}};
|
||||
|
||||
auto it = inputMap.find(name);
|
||||
return it != inputMap.end() ? it->second : InputType::NONE;
|
||||
return it != inputMap.end() ? it->second : InputAction::NONE;
|
||||
}
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool Input::checkAxisInput(InputType input, int controller_index, bool repeat)
|
||||
bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
|
||||
{
|
||||
// Umbral para considerar el eje como activo
|
||||
const Sint16 threshold = 30000;
|
||||
@@ -390,16 +390,16 @@ bool Input::checkAxisInput(InputType input, int controller_index, bool repeat)
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case InputType::LEFT:
|
||||
case InputAction::LEFT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -threshold;
|
||||
break;
|
||||
case InputType::RIGHT:
|
||||
case InputAction::RIGHT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > threshold;
|
||||
break;
|
||||
case InputType::UP:
|
||||
case InputAction::UP:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -threshold;
|
||||
break;
|
||||
case InputType::DOWN:
|
||||
case InputAction::DOWN:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > threshold;
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user