clang-format
mogudes coses de config.yaml a debug.yaml
This commit is contained in:
@@ -2,23 +2,23 @@
|
||||
|
||||
namespace info {
|
||||
|
||||
struct GameContext {
|
||||
int num_piramide = 0;
|
||||
int num_habitacio = 0;
|
||||
int diners = 0;
|
||||
int diamants = 0;
|
||||
int vida = 0;
|
||||
int momies = 0;
|
||||
int engendros = 0;
|
||||
bool nou_personatge = false;
|
||||
bool pepe_activat = false;
|
||||
struct GameContext {
|
||||
int num_piramide = 0;
|
||||
int num_habitacio = 0;
|
||||
int diners = 0;
|
||||
int diamants = 0;
|
||||
int vida = 0;
|
||||
int momies = 0;
|
||||
int engendros = 0;
|
||||
bool nou_personatge = false;
|
||||
bool pepe_activat = false;
|
||||
|
||||
void reset() { *this = GameContext{}; }
|
||||
};
|
||||
void reset() { *this = GameContext{}; }
|
||||
};
|
||||
|
||||
// Instància única de l'estat del joc. Reemplaça les variables soltes del
|
||||
// namespace `info::` per una struct encapsulada. A Fase 5 (single-threaded)
|
||||
// es podrà passar per referència als mòduls en lloc d'accedir via singleton.
|
||||
inline GameContext ctx;
|
||||
// Instància única de l'estat del joc. Reemplaça les variables soltes del
|
||||
// namespace `info::` per una struct encapsulada. A Fase 5 (single-threaded)
|
||||
// es podrà passar per referència als mòduls en lloc d'accedir via singleton.
|
||||
inline GameContext ctx;
|
||||
|
||||
} // namespace info
|
||||
|
||||
@@ -42,16 +42,17 @@ void ModuleGame::onEnter() {
|
||||
// fade interpolarien cap a una paleta amb pantalla buida.
|
||||
this->Draw();
|
||||
|
||||
const char* music = info::ctx.num_piramide == 3 ? "music/00000008.ogg"
|
||||
: info::ctx.num_piramide == 2 ? "music/00000007.ogg"
|
||||
: info::ctx.num_piramide == 6 ? "music/00000002.ogg"
|
||||
: "music/00000006.ogg";
|
||||
const char* music = info::ctx.num_piramide == 3 ? "music/00000008.ogg"
|
||||
: info::ctx.num_piramide == 2 ? "music/00000007.ogg"
|
||||
: info::ctx.num_piramide == 6 ? "music/00000002.ogg"
|
||||
: "music/00000006.ogg";
|
||||
const char* current_music = JA_GetMusicFilename();
|
||||
if ((JA_GetMusicState() != JA_MUSIC_PLAYING) || !current_music ||
|
||||
strcmp(music, current_music) != 0) {
|
||||
auto buffer = ResourceHelper::loadFile(music);
|
||||
JA_PlayMusic(JA_LoadMusic(buffer.data(),
|
||||
static_cast<Uint32>(buffer.size()), music));
|
||||
static_cast<Uint32>(buffer.size()),
|
||||
music));
|
||||
}
|
||||
|
||||
// Arranca el fade-in tick-based. El `PaletteFade` avança un pas (de
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -141,11 +141,21 @@ namespace Options {
|
||||
inline std::string crtpi_file_path{};
|
||||
inline int current_crtpi_preset{0};
|
||||
|
||||
inline std::string debug_file_path{};
|
||||
|
||||
// --- API ---
|
||||
void setConfigFile(const std::string& path);
|
||||
auto loadFromFile() -> bool;
|
||||
auto saveToFile() -> bool;
|
||||
|
||||
// debug.yaml: estat inicial de gameplay per a tests ràpids
|
||||
// (`habitacio_inicial`, `piramide_inicial`, `vides`, `diamants_inicial`,
|
||||
// `diners_inicial`). Només es carrega/desa en builds de debug; en release
|
||||
// els camps queden als seus defaults.
|
||||
void setDebugFile(const std::string& path);
|
||||
auto loadDebugFromFile() -> bool;
|
||||
auto saveDebugToFile() -> bool;
|
||||
|
||||
void setPostFXFile(const std::string& path);
|
||||
auto loadPostFXFromFile() -> bool;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user