neteja clang-tidy
This commit is contained in:
@@ -38,6 +38,38 @@
|
||||
#include "game/ui/service_menu.hpp" // Para ServiceMenu
|
||||
#include "utils/param.hpp" // Para loadParamsFromFile
|
||||
|
||||
namespace {
|
||||
// Llig un camp opcional d'un YAML cap a `dest`. Si no existeix, no toca `dest`.
|
||||
// Si existeix però el tipus no encaixa, deixa el valor per defecte i avisa per stderr
|
||||
// (un debug.yaml mal escrit no ha de tombar l'arrencada, però l'usuari ha de saber-ho).
|
||||
template <typename T>
|
||||
void loadYamlField(const fkyaml::node& yaml, const std::string& key, T& dest) {
|
||||
if (!yaml.contains(key)) { return; }
|
||||
try {
|
||||
dest = yaml[key].get_value<T>();
|
||||
} catch (...) {
|
||||
std::cerr << "debug.yaml: valor invàlid per a '" << key << "', es manté el valor per defecte\n";
|
||||
}
|
||||
}
|
||||
|
||||
auto parseInitialSection(const std::string& value) -> Section::Name {
|
||||
if (value == "logo") { return Section::Name::LOGO; }
|
||||
if (value == "intro") { return Section::Name::INTRO; }
|
||||
if (value == "title") { return Section::Name::TITLE; }
|
||||
if (value == "credits") { return Section::Name::CREDITS; }
|
||||
if (value == "instructions") { return Section::Name::INSTRUCTIONS; }
|
||||
if (value == "hiscore") { return Section::Name::HI_SCORE_TABLE; }
|
||||
return Section::Name::GAME; // "game" i qualsevol valor desconegut
|
||||
}
|
||||
|
||||
auto parseInitialOptions(const std::string& value) -> Section::Options {
|
||||
if (value == "none") { return Section::Options::NONE; }
|
||||
if (value == "2p") { return Section::Options::GAME_PLAY_2P; }
|
||||
if (value == "both") { return Section::Options::GAME_PLAY_BOTH; }
|
||||
return Section::Options::GAME_PLAY_1P; // "1p" i qualsevol valor desconegut
|
||||
}
|
||||
} // namespace
|
||||
|
||||
// Constructor
|
||||
Director::Director() {
|
||||
Section::attract_mode = Section::AttractMode::TITLE_TO_DEMO;
|
||||
@@ -275,78 +307,20 @@ void Director::loadDebugConfig() {
|
||||
file.close();
|
||||
try {
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
if (yaml.contains("initial_section")) {
|
||||
try {
|
||||
debug_config.initial_section = yaml["initial_section"].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("initial_options")) {
|
||||
try {
|
||||
debug_config.initial_options = yaml["initial_options"].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("initial_stage")) {
|
||||
try {
|
||||
debug_config.initial_stage = yaml["initial_stage"].get_value<int>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("show_render_info")) {
|
||||
try {
|
||||
debug_config.show_render_info = yaml["show_render_info"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("resource_loading")) {
|
||||
try {
|
||||
debug_config.resource_loading = yaml["resource_loading"].get_value<std::string>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("autoplay")) {
|
||||
try {
|
||||
debug_config.autoplay = yaml["autoplay"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
if (yaml.contains("invincibility")) {
|
||||
try {
|
||||
debug_config.invincibility = yaml["invincibility"].get_value<bool>();
|
||||
} catch (...) {}
|
||||
}
|
||||
loadYamlField(yaml, "initial_section", debug_config.initial_section);
|
||||
loadYamlField(yaml, "initial_options", debug_config.initial_options);
|
||||
loadYamlField(yaml, "initial_stage", debug_config.initial_stage);
|
||||
loadYamlField(yaml, "show_render_info", debug_config.show_render_info);
|
||||
loadYamlField(yaml, "resource_loading", debug_config.resource_loading);
|
||||
loadYamlField(yaml, "autoplay", debug_config.autoplay);
|
||||
loadYamlField(yaml, "invincibility", debug_config.invincibility);
|
||||
} catch (...) {
|
||||
std::cout << "Error parsing debug.yaml, using defaults" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
// Mapear strings a enums
|
||||
const auto& sec = debug_config.initial_section;
|
||||
if (sec == "logo") {
|
||||
Section::name = Section::Name::LOGO;
|
||||
} else if (sec == "intro") {
|
||||
Section::name = Section::Name::INTRO;
|
||||
} else if (sec == "title") {
|
||||
Section::name = Section::Name::TITLE;
|
||||
} else if (sec == "game") {
|
||||
Section::name = Section::Name::GAME;
|
||||
} else if (sec == "credits") {
|
||||
Section::name = Section::Name::CREDITS;
|
||||
} else if (sec == "instructions") {
|
||||
Section::name = Section::Name::INSTRUCTIONS;
|
||||
} else if (sec == "hiscore") {
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
} else {
|
||||
Section::name = Section::Name::GAME;
|
||||
}
|
||||
|
||||
const auto& opt = debug_config.initial_options;
|
||||
if (opt == "none") {
|
||||
Section::options = Section::Options::NONE;
|
||||
} else if (opt == "1p") {
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
} else if (opt == "2p") {
|
||||
Section::options = Section::Options::GAME_PLAY_2P;
|
||||
} else if (opt == "both") {
|
||||
Section::options = Section::Options::GAME_PLAY_BOTH;
|
||||
} else {
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
}
|
||||
Section::name = parseInitialSection(debug_config.initial_section);
|
||||
Section::options = parseInitialOptions(debug_config.initial_options);
|
||||
}
|
||||
|
||||
// Crea la carpeta del sistema donde guardar datos
|
||||
|
||||
Reference in New Issue
Block a user