Redistribuits els .cpp en carpetes
Actualitzat cmake Modificats els include de SDL2 a SDL3
This commit is contained in:
468
source/input.cpp
468
source/input.cpp
@@ -1,258 +1,205 @@
|
||||
#include "input.h"
|
||||
#include <SDL2/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||
#include <SDL2/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL2/SDL_events.h> // Para SDL_ENABLE
|
||||
#include <SDL2/SDL_keyboard.h> // Para SDL_GetKeyboardState
|
||||
#include <algorithm> // Para find
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||
#include <iterator> // Para distance
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||
#include <utility> // Para pair
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_INIT_GAMECONTROLLER, SDL_InitSubS...
|
||||
#include <SDL3/SDL_error.h> // Para SDL_GetError
|
||||
#include <SDL3/SDL_events.h> // Para SDL_ENABLE
|
||||
#include <SDL3/SDL_keyboard.h> // Para SDL_GetKeyboardState
|
||||
|
||||
#include <algorithm> // Para find
|
||||
#include <iostream> // Para basic_ostream, operator<<, cout, endl
|
||||
#include <iterator> // Para distance
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_cons...
|
||||
#include <utility> // Para pair
|
||||
|
||||
// [SINGLETON]
|
||||
Input *Input::input_ = nullptr;
|
||||
Input* Input::input_ = nullptr;
|
||||
|
||||
// [SINGLETON] Crearemos el objeto con esta función estática
|
||||
void Input::init(const std::string &game_controller_db_path)
|
||||
{
|
||||
Input::input_ = new Input(game_controller_db_path);
|
||||
void Input::init(const std::string& game_controller_db_path) {
|
||||
Input::input_ = new Input(game_controller_db_path);
|
||||
}
|
||||
|
||||
// [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
void Input::destroy()
|
||||
{
|
||||
delete Input::input_;
|
||||
void Input::destroy() {
|
||||
delete Input::input_;
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Input *Input::get()
|
||||
{
|
||||
return Input::input_;
|
||||
Input* Input::get() {
|
||||
return Input::input_;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Input::Input(const std::string &game_controller_db_path)
|
||||
: game_controller_db_path_(game_controller_db_path)
|
||||
{
|
||||
// Busca si hay mandos conectados
|
||||
discoverGameControllers();
|
||||
Input::Input(const std::string& game_controller_db_path)
|
||||
: game_controller_db_path_(game_controller_db_path) {
|
||||
// Busca si hay mandos conectados
|
||||
discoverGameControllers();
|
||||
|
||||
// Inicializa los vectores
|
||||
key_bindings_.resize(static_cast<int>(InputAction::SIZE), KeyBindings());
|
||||
controller_bindings_.resize(num_gamepads_, std::vector<ControllerBindings>(static_cast<int>(InputAction::SIZE), ControllerBindings()));
|
||||
// Inicializa los vectores
|
||||
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_ = {InputAction::JUMP};
|
||||
// Listado de los inputs para jugar que utilizan botones, ni palancas ni crucetas
|
||||
button_inputs_ = {InputAction::JUMP};
|
||||
}
|
||||
|
||||
// Asigna inputs a teclas
|
||||
void Input::bindKey(InputAction input, SDL_Scancode code)
|
||||
{
|
||||
key_bindings_.at(static_cast<int>(input)).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, InputAction input, SDL_GameControllerButton button)
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button;
|
||||
}
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input, SDL_GameControllerButton button) {
|
||||
if (controller_index < num_gamepads_) {
|
||||
controller_bindings_.at(controller_index).at(static_cast<int>(input)).button = button;
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna inputs a botones del mando
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input_target, InputAction input_source)
|
||||
{
|
||||
if (controller_index < num_gamepads_)
|
||||
{
|
||||
controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button;
|
||||
}
|
||||
void Input::bindGameControllerButton(int controller_index, InputAction input_target, InputAction input_source) {
|
||||
if (controller_index < num_gamepads_) {
|
||||
controller_bindings_.at(controller_index).at(static_cast<int>(input_target)).button = controller_bindings_.at(controller_index).at(static_cast<int>(input_source)).button;
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si un input esta activo
|
||||
bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
bool Input::checkInput(InputAction input, bool repeat, InputDeviceToUse device, int controller_index) {
|
||||
bool success_keyboard = false;
|
||||
bool success_controller = false;
|
||||
const int input_index = static_cast<int>(input);
|
||||
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *keyStates = SDL_GetKeyboardState(nullptr);
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY) {
|
||||
const Uint8* keyStates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
success_keyboard = keyStates[key_bindings_[input_index].scancode] != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!key_bindings_[input_index].active)
|
||||
{
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0)
|
||||
{
|
||||
key_bindings_[input_index].active = true;
|
||||
success_keyboard = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (keyStates[key_bindings_[input_index].scancode] == 0)
|
||||
{
|
||||
key_bindings_[input_index].active = false;
|
||||
}
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (repeat) {
|
||||
success_keyboard = keyStates[key_bindings_[input_index].scancode] != 0;
|
||||
} else {
|
||||
if (!key_bindings_[input_index].active) {
|
||||
if (keyStates[key_bindings_[input_index].scancode] != 0) {
|
||||
key_bindings_[input_index].active = true;
|
||||
success_keyboard = true;
|
||||
} else {
|
||||
success_keyboard = false;
|
||||
}
|
||||
} else {
|
||||
if (keyStates[key_bindings_[input_index].scancode] == 0) {
|
||||
key_bindings_[input_index].active = false;
|
||||
}
|
||||
success_keyboard = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_)
|
||||
{
|
||||
if ((device == InputDeviceToUse::CONTROLLER) || (device == InputDeviceToUse::ANY))
|
||||
{
|
||||
success_controller = checkAxisInput(input, controller_index, repeat);
|
||||
if (gameControllerFound() && controller_index >= 0 && controller_index < num_gamepads_) {
|
||||
if ((device == InputDeviceToUse::CONTROLLER) || (device == InputDeviceToUse::ANY)) {
|
||||
success_controller = checkAxisInput(input, controller_index, repeat);
|
||||
|
||||
if (!success_controller)
|
||||
{
|
||||
if (repeat)
|
||||
{
|
||||
success_controller = SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!controller_bindings_.at(controller_index).at(input_index).active)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0)
|
||||
{
|
||||
controller_bindings_.at(controller_index).at(input_index).active = true;
|
||||
success_controller = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0)
|
||||
{
|
||||
controller_bindings_.at(controller_index).at(input_index).active = false;
|
||||
}
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!success_controller) {
|
||||
if (repeat) {
|
||||
success_controller = SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0;
|
||||
} else {
|
||||
if (!controller_bindings_.at(controller_index).at(input_index).active) {
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) != 0) {
|
||||
controller_bindings_.at(controller_index).at(input_index).active = true;
|
||||
success_controller = true;
|
||||
} else {
|
||||
success_controller = false;
|
||||
}
|
||||
} else {
|
||||
if (SDL_GameControllerGetButton(connected_controllers_.at(controller_index), controller_bindings_.at(controller_index).at(input_index).button) == 0) {
|
||||
controller_bindings_.at(controller_index).at(input_index).active = false;
|
||||
}
|
||||
success_controller = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (success_keyboard || success_controller);
|
||||
return (success_keyboard || success_controller);
|
||||
}
|
||||
|
||||
// Comprueba si hay almenos un input activo
|
||||
bool Input::checkAnyInput(InputDeviceToUse device, int controller_index)
|
||||
{
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
const Uint8 *mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
bool Input::checkAnyInput(InputDeviceToUse device, int controller_index) {
|
||||
if (device == InputDeviceToUse::KEYBOARD || device == InputDeviceToUse::ANY) {
|
||||
const Uint8* mKeystates = SDL_GetKeyboardState(nullptr);
|
||||
|
||||
for (int i = 0; i < (int)key_bindings_.size(); ++i)
|
||||
{
|
||||
if (mKeystates[key_bindings_[i].scancode] != 0 && !key_bindings_[i].active)
|
||||
{
|
||||
key_bindings_[i].active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < (int)key_bindings_.size(); ++i) {
|
||||
if (mKeystates[key_bindings_[i].scancode] != 0 && !key_bindings_[i].active) {
|
||||
key_bindings_[i].active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (gameControllerFound())
|
||||
{
|
||||
if (device == InputDeviceToUse::CONTROLLER || device == InputDeviceToUse::ANY)
|
||||
{
|
||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i)
|
||||
{
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][i].button) != 0 && !controller_bindings_[controller_index][i].active)
|
||||
{
|
||||
controller_bindings_[controller_index][i].active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (gameControllerFound()) {
|
||||
if (device == InputDeviceToUse::CONTROLLER || device == InputDeviceToUse::ANY) {
|
||||
for (int i = 0; i < (int)controller_bindings_.size(); ++i) {
|
||||
if (SDL_GameControllerGetButton(connected_controllers_[controller_index], controller_bindings_[controller_index][i].button) != 0 && !controller_bindings_[controller_index][i].active) {
|
||||
controller_bindings_[controller_index][i].active = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Busca si hay mandos conectados
|
||||
bool Input::discoverGameControllers()
|
||||
{
|
||||
bool found = false;
|
||||
bool Input::discoverGameControllers() {
|
||||
bool found = false;
|
||||
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1)
|
||||
{
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
}
|
||||
if (SDL_WasInit(SDL_INIT_GAMECONTROLLER) != 1) {
|
||||
SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER);
|
||||
}
|
||||
|
||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0)
|
||||
{
|
||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
if (SDL_GameControllerAddMappingsFromFile(game_controller_db_path_.c_str()) < 0) {
|
||||
std::cout << "Error, could not load " << game_controller_db_path_.c_str() << " file: " << SDL_GetError() << std::endl;
|
||||
}
|
||||
|
||||
num_joysticks_ = SDL_NumJoysticks();
|
||||
num_gamepads_ = 0;
|
||||
num_joysticks_ = SDL_NumJoysticks();
|
||||
num_gamepads_ = 0;
|
||||
|
||||
// Cuenta el número de mandos
|
||||
joysticks_.clear();
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
auto joy = SDL_JoystickOpen(i);
|
||||
joysticks_.push_back(joy);
|
||||
if (SDL_IsGameController(i))
|
||||
{
|
||||
num_gamepads_++;
|
||||
}
|
||||
}
|
||||
// Cuenta el número de mandos
|
||||
joysticks_.clear();
|
||||
for (int i = 0; i < num_joysticks_; ++i) {
|
||||
auto joy = SDL_JoystickOpen(i);
|
||||
joysticks_.push_back(joy);
|
||||
if (SDL_IsGameController(i)) {
|
||||
num_gamepads_++;
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
if (num_joysticks_ != num_gamepads_)
|
||||
{
|
||||
std::cout << "Joysticks found: " << num_joysticks_ << std::endl;
|
||||
std::cout << "Gamepads found : " << num_gamepads_ << std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||
}
|
||||
std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
if (num_joysticks_ != num_gamepads_) {
|
||||
std::cout << "Joysticks found: " << num_joysticks_ << std::endl;
|
||||
std::cout << "Gamepads found : " << num_gamepads_ << std::endl;
|
||||
} else {
|
||||
std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
|
||||
}
|
||||
|
||||
if (num_gamepads_ > 0)
|
||||
{
|
||||
found = true;
|
||||
if (num_gamepads_ > 0) {
|
||||
found = true;
|
||||
|
||||
for (int i = 0; i < num_gamepads_; i++)
|
||||
{
|
||||
// Abre el mando y lo añade a la lista
|
||||
auto pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1)
|
||||
{
|
||||
connected_controllers_.push_back(pad);
|
||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||
std::cout << "#" << i << ": " << name << std::endl;
|
||||
controller_names_.push_back(name);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < num_gamepads_; i++) {
|
||||
// Abre el mando y lo añade a la lista
|
||||
auto pad = SDL_GameControllerOpen(i);
|
||||
if (SDL_GameControllerGetAttached(pad) == 1) {
|
||||
connected_controllers_.push_back(pad);
|
||||
const std::string name = SDL_GameControllerNameForIndex(i);
|
||||
std::cout << "#" << i << ": " << name << std::endl;
|
||||
controller_names_.push_back(name);
|
||||
} else {
|
||||
std::cout << "SDL_GetError() = " << SDL_GetError() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
SDL_GameControllerEventState(SDL_ENABLE);
|
||||
}
|
||||
|
||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
return found;
|
||||
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
|
||||
return found;
|
||||
}
|
||||
|
||||
// Comprueba si hay algun mando conectado
|
||||
@@ -265,79 +212,66 @@ std::string Input::getControllerName(int controller_index) const { return num_ga
|
||||
int Input::getNumControllers() const { return num_gamepads_; }
|
||||
|
||||
// Obtiene el indice del controlador a partir de un event.id
|
||||
int Input::getJoyIndex(int id) const
|
||||
{
|
||||
for (int i = 0; i < num_joysticks_; ++i)
|
||||
{
|
||||
if (SDL_JoystickInstanceID(joysticks_[i]) == id)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
int Input::getJoyIndex(int id) const {
|
||||
for (int i = 0; i < num_joysticks_; ++i) {
|
||||
if (SDL_JoystickInstanceID(joysticks_[i]) == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Obtiene el SDL_GameControllerButton asignado a un input
|
||||
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputAction input) const
|
||||
{
|
||||
return controller_bindings_[controller_index][static_cast<int>(input)].button;
|
||||
SDL_GameControllerButton Input::getControllerBinding(int controller_index, InputAction input) const {
|
||||
return controller_bindings_[controller_index][static_cast<int>(input)].button;
|
||||
}
|
||||
|
||||
// Obtiene el indice a partir del nombre del mando
|
||||
int Input::getIndexByName(const std::string &name) const
|
||||
{
|
||||
auto it = std::find(controller_names_.begin(), controller_names_.end(), name);
|
||||
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
|
||||
int Input::getIndexByName(const std::string& name) const {
|
||||
auto it = std::find(controller_names_.begin(), controller_names_.end(), name);
|
||||
return it != controller_names_.end() ? std::distance(controller_names_.begin(), it) : -1;
|
||||
}
|
||||
|
||||
// Comprueba el eje del mando
|
||||
bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat)
|
||||
{
|
||||
// Umbral para considerar el eje como activo
|
||||
const Sint16 threshold = 30000;
|
||||
bool axis_active_now = false;
|
||||
bool Input::checkAxisInput(InputAction input, int controller_index, bool repeat) {
|
||||
// Umbral para considerar el eje como activo
|
||||
const Sint16 threshold = 30000;
|
||||
bool axis_active_now = false;
|
||||
|
||||
switch (input)
|
||||
{
|
||||
case InputAction::LEFT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -threshold;
|
||||
break;
|
||||
case InputAction::RIGHT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > threshold;
|
||||
break;
|
||||
case InputAction::UP:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -threshold;
|
||||
break;
|
||||
case InputAction::DOWN:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > threshold;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
switch (input) {
|
||||
case InputAction::LEFT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) < -threshold;
|
||||
break;
|
||||
case InputAction::RIGHT:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTX) > threshold;
|
||||
break;
|
||||
case InputAction::UP:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) < -threshold;
|
||||
break;
|
||||
case InputAction::DOWN:
|
||||
axis_active_now = SDL_GameControllerGetAxis(connected_controllers_[controller_index], SDL_CONTROLLER_AXIS_LEFTY) > threshold;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
// Referencia al binding correspondiente
|
||||
auto &binding = controller_bindings_.at(controller_index).at(static_cast<int>(input));
|
||||
// Referencia al binding correspondiente
|
||||
auto& binding = controller_bindings_.at(controller_index).at(static_cast<int>(input));
|
||||
|
||||
if (repeat)
|
||||
{
|
||||
// Si se permite repetir, simplemente devolvemos el estado actual
|
||||
return axis_active_now;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Si no se permite repetir, aplicamos la lógica de transición
|
||||
if (axis_active_now && !binding.axis_active)
|
||||
{
|
||||
// Transición de inactivo a activo
|
||||
binding.axis_active = true;
|
||||
return true;
|
||||
}
|
||||
else if (!axis_active_now && binding.axis_active)
|
||||
{
|
||||
// Transición de activo a inactivo
|
||||
binding.axis_active = false;
|
||||
}
|
||||
// Mantener el estado actual
|
||||
return false;
|
||||
}
|
||||
if (repeat) {
|
||||
// Si se permite repetir, simplemente devolvemos el estado actual
|
||||
return axis_active_now;
|
||||
} else {
|
||||
// Si no se permite repetir, aplicamos la lógica de transición
|
||||
if (axis_active_now && !binding.axis_active) {
|
||||
// Transición de inactivo a activo
|
||||
binding.axis_active = true;
|
||||
return true;
|
||||
} else if (!axis_active_now && binding.axis_active) {
|
||||
// Transición de activo a inactivo
|
||||
binding.axis_active = false;
|
||||
}
|
||||
// Mantener el estado actual
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user