Fixed formatting from clang-format

This commit is contained in:
nickci2002 2025-06-17 10:36:09 -04:00
parent 429c64a51b
commit 990e349424
4 changed files with 66 additions and 77 deletions

View file

@ -223,25 +223,19 @@ void ParseInputConfig(const std::string game_id = "") {
while (std::getline(file, line)) { while (std::getline(file, line)) {
lineCount++; lineCount++;
auto line_kpmask = (line.substr(0, 2) == "kp ") ? line.begin() + 2 : line.begin();
// Strip the ; and whitespace // Strip the ; and whitespace
line.erase(std::remove_if(line_kpmask, line.end(), line.erase(std::remove_if(line.begin(), line.end(),
[](unsigned char c) { return std::isspace(c); }), [](unsigned char c) { return std::isspace(c); }),
line.end()); line.end());
if (line.empty()) { if (line.empty()) {
continue; continue;
} }
// Truncate lines starting at # // Truncate lines starting at #
std::size_t comment_pos = line.find('#'); std::size_t comment_pos = line.find('#');
if (comment_pos != std::string::npos) { if (comment_pos != std::string::npos) {
line = line.substr(0, comment_pos); line = line.substr(0, comment_pos);
} }
// Remove trailing semicolon
if (!line.empty() && std::distance(line_kpmask, line.end()) != 1 && line[line.length() - 1] == ';') {
line = line.substr(0, line.length() - 1);
}
if (line.empty()) { if (line.empty()) {
continue; continue;
} }
@ -256,14 +250,18 @@ void ParseInputConfig(const std::string game_id = "") {
std::string output_string = line.substr(0, equal_pos); std::string output_string = line.substr(0, equal_pos);
std::string input_string = line.substr(equal_pos + 1); std::string input_string = line.substr(equal_pos + 1);
std::size_t comma_pos = input_string.find(','); // Remove trailing semicolon from input_string
if (!input_string.empty() && input_string[input_string.length() - 1] == ';') {
if (!(input_string == ";" || input_string == "kp;")) {
line = line.substr(0, line.length() - 1);
}
}
std::size_t comma_pos = input_string.find(',');
auto parseInt = [](const std::string& s) -> std::optional<int> { auto parseInt = [](const std::string& s) -> std::optional<int> {
int value = 0; try {
auto [ptr, ec] = std::from_chars(s.data(), s.data() + s.size(), value); return std::stoi(s);
if (ec == std::errc()) { } catch (...) {
return value;
} else {
return std::nullopt; return std::nullopt;
} }
}; };
@ -377,7 +375,6 @@ void ParseInputConfig(const std::string game_id = "") {
BindingConnection connection(InputID(), nullptr); BindingConnection connection(InputID(), nullptr);
auto button_it = string_to_cbutton_map.find(output_string); auto button_it = string_to_cbutton_map.find(output_string);
auto axis_it = string_to_axis_map.find(output_string); auto axis_it = string_to_axis_map.find(output_string);
if (binding.IsEmpty()) { if (binding.IsEmpty()) {
LOG_WARNING(Input, "Invalid format at line: {}, data: \"{}\", skipping line.", LOG_WARNING(Input, "Invalid format at line: {}, data: \"{}\", skipping line.",
lineCount, line); lineCount, line);
@ -444,11 +441,11 @@ InputEvent InputBinding::GetInputEventFromSDLEvent(const SDL_Event& e) {
e.type == SDL_EVENT_MOUSE_WHEEL, 0); e.type == SDL_EVENT_MOUSE_WHEEL, 0);
case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
case SDL_EVENT_GAMEPAD_BUTTON_UP: case SDL_EVENT_GAMEPAD_BUTTON_UP:
return InputEvent(InputType::Controller, static_cast<u32>(e.gbutton.button), return InputEvent(InputType::Controller, static_cast<u32>(e.gbutton.button), e.gbutton.down,
e.gbutton.down, 0); 0); // clang made me do it
case SDL_EVENT_GAMEPAD_AXIS_MOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
return InputEvent(InputType::Axis, static_cast<u32>(e.gaxis.axis), return InputEvent(InputType::Axis, static_cast<u32>(e.gaxis.axis), true,
true, e.gaxis.value / 256); e.gaxis.value / 256); // this too
default: default:
return InputEvent(); return InputEvent();
} }

View file

@ -32,7 +32,6 @@
#define KEY_TOGGLE 0x00200000 #define KEY_TOGGLE 0x00200000
#define SDL_INVALID_ID UINT32_MAX #define SDL_INVALID_ID UINT32_MAX
namespace Input { namespace Input {

View file

@ -225,12 +225,6 @@ void KBMSettings::SaveKBMConfig(bool close_on_save) {
while (std::getline(file, line)) { while (std::getline(file, line)) {
lineCount++; lineCount++;
// remove whitespace from the beginning of the line
auto line_kpmask = (line.substr(0, 2) == "kp ") ? line.begin() + 2 : line.begin();
line.erase(std::remove_if(line_kpmask, line.end(),
[](unsigned char c) { return std::isspace(c); }),
line.end());
if (line.empty()) { if (line.empty()) {
lines.push_back(line); lines.push_back(line);
continue; continue;
@ -354,7 +348,6 @@ void KBMSettings::SetUIValuestoMappings(std::string config_id) {
if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) == if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) ==
ControllerInputs.end()) { ControllerInputs.end()) {
if (output_string == "cross") { if (output_string == "cross") {
ui->CrossButton->setText(QString::fromStdString(input_string)); ui->CrossButton->setText(QString::fromStdString(input_string));
} else if (output_string == "circle") { } else if (output_string == "circle") {
@ -532,8 +525,8 @@ void KBMSettings::SetMapping(QString input) {
} }
// Helper lambda to get the modified button text based on the current keyboard modifiers // Helper lambda to get the modified button text based on the current keyboard modifiers
auto GetModifiedButton = [](Qt::KeyboardModifiers modifier, auto GetModifiedButton = [](Qt::KeyboardModifiers modifier, const std::string& m_button,
const std::string& m_button, const std::string& n_button) -> QString { const std::string& n_button) -> QString {
if (QApplication::keyboardModifiers() & modifier) { if (QApplication::keyboardModifiers() & modifier) {
return QString::fromStdString(m_button); return QString::fromStdString(m_button);
} else { } else {
@ -920,16 +913,16 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
if (wheelEvent->angleDelta().x() > 5) { if (wheelEvent->angleDelta().x() > 5) {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) {
// QT changes scrolling to horizontal for all widgets with the alt modifier // QT changes scrolling to horizontal for all widgets with the alt modifier
pressedKeys.insert(GetModifiedButton(Qt::AltModifier, pressedKeys.insert(
"mousewheelup", "mousewheelright")); GetModifiedButton(Qt::AltModifier, "mousewheelup", "mousewheelright"));
} else { } else {
QMessageBox::information(this, tr("Cannot set mapping"), QMessageBox::information(this, tr("Cannot set mapping"),
tr("Mousewheel cannot be mapped to stick outputs")); tr("Mousewheel cannot be mapped to stick outputs"));
} }
} else if (wheelEvent->angleDelta().x() < -5) { } else if (wheelEvent->angleDelta().x() < -5) {
if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) { if (std::find(AxisList.begin(), AxisList.end(), MappingButton) == AxisList.end()) {
pressedKeys.insert(GetModifiedButton(Qt::AltModifier, pressedKeys.insert(
"mousewheeldown", "mousewheelleft")); GetModifiedButton(Qt::AltModifier, "mousewheeldown", "mousewheelleft"));
} else { } else {
QMessageBox::information(this, tr("Cannot set mapping"), QMessageBox::information(this, tr("Cannot set mapping"),
tr("Mousewheel cannot be mapped to stick outputs")); tr("Mousewheel cannot be mapped to stick outputs"));