clase Debug ara carrega la posicio i habitacio inicial desde un fitxer
This commit is contained in:
@@ -74,6 +74,10 @@ assets:
|
||||
path: ${SYSTEM_FOLDER}/config.yaml
|
||||
required: false
|
||||
absolute: true
|
||||
- type: DATA
|
||||
path: ${SYSTEM_FOLDER}/debug.yaml
|
||||
required: false
|
||||
absolute: true
|
||||
- type: DATA
|
||||
path: ${SYSTEM_FOLDER}/stats_buffer.csv
|
||||
required: false
|
||||
|
||||
@@ -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
|
||||
@@ -10,6 +10,13 @@
|
||||
// Clase Debug
|
||||
class Debug {
|
||||
public:
|
||||
struct SpawnSettings {
|
||||
std::string room;
|
||||
int spawn_x = 0;
|
||||
int spawn_y = 0;
|
||||
SDL_FlipMode flip = SDL_FLIP_NONE;
|
||||
};
|
||||
|
||||
static void init(); // [SINGLETON] Crearemos el objeto con esta función estática
|
||||
static void destroy(); // [SINGLETON] Destruiremos el objeto con esta función estática
|
||||
static auto get() -> Debug*; // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
@@ -27,6 +34,11 @@ class Debug {
|
||||
void setEnabled(bool value) { enabled_ = value; } // Establece si el debug está activo
|
||||
void toggleEnabled() { enabled_ = !enabled_; } // Alterna el estado del debug
|
||||
|
||||
void setDebugFile(const std::string& path); // Establece la ruta del archivo debug.yaml
|
||||
void loadFromFile(); // Carga la configuración de debug desde debug.yaml
|
||||
void saveToFile() const; // Guarda la configuración de debug en debug.yaml
|
||||
[[nodiscard]] auto getSpawnSettings() const -> const SpawnSettings& { return spawn_settings_; } // Obtiene los valores de spawn
|
||||
|
||||
private:
|
||||
static Debug* debug; // [SINGLETON] Objeto privado
|
||||
|
||||
@@ -39,6 +51,8 @@ class Debug {
|
||||
int x_ = 0; // Posicion donde escribir el texto de debug
|
||||
int y_ = 0; // Posición donde escribir el texto de debug
|
||||
bool enabled_ = false; // Indica si esta activo el modo debug
|
||||
std::string debug_file_path_; // Ruta del archivo debug.yaml
|
||||
SpawnSettings spawn_settings_; // Configuración de spawn para debug
|
||||
};
|
||||
|
||||
#endif // _DEBUG
|
||||
@@ -165,6 +165,8 @@ Director::Director(std::vector<std::string> const& args) {
|
||||
|
||||
#ifdef _DEBUG
|
||||
Debug::init();
|
||||
Debug::get()->setDebugFile(Resource::List::get()->get("debug.yaml"));
|
||||
Debug::get()->loadFromFile();
|
||||
#endif
|
||||
|
||||
std::cout << "\n"; // Fin de inicialización de sistemas
|
||||
|
||||
@@ -89,21 +89,11 @@ namespace Defaults::Localization {
|
||||
} // namespace Defaults::Localization
|
||||
|
||||
namespace Defaults::Game::Room {
|
||||
#ifdef _DEBUG
|
||||
constexpr const char* INITIAL = "51.yaml"; // Habitación de inicio en debug
|
||||
#else
|
||||
constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio en release
|
||||
#endif
|
||||
constexpr const char* INITIAL = "03.yaml"; // Habitación de inicio
|
||||
} // namespace Defaults::Game::Room
|
||||
|
||||
namespace Defaults::Game::Player {
|
||||
#ifdef _DEBUG
|
||||
constexpr int SPAWN_X = 26 * Tile::SIZE; // Posición X inicial en debug
|
||||
constexpr int SPAWN_Y = 10 * Tile::SIZE; // Posición Y inicial en debug
|
||||
constexpr SDL_FlipMode SPAWN_FLIP = Flip::LEFT; // Orientación inicial en debug
|
||||
#else
|
||||
constexpr int SPAWN_X = 25 * Tile::SIZE; // Posición X inicial en release
|
||||
constexpr int SPAWN_Y = 13 * Tile::SIZE; // Posición Y inicial en release
|
||||
constexpr SDL_FlipMode SPAWN_FLIP = Flip::LEFT; // Orientación inicial en release
|
||||
#endif
|
||||
constexpr int SPAWN_X = 25 * Tile::SIZE; // Posición X inicial
|
||||
constexpr int SPAWN_Y = 13 * Tile::SIZE; // Posición Y inicial
|
||||
constexpr SDL_FlipMode SPAWN_FLIP = Flip::LEFT; // Orientación inicial
|
||||
} // namespace Defaults::Game::Player
|
||||
|
||||
@@ -42,8 +42,13 @@ Game::Game(Mode mode)
|
||||
room_tracker_(std::make_shared<RoomTracker>()),
|
||||
stats_(std::make_shared<Stats>(Resource::List::get()->get("stats.csv"), Resource::List::get()->get("stats_buffer.csv"))),
|
||||
mode_(mode),
|
||||
#ifdef _DEBUG
|
||||
current_room_(Debug::get()->getSpawnSettings().room),
|
||||
spawn_data_(Player::SpawnData(Debug::get()->getSpawnSettings().spawn_x, Debug::get()->getSpawnSettings().spawn_y, 0, 0, 0, Player::State::ON_GROUND, Debug::get()->getSpawnSettings().flip)) {
|
||||
#else
|
||||
current_room_(Defaults::Game::Room::INITIAL),
|
||||
spawn_data_(Player::SpawnData(Defaults::Game::Player::SPAWN_X, Defaults::Game::Player::SPAWN_Y, 0, 0, 0, Player::State::ON_GROUND, Defaults::Game::Player::SPAWN_FLIP)) {
|
||||
#endif
|
||||
// Crea objetos e inicializa variables
|
||||
ItemTracker::init();
|
||||
demoInit();
|
||||
|
||||
Reference in New Issue
Block a user