clase Debug ara carrega la posicio i habitacio inicial desde un fitxer
This commit is contained in:
@@ -3,11 +3,15 @@
|
||||
#ifdef _DEBUG
|
||||
|
||||
#include <algorithm> // Para max
|
||||
#include <fstream> // Para ifstream, ofstream
|
||||
#include <memory> // Para __shared_ptr_access, shared_ptr
|
||||
|
||||
#include "core/rendering/text.hpp" // Para Text
|
||||
#include "core/resources/resource_cache.hpp" // Para Resource
|
||||
#include "utils/utils.hpp" // Para Color
|
||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||
#include "game/defaults.hpp" // Para Defaults::Game::*
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE
|
||||
#include "utils/utils.hpp" // Para Color, Flip::
|
||||
|
||||
// [SINGLETON]
|
||||
Debug* Debug::debug = nullptr;
|
||||
@@ -56,4 +60,63 @@ void Debug::setPos(SDL_FPoint p) {
|
||||
y_ = p.y;
|
||||
}
|
||||
|
||||
// Establece la ruta del archivo debug.yaml
|
||||
void Debug::setDebugFile(const std::string& path) {
|
||||
debug_file_path_ = path;
|
||||
}
|
||||
|
||||
// Carga la configuración de debug desde debug.yaml
|
||||
void Debug::loadFromFile() {
|
||||
// Inicializar con valores de release por defecto
|
||||
spawn_settings_.room = Defaults::Game::Room::INITIAL;
|
||||
spawn_settings_.spawn_x = Defaults::Game::Player::SPAWN_X;
|
||||
spawn_settings_.spawn_y = Defaults::Game::Player::SPAWN_Y;
|
||||
spawn_settings_.flip = Defaults::Game::Player::SPAWN_FLIP;
|
||||
|
||||
std::ifstream file(debug_file_path_);
|
||||
if (!file.good()) {
|
||||
saveToFile(); // No existe: crear con valores por defecto
|
||||
return;
|
||||
}
|
||||
|
||||
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
|
||||
file.close();
|
||||
|
||||
try {
|
||||
auto yaml = fkyaml::node::deserialize(content);
|
||||
if (yaml.contains("room")) {
|
||||
spawn_settings_.room = yaml["room"].get_value<std::string>();
|
||||
}
|
||||
if (yaml.contains("spawn_x")) {
|
||||
spawn_settings_.spawn_x = yaml["spawn_x"].get_value<int>() * Tile::SIZE;
|
||||
}
|
||||
if (yaml.contains("spawn_y")) {
|
||||
spawn_settings_.spawn_y = yaml["spawn_y"].get_value<int>() * Tile::SIZE;
|
||||
}
|
||||
if (yaml.contains("spawn_flip")) {
|
||||
auto s = yaml["spawn_flip"].get_value<std::string>();
|
||||
spawn_settings_.flip = (s == "right") ? Flip::RIGHT : Flip::LEFT;
|
||||
}
|
||||
} catch (...) {
|
||||
// YAML inválido: resetear a defaults y sobreescribir
|
||||
spawn_settings_.room = Defaults::Game::Room::INITIAL;
|
||||
spawn_settings_.spawn_x = Defaults::Game::Player::SPAWN_X;
|
||||
spawn_settings_.spawn_y = Defaults::Game::Player::SPAWN_Y;
|
||||
spawn_settings_.flip = Defaults::Game::Player::SPAWN_FLIP;
|
||||
saveToFile();
|
||||
}
|
||||
}
|
||||
|
||||
// Guarda la configuración de debug en debug.yaml
|
||||
void Debug::saveToFile() const {
|
||||
std::ofstream file(debug_file_path_);
|
||||
if (!file.is_open()) { return; }
|
||||
file << "# JailDoctor's Dilemma - Debug Configuration\n";
|
||||
file << "# Edita para cambiar la habitacion y spawn del jugador en builds debug.\n\n";
|
||||
file << "room: \"" << spawn_settings_.room << "\"\n";
|
||||
file << "spawn_x: " << (spawn_settings_.spawn_x / Tile::SIZE) << " # en tiles\n";
|
||||
file << "spawn_y: " << (spawn_settings_.spawn_y / Tile::SIZE) << " # en tiles\n";
|
||||
file << "spawn_flip: " << ((spawn_settings_.flip == Flip::RIGHT) ? "right" : "left") << "\n";
|
||||
}
|
||||
|
||||
#endif // _DEBUG
|
||||
Reference in New Issue
Block a user