clang-tidy readability-function-cognitive-complexity
This commit is contained in:
373
source/param.cpp
373
source/param.cpp
@@ -2,10 +2,12 @@
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogError, SDL_LogInfo
|
||||
|
||||
#include <fstream> // Para basic_istream, basic_ifstream, ifstream
|
||||
#include <fstream> // Para basic_istream, basic_ifstream, ifstream
|
||||
#include <functional>
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <string> // Para operator==, stoi, char_traits, string, ope...
|
||||
#include <unordered_map>
|
||||
|
||||
#include "utils.h" // Para Zone, Color, NotifyPosition, getFileName
|
||||
|
||||
@@ -15,7 +17,7 @@ Param param;
|
||||
void precalculateZones();
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
auto setParams(const std::string &var, const std::string &value) -> bool;
|
||||
auto setParams(const std::string& var, const std::string& value) -> bool;
|
||||
|
||||
// Establece valores por defecto a las variables
|
||||
void initParam() {
|
||||
@@ -89,7 +91,7 @@ void initParam() {
|
||||
}
|
||||
|
||||
// Carga los parámetros desde un archivo
|
||||
void loadParamsFromFile(const std::string &file_path) {
|
||||
void loadParamsFromFile(const std::string& file_path) {
|
||||
// Inicializa los parámetros con valores por defecto
|
||||
initParam();
|
||||
|
||||
@@ -128,219 +130,97 @@ void loadParamsFromFile(const std::string &file_path) {
|
||||
precalculateZones();
|
||||
}
|
||||
|
||||
// Asigna variables a partir de dos cadenas
|
||||
auto setParams(const std::string &var, const std::string &value) -> bool {
|
||||
// Indicador de éxito en la asignación
|
||||
auto success = true;
|
||||
auto setParams(const std::string& var, const std::string& value) -> bool {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> intParams = {
|
||||
{"game.width", [](const std::string& v) { param.game.width = std::stoi(v); }},
|
||||
{"game.height", [](const std::string& v) { param.game.height = std::stoi(v); }},
|
||||
{"game.item_size", [](const std::string& v) { param.game.item_size = std::stoi(v); }},
|
||||
{"game.play_area.rect.x", [](const std::string& v) { param.game.play_area.rect.x = std::stoi(v); }},
|
||||
{"game.play_area.rect.y", [](const std::string& v) { param.game.play_area.rect.y = std::stoi(v); }},
|
||||
{"game.play_area.rect.w", [](const std::string& v) { param.game.play_area.rect.w = std::stoi(v); }},
|
||||
{"game.play_area.rect.h", [](const std::string& v) { param.game.play_area.rect.h = std::stoi(v); }},
|
||||
{"game.name_entry_idle_time", [](const std::string& v) { param.game.name_entry_idle_time = std::stoi(v); }},
|
||||
{"game.name_entry_total_time", [](const std::string& v) { param.game.name_entry_total_time = std::stoi(v); }},
|
||||
{"game.hit_stop_ms", [](const std::string& v) { param.game.hit_stop_ms = std::stoi(v); }},
|
||||
{"fade.num_squares_width", [](const std::string& v) { param.fade.num_squares_width = std::stoi(v); }},
|
||||
{"fade.num_squares_height", [](const std::string& v) { param.fade.num_squares_height = std::stoi(v); }},
|
||||
{"fade.random_squares_delay", [](const std::string& v) { param.fade.random_squares_delay = std::stoi(v); }},
|
||||
{"fade.random_squares_mult", [](const std::string& v) { param.fade.random_squares_mult = std::stoi(v); }},
|
||||
{"fade.post_duration", [](const std::string& v) { param.fade.post_duration = std::stoi(v); }},
|
||||
{"fade.venetian_size", [](const std::string& v) { param.fade.venetian_size = std::stoi(v); }},
|
||||
{"scoreboard.rect.x", [](const std::string& v) { param.scoreboard.rect.x = std::stoi(v); }},
|
||||
{"scoreboard.rect.y", [](const std::string& v) { param.scoreboard.rect.y = std::stoi(v); }},
|
||||
{"scoreboard.rect.w", [](const std::string& v) { param.scoreboard.rect.w = std::stoi(v); }},
|
||||
{"scoreboard.rect.h", [](const std::string& v) { param.scoreboard.rect.h = std::stoi(v); }},
|
||||
{"scoreboard.skip_countdown_value", [](const std::string& v) { param.scoreboard.skip_countdown_value = std::stoi(v); }},
|
||||
{"title.press_start_position", [](const std::string& v) { param.title.press_start_position = std::stoi(v); }},
|
||||
{"title.title_duration", [](const std::string& v) { param.title.title_duration = std::stoi(v); }},
|
||||
{"title.arcade_edition_position", [](const std::string& v) { param.title.arcade_edition_position = std::stoi(v); }},
|
||||
{"title.title_c_c_position", [](const std::string& v) { param.title.title_c_c_position = std::stoi(v); }},
|
||||
{"intro.text_distance_from_bottom", [](const std::string& v) { param.intro.text_distance_from_bottom = std::stoi(v); }}};
|
||||
|
||||
// GAME
|
||||
if (var == "game.width") {
|
||||
param.game.width = std::stoi(value);
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> colorParams = {
|
||||
{"fade.color", [](const std::string& v) { param.fade.color = Color::fromHex(v); }},
|
||||
{"scoreboard.separator_color", [](const std::string& v) { param.scoreboard.separator_color = Color::fromHex(v); }},
|
||||
{"scoreboard.easy_color", [](const std::string& v) { param.scoreboard.easy_color = Color::fromHex(v); }},
|
||||
{"scoreboard.normal_color", [](const std::string& v) { param.scoreboard.normal_color = Color::fromHex(v); }},
|
||||
{"scoreboard.hard_color", [](const std::string& v) { param.scoreboard.hard_color = Color::fromHex(v); }},
|
||||
{"scoreboard.text_color1", [](const std::string& v) { param.scoreboard.text_color1 = Color::fromHex(v); }},
|
||||
{"scoreboard.text_color2", [](const std::string& v) { param.scoreboard.text_color2 = Color::fromHex(v); }},
|
||||
{"title.bg_color", [](const std::string& v) { param.title.bg_color = Color::fromHex(v); }},
|
||||
{"background.attenuate_color", [](const std::string& v) { param.background.attenuate_color = Color::fromHex(v); }},
|
||||
{"notification.color", [](const std::string& v) { param.notification.color = Color::fromHex(v); }},
|
||||
{"service_menu.title_color", [](const std::string& v) { param.service_menu.title_color = Color::fromHex(v); }},
|
||||
{"service_menu.text_color", [](const std::string& v) { param.service_menu.text_color = Color::fromHex(v); }},
|
||||
{"service_menu.selected_color", [](const std::string& v) { param.service_menu.selected_color = Color::fromHex(v); }},
|
||||
{"service_menu.bg_color", [](const std::string& v) { param.service_menu.bg_color = Color::fromHex(v); }},
|
||||
{"intro.bg_color", [](const std::string& v) { param.intro.bg_color = Color::fromHex(v); }},
|
||||
{"intro.card_color", [](const std::string& v) { param.intro.card_color = Color::fromHex(v); }},
|
||||
{"intro.shadow_color", [](const std::string& v) { param.intro.shadow_color = Color::fromHex(v); }},
|
||||
{"debug.color", [](const std::string& v) { param.debug.color = Color::fromHex(v); }},
|
||||
{"resource.color", [](const std::string& v) { param.resource.color = Color::fromHex(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> boolParams = {
|
||||
{"game.hit_stop", [](const std::string& v) { param.game.hit_stop = stringToBool(v); }},
|
||||
{"scoreboard.separator_autocolor", [](const std::string& v) { param.scoreboard.separator_autocolor = stringToBool(v); }},
|
||||
{"scoreboard.text_autocolor", [](const std::string& v) { param.scoreboard.text_autocolor = stringToBool(v); }},
|
||||
{"balloon.bouncing_sound", [](const std::string& v) { param.balloon.bouncing_sound = stringToBool(v); }},
|
||||
{"notification.sound", [](const std::string& v) { param.notification.sound = stringToBool(v); }},
|
||||
{"service_menu.drop_shadow", [](const std::string& v) { param.service_menu.drop_shadow = stringToBool(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> floatParams = {
|
||||
{"balloon.settings[0].vel", [](const std::string& v) { param.balloon.settings.at(0).vel = std::stof(v); }},
|
||||
{"balloon.settings[0].grav", [](const std::string& v) { param.balloon.settings.at(0).grav = std::stof(v); }},
|
||||
{"balloon.settings[1].vel", [](const std::string& v) { param.balloon.settings.at(1).vel = std::stof(v); }},
|
||||
{"balloon.settings[1].grav", [](const std::string& v) { param.balloon.settings.at(1).grav = std::stof(v); }},
|
||||
{"balloon.settings[2].vel", [](const std::string& v) { param.balloon.settings.at(2).vel = std::stof(v); }},
|
||||
{"balloon.settings[2].grav", [](const std::string& v) { param.balloon.settings.at(2).grav = std::stof(v); }},
|
||||
{"balloon.settings[3].vel", [](const std::string& v) { param.balloon.settings.at(3).vel = std::stof(v); }},
|
||||
{"balloon.settings[3].grav", [](const std::string& v) { param.balloon.settings.at(3).grav = std::stof(v); }}};
|
||||
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> stringParams = {
|
||||
{"balloon.color[0]", [](const std::string& v) { param.balloon.color.at(0) = v; }},
|
||||
{"balloon.color[1]", [](const std::string& v) { param.balloon.color.at(1) = v; }},
|
||||
{"balloon.color[2]", [](const std::string& v) { param.balloon.color.at(2) = v; }},
|
||||
{"balloon.color[3]", [](const std::string& v) { param.balloon.color.at(3) = v; }}};
|
||||
|
||||
// Intentar cada mapa de parámetros
|
||||
auto tryMap = [&](const auto& paramMap) -> bool {
|
||||
auto it = paramMap.find(var);
|
||||
if (it != paramMap.end()) {
|
||||
it->second(value);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if (tryMap(intParams) || tryMap(colorParams) || tryMap(boolParams) ||
|
||||
tryMap(floatParams) || tryMap(stringParams)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (var == "game.height") {
|
||||
param.game.height = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.item_size") {
|
||||
param.game.item_size = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.x") {
|
||||
param.game.play_area.rect.x = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.y") {
|
||||
param.game.play_area.rect.y = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.w") {
|
||||
param.game.play_area.rect.w = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.play_area.rect.h") {
|
||||
param.game.play_area.rect.h = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.name_entry_idle_time") {
|
||||
param.game.name_entry_idle_time = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.name_entry_total_time") {
|
||||
param.game.name_entry_total_time = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "game.hit_stop") {
|
||||
param.game.hit_stop = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "game.hit_stop_ms") {
|
||||
param.game.hit_stop_ms = std::stoi(value);
|
||||
}
|
||||
|
||||
// FADE
|
||||
else if (var == "fade.color") {
|
||||
param.fade.color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.num_squares_width") {
|
||||
param.fade.num_squares_width = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.num_squares_height") {
|
||||
param.fade.num_squares_height = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.random_squares_delay") {
|
||||
param.fade.random_squares_delay = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.random_squares_mult") {
|
||||
param.fade.random_squares_mult = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.post_duration") {
|
||||
param.fade.post_duration = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "fade.venetian_size") {
|
||||
param.fade.venetian_size = std::stoi(value);
|
||||
}
|
||||
|
||||
// SCOREBOARD
|
||||
else if (var == "scoreboard.rect.x") {
|
||||
param.scoreboard.rect.x = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.rect.y") {
|
||||
param.scoreboard.rect.y = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.rect.w") {
|
||||
param.scoreboard.rect.w = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.rect.h") {
|
||||
param.scoreboard.rect.h = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.separator_autocolor") {
|
||||
param.scoreboard.separator_autocolor = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.separator_color") {
|
||||
param.scoreboard.separator_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.easy_color") {
|
||||
param.scoreboard.easy_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.normal_color") {
|
||||
param.scoreboard.normal_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.hard_color") {
|
||||
param.scoreboard.hard_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.text_autocolor") {
|
||||
param.scoreboard.text_autocolor = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.text_color1") {
|
||||
param.scoreboard.text_color1 = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.text_color2") {
|
||||
param.scoreboard.text_color2 = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "scoreboard.skip_countdown_value") {
|
||||
param.scoreboard.skip_countdown_value = std::stoi(value);
|
||||
}
|
||||
|
||||
// TITLE
|
||||
else if (var == "title.press_start_position") {
|
||||
param.title.press_start_position = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.title_duration") {
|
||||
param.title.title_duration = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.arcade_edition_position") {
|
||||
param.title.arcade_edition_position = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.title_c_c_position") {
|
||||
param.title.title_c_c_position = std::stoi(value);
|
||||
}
|
||||
|
||||
else if (var == "title.bg_color") {
|
||||
param.title.bg_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
// BACKGROUND
|
||||
else if (var == "background.attenuate_color") {
|
||||
param.background.attenuate_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
// BALLOON
|
||||
else if (var == "balloon.settings[0].vel") {
|
||||
param.balloon.settings.at(0).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[0].grav") {
|
||||
param.balloon.settings.at(0).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[1].vel") {
|
||||
param.balloon.settings.at(1).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[1].grav") {
|
||||
param.balloon.settings.at(1).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[2].vel") {
|
||||
param.balloon.settings.at(2).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[2].grav") {
|
||||
param.balloon.settings.at(2).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[3].vel") {
|
||||
param.balloon.settings.at(3).vel = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.settings[3].grav") {
|
||||
param.balloon.settings.at(3).grav = std::stof(value);
|
||||
}
|
||||
|
||||
else if (var == "balloon.color[0]") {
|
||||
param.balloon.color.at(0) = value;
|
||||
}
|
||||
|
||||
else if (var == "balloon.color[1]") {
|
||||
param.balloon.color.at(1) = value;
|
||||
}
|
||||
|
||||
else if (var == "balloon.color[2]") {
|
||||
param.balloon.color.at(2) = value;
|
||||
}
|
||||
|
||||
else if (var == "balloon.color[3]") {
|
||||
param.balloon.color.at(3) = value;
|
||||
}
|
||||
|
||||
else if (var == "balloon.bouncing_sound") {
|
||||
param.balloon.bouncing_sound = stringToBool(value);
|
||||
}
|
||||
|
||||
// NOTIFICACIONES
|
||||
else if (var == "notification.pos_h") {
|
||||
// Casos especiales que necesitan lógica personalizada
|
||||
if (var == "notification.pos_h") {
|
||||
if (value == "LEFT") {
|
||||
param.notification.pos_h = NotifyPosition::LEFT;
|
||||
} else if (value == "MIDDLE") {
|
||||
@@ -348,74 +228,15 @@ auto setParams(const std::string &var, const std::string &value) -> bool {
|
||||
} else {
|
||||
param.notification.pos_h = NotifyPosition::RIGHT;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (var == "notification.pos_v") {
|
||||
if (var == "notification.pos_v") {
|
||||
param.notification.pos_v = value == "TOP" ? NotifyPosition::TOP : NotifyPosition::BOTTOM;
|
||||
return true;
|
||||
}
|
||||
|
||||
else if (var == "notification.sound") {
|
||||
param.notification.sound = stringToBool(value);
|
||||
}
|
||||
|
||||
else if (var == "notification.color") {
|
||||
param.notification.color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
// SERVICE MENU
|
||||
else if (var == "service_menu.title_color") {
|
||||
param.service_menu.title_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "service_menu.text_color") {
|
||||
param.service_menu.text_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "service_menu.selected_color") {
|
||||
param.service_menu.selected_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "service_menu.bg_color") {
|
||||
param.service_menu.bg_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "service_menu.drop_shadow") {
|
||||
param.service_menu.drop_shadow = stringToBool(value);
|
||||
}
|
||||
|
||||
// INTRO
|
||||
else if (var == "intro.bg_color") {
|
||||
param.intro.bg_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "intro.card_color") {
|
||||
param.intro.card_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "intro.shadow_color") {
|
||||
param.intro.shadow_color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
else if (var == "intro.text_distance_from_bottom") {
|
||||
param.intro.text_distance_from_bottom = std::stoi(value);
|
||||
}
|
||||
|
||||
// DEBUG
|
||||
else if (var == "debug.color") {
|
||||
param.debug.color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
// RESOURCE
|
||||
else if (var == "resource.color") {
|
||||
param.resource.color = Color::fromHex(value);
|
||||
}
|
||||
|
||||
// RESTO
|
||||
else {
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
return false; // Parámetro no encontrado
|
||||
}
|
||||
|
||||
// Calcula variables a partir de otras variables
|
||||
|
||||
Reference in New Issue
Block a user