clang-format
mogudes coses de config.yaml a debug.yaml
This commit is contained in:
@@ -16,6 +16,66 @@ namespace Options {
|
||||
config_file_path = path;
|
||||
}
|
||||
|
||||
void setDebugFile(const std::string& path) {
|
||||
debug_file_path = path;
|
||||
}
|
||||
|
||||
auto saveDebugToFile() -> bool {
|
||||
std::ofstream file(debug_file_path);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Error: Unable to open file " << debug_file_path << " for writing\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << "Writing debug file: " << debug_file_path << '\n';
|
||||
|
||||
file << "# Aventures En Egipte - Debug Configuration File\n";
|
||||
file << "#\n";
|
||||
file << "# Loaded only in debug builds. Override gameplay starting state for testing.\n";
|
||||
file << "\n";
|
||||
file << "game:\n";
|
||||
file << " habitacio_inicial: " << game.habitacio_inicial << "\n";
|
||||
file << " piramide_inicial: " << game.piramide_inicial << "\n";
|
||||
file << " vides: " << game.vides << "\n";
|
||||
file << " diamants_inicial: " << game.diamants_inicial << "\n";
|
||||
file << " diners_inicial: " << game.diners_inicial << "\n";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
auto loadDebugFromFile() -> bool {
|
||||
std::ifstream file(debug_file_path);
|
||||
if (!file.good()) {
|
||||
std::cout << "Debug file not found, creating default: " << debug_file_path << '\n';
|
||||
return saveDebugToFile();
|
||||
}
|
||||
|
||||
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
|
||||
try {
|
||||
std::cout << "Reading debug file: " << debug_file_path << '\n';
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
if (yaml.contains("game")) {
|
||||
const auto& node = yaml["game"];
|
||||
if (node.contains("habitacio_inicial"))
|
||||
game.habitacio_inicial = node["habitacio_inicial"].get_value<int>();
|
||||
if (node.contains("piramide_inicial"))
|
||||
game.piramide_inicial = node["piramide_inicial"].get_value<int>();
|
||||
if (node.contains("vides"))
|
||||
game.vides = node["vides"].get_value<int>();
|
||||
if (node.contains("diamants_inicial"))
|
||||
game.diamants_inicial = node["diamants_inicial"].get_value<int>();
|
||||
if (node.contains("diners_inicial"))
|
||||
game.diners_inicial = node["diners_inicial"].get_value<int>();
|
||||
}
|
||||
return true;
|
||||
} catch (const fkyaml::exception& e) {
|
||||
std::cerr << "Error parsing YAML debug: " << e.what() << '\n';
|
||||
return saveDebugToFile();
|
||||
}
|
||||
}
|
||||
|
||||
void applyAudio() {
|
||||
const float master = audio.enabled ? audio.volume : 0.0F;
|
||||
JA_EnableMusic(audio.music_enabled);
|
||||
@@ -138,16 +198,6 @@ namespace Options {
|
||||
if (!yaml.contains("game")) return;
|
||||
const auto& node = yaml["game"];
|
||||
|
||||
if (node.contains("habitacio_inicial"))
|
||||
game.habitacio_inicial = node["habitacio_inicial"].get_value<int>();
|
||||
if (node.contains("piramide_inicial"))
|
||||
game.piramide_inicial = node["piramide_inicial"].get_value<int>();
|
||||
if (node.contains("vides"))
|
||||
game.vides = node["vides"].get_value<int>();
|
||||
if (node.contains("diamants_inicial"))
|
||||
game.diamants_inicial = node["diamants_inicial"].get_value<int>();
|
||||
if (node.contains("diners_inicial"))
|
||||
game.diners_inicial = node["diners_inicial"].get_value<int>();
|
||||
if (node.contains("use_new_logo"))
|
||||
game.use_new_logo = node["use_new_logo"].get_value<bool>();
|
||||
if (node.contains("show_title_credits"))
|
||||
@@ -279,11 +329,6 @@ namespace Options {
|
||||
// GAME
|
||||
file << "# GAME\n";
|
||||
file << "game:\n";
|
||||
file << " habitacio_inicial: " << game.habitacio_inicial << "\n";
|
||||
file << " piramide_inicial: " << game.piramide_inicial << "\n";
|
||||
file << " vides: " << game.vides << "\n";
|
||||
file << " diamants_inicial: " << game.diamants_inicial << "\n";
|
||||
file << " diners_inicial: " << game.diners_inicial << "\n";
|
||||
file << " use_new_logo: " << (game.use_new_logo ? "true" : "false") << "\n";
|
||||
file << " show_title_credits: " << (game.show_title_credits ? "true" : "false") << "\n";
|
||||
file << "\n";
|
||||
|
||||
Reference in New Issue
Block a user