tidy-fix automàtic (sense naming)

This commit is contained in:
2026-05-14 18:28:23 +02:00
parent 358e91ea30
commit b7a551c158
81 changed files with 1549 additions and 831 deletions
+44 -20
View File
@@ -52,8 +52,8 @@ namespace Gamepad {
// Recorta el nom visible del mando: trim des del primer '(' o '['
// (per a evitar coses com "Retroid Controller (vendor: 1001) ..."),
// elimina espais finals i talla a 25 caràcters.
static std::string prettyName(const char* raw) {
std::string name = (raw && *raw) ? raw : "Gamepad";
static auto prettyName(const char* raw) -> std::string {
std::string name = ((raw != nullptr) && (*raw != 0)) ? raw : "Gamepad";
const auto pos = name.find_first_of("([");
if (pos != std::string::npos) {
name.erase(pos);
@@ -64,7 +64,9 @@ namespace Gamepad {
if (name.size() > 25) {
name.resize(25);
}
if (name.empty()) name = "Gamepad";
if (name.empty()) {
name = "Gamepad";
}
return name;
}
@@ -98,12 +100,14 @@ namespace Gamepad {
static void openFirstGamepad() {
int count = 0;
SDL_JoystickID* ids = SDL_GetJoysticks(&count);
if (ids) {
if (ids != nullptr) {
for (int i = 0; i < count; ++i) {
installWebStandardMapping(ids[i]);
if (!SDL_IsGamepad(ids[i])) continue;
if (!SDL_IsGamepad(ids[i])) {
continue;
}
pad_ = SDL_OpenGamepad(ids[i]);
if (pad_) {
if (pad_ != nullptr) {
pad_id_ = ids[i];
SDL_Log("Gamepad connectat: %s", SDL_GetGamepadName(pad_));
break;
@@ -128,7 +132,7 @@ namespace Gamepad {
}
void destroy() {
if (pad_) {
if (pad_ != nullptr) {
SDL_CloseGamepad(pad_);
pad_ = nullptr;
pad_id_ = 0;
@@ -145,12 +149,14 @@ namespace Gamepad {
// GAMEPAD_ADDED) perquè SDL no reconeix el GUID. Escoltem els dos i
// injectem el mapping estàndard abans d'obrir el mando.
if (event.type == SDL_EVENT_GAMEPAD_ADDED || event.type == SDL_EVENT_JOYSTICK_ADDED) {
if (!pad_) {
if (pad_ == nullptr) {
SDL_JoystickID jid = event.jdevice.which;
installWebStandardMapping(jid);
if (!SDL_IsGamepad(jid)) return;
if (!SDL_IsGamepad(jid)) {
return;
}
pad_ = SDL_OpenGamepad(jid);
if (pad_) {
if (pad_ != nullptr) {
pad_id_ = jid;
std::string name = prettyName(SDL_GetGamepadName(pad_));
SDL_Log("Gamepad connectat: %s", name.c_str());
@@ -158,7 +164,7 @@ namespace Gamepad {
}
}
} else if (event.type == SDL_EVENT_GAMEPAD_REMOVED || event.type == SDL_EVENT_JOYSTICK_REMOVED) {
if (pad_ && event.jdevice.which == pad_id_) {
if ((pad_ != nullptr) && event.jdevice.which == pad_id_) {
std::string saved_name = prettyName(SDL_GetGamepadName(pad_));
SDL_Log("Gamepad desconnectat: %s", saved_name.c_str());
SDL_CloseGamepad(pad_);
@@ -190,7 +196,9 @@ namespace Gamepad {
}
void update() {
if (!pad_) return;
if (pad_ == nullptr) {
return;
}
// D-pad
bool dup = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_DPAD_UP);
@@ -220,19 +228,35 @@ namespace Gamepad {
bool back = SDL_GetGamepadButton(pad_, SDL_GAMEPAD_BUTTON_BACK);
// Select (Back) → obre/tanca menú de servei (flanc)
if (back && !prev_back_) pushKey(KeyConfig::scancode("menu_toggle"));
if (back && !prev_back_) {
pushKey(KeyConfig::scancode("menu_toggle"));
}
// Start → pausa (flanc)
if (start && !prev_start_) pushKey(KeyConfig::scancode("pause_toggle"));
if (start && !prev_start_) {
pushKey(KeyConfig::scancode("pause_toggle"));
}
if (Menu::isOpen()) {
// Navegació del menú per flanc
if (up && !prev_up_) pushKey(SDL_SCANCODE_UP);
if (dn && !prev_down_) pushKey(SDL_SCANCODE_DOWN);
if (lt && !prev_left_) pushKey(SDL_SCANCODE_LEFT);
if (rt && !prev_right_) pushKey(SDL_SCANCODE_RIGHT);
if (up && !prev_up_) {
pushKey(SDL_SCANCODE_UP);
}
if (dn && !prev_down_) {
pushKey(SDL_SCANCODE_DOWN);
}
if (lt && !prev_left_) {
pushKey(SDL_SCANCODE_LEFT);
}
if (rt && !prev_right_) {
pushKey(SDL_SCANCODE_RIGHT);
}
// EAST accepta, SOUTH cancela / endarrere
if (east && !prev_east_) pushKey(SDL_SCANCODE_RETURN);
if (south && !prev_south_) pushKey(SDL_SCANCODE_BACKSPACE);
if (east && !prev_east_) {
pushKey(SDL_SCANCODE_RETURN);
}
if (south && !prev_south_) {
pushKey(SDL_SCANCODE_BACKSPACE);
}
// Assegura que el joc no rep tecles de moviment mentre el menú està obert
JI_SetVirtualKey(SDL_SCANCODE_UP, JI_VSRC_GAMEPAD, false);
+30 -10
View File
@@ -34,7 +34,9 @@ namespace GlobalInputs {
snprintf(msg, sizeof(msg), Locale::get("notifications.zoom_fmt"), Screen::get()->getZoom());
Overlay::showNotification(msg);
}
if (dec_zoom) consumed = true;
if (dec_zoom) {
consumed = true;
}
dec_zoom_prev = dec_zoom;
// F2 — Augmentar zoom
@@ -45,7 +47,9 @@ namespace GlobalInputs {
snprintf(msg, sizeof(msg), Locale::get("notifications.zoom_fmt"), Screen::get()->getZoom());
Overlay::showNotification(msg);
}
if (inc_zoom) consumed = true;
if (inc_zoom) {
consumed = true;
}
inc_zoom_prev = inc_zoom;
// F3 — Toggle pantalla completa
@@ -54,7 +58,9 @@ namespace GlobalInputs {
Screen::get()->toggleFullscreen();
Overlay::showNotification(Screen::get()->isFullscreen() ? Locale::get("notifications.fullscreen") : Locale::get("notifications.windowed"));
}
if (fullscreen) consumed = true;
if (fullscreen) {
consumed = true;
}
fullscreen_prev = fullscreen;
// F4 — Toggle shaders
@@ -63,7 +69,9 @@ namespace GlobalInputs {
Screen::get()->toggleShaders();
Overlay::showNotification(Options::video.shader_enabled ? Locale::get("notifications.shader_on") : Locale::get("notifications.shader_off"));
}
if (shader) consumed = true;
if (shader) {
consumed = true;
}
shader_prev = shader;
// F5 — Toggle aspect ratio 4:3
@@ -72,7 +80,9 @@ namespace GlobalInputs {
Screen::get()->toggleAspectRatio();
Overlay::showNotification(Options::video.aspect_ratio_4_3 ? Locale::get("notifications.aspect_43") : Locale::get("notifications.aspect_square"));
}
if (aspect) consumed = true;
if (aspect) {
consumed = true;
}
aspect_prev = aspect;
// F6 — Toggle supersampling
@@ -82,7 +92,9 @@ namespace GlobalInputs {
Overlay::showNotification(Options::video.supersampling ? Locale::get("notifications.ss_on") : Locale::get("notifications.ss_off"));
}
}
if (ss) consumed = true;
if (ss) {
consumed = true;
}
ss_prev = ss;
// F7 — Canviar tipus de shader (PostFX ↔ CrtPi)
@@ -94,7 +106,9 @@ namespace GlobalInputs {
Overlay::showNotification(msg);
}
}
if (next_shader) consumed = true;
if (next_shader) {
consumed = true;
}
next_shader_prev = next_shader;
// F8 — Pròxim preset del shader actiu
@@ -106,7 +120,9 @@ namespace GlobalInputs {
Overlay::showNotification(msg);
}
}
if (next_preset) consumed = true;
if (next_preset) {
consumed = true;
}
next_preset_prev = next_preset;
// F9 — Cicla filtre de textura (NEAREST ↔ LINEAR), sempre aplicat
@@ -117,7 +133,9 @@ namespace GlobalInputs {
? Locale::get("notifications.filter_linear")
: Locale::get("notifications.filter_nearest"));
}
if (texture_filter) consumed = true;
if (texture_filter) {
consumed = true;
}
texture_filter_prev = texture_filter;
// F10 — Toggle render info (FPS, driver, shader)
@@ -125,7 +143,9 @@ namespace GlobalInputs {
if (render_info && !render_info_prev) {
Overlay::toggleRenderInfo();
}
if (render_info) consumed = true;
if (render_info) {
consumed = true;
}
render_info_prev = render_info;
return consumed;
+33 -11
View File
@@ -16,7 +16,9 @@ namespace KeyConfig {
auto findIndex(const std::string& id) -> size_t {
auto it = index_.find(id);
if (it == index_.end()) return SIZE_MAX;
if (it == index_.end()) {
return SIZE_MAX;
}
return it->second;
}
@@ -30,7 +32,9 @@ namespace KeyConfig {
std::string content(buf.begin(), buf.end());
try {
auto yaml = fkyaml::node::deserialize(content);
if (!yaml.contains("keys")) return;
if (!yaml.contains("keys")) {
return;
}
for (const auto& node : yaml["keys"]) {
KeyEntry entry;
@@ -59,7 +63,9 @@ namespace KeyConfig {
void applyOverrides(const std::string& disk_path) {
std::ifstream file(disk_path);
if (!file.good()) return;
if (!file.good()) {
return;
}
std::string content((std::istreambuf_iterator<char>(file)),
std::istreambuf_iterator<char>());
@@ -67,7 +73,9 @@ namespace KeyConfig {
try {
auto yaml = fkyaml::node::deserialize(content);
if (!yaml.contains("overrides")) return;
if (!yaml.contains("overrides")) {
return;
}
int applied = 0;
for (const auto& kv : yaml["overrides"].as_map()) {
@@ -118,28 +126,38 @@ namespace KeyConfig {
auto scancode(const std::string& id) -> SDL_Scancode {
auto idx = findIndex(id);
if (idx == SIZE_MAX) return SDL_SCANCODE_UNKNOWN;
if (idx == SIZE_MAX) {
return SDL_SCANCODE_UNKNOWN;
}
return entries_[idx].scancode;
}
auto scancodePtr(const std::string& id) -> SDL_Scancode* {
auto idx = findIndex(id);
if (idx == SIZE_MAX) return nullptr;
if (idx == SIZE_MAX) {
return nullptr;
}
return &entries_[idx].scancode;
}
void setScancode(const std::string& id, SDL_Scancode sc) {
auto idx = findIndex(id);
if (idx == SIZE_MAX) return;
if (idx == SIZE_MAX) {
return;
}
entries_[idx].scancode = sc;
const char* name = SDL_GetScancodeName(sc);
entries_[idx].code = (name != nullptr) ? name : "";
}
auto isGuiKey(SDL_Scancode sc) -> bool {
if (sc == SDL_SCANCODE_UNKNOWN) return false;
if (sc == SDL_SCANCODE_UNKNOWN) {
return false;
}
for (const auto& e : entries_) {
if (e.scancode == sc) return true;
if (e.scancode == sc) {
return true;
}
}
return false;
}
@@ -149,12 +167,16 @@ namespace KeyConfig {
}
auto saveOverrides() -> bool {
if (overrides_path_.empty()) return false;
if (overrides_path_.empty()) {
return false;
}
// Recull només les entrades remapeades.
std::vector<const KeyEntry*> changed;
for (const auto& e : entries_) {
if (e.scancode != e.default_scancode) changed.push_back(&e);
if (e.scancode != e.default_scancode) {
changed.push_back(&e);
}
}
std::ofstream file(overrides_path_);
+3 -1
View File
@@ -17,7 +17,9 @@ namespace KeyRemap {
void update() {
const bool* ks = SDL_GetKeyboardState(nullptr);
if (!ks) return;
if (ks == nullptr) {
return;
}
mirror(Options::keys_game.up, SDL_SCANCODE_UP, ks);
mirror(Options::keys_game.down, SDL_SCANCODE_DOWN, ks);
mirror(Options::keys_game.left, SDL_SCANCODE_LEFT, ks);