This commit is contained in:
2025-11-20 09:19:24 +01:00
parent 7d962ae752
commit 34840a64cf
5 changed files with 242 additions and 256 deletions

View File

@@ -1,29 +1,7 @@
{
"permissions": {
"allow": [
"Bash(cmake --build:*)",
"Bash(test:*)",
"Bash(tools/linter/run_clang-tidy.sh:*)",
"Bash(make resources.pack:*)",
"Bash(tools/linter/run_cppcheck.sh:*)",
"Bash(cat:*)",
"Bash(git add:*)",
"Bash(git commit:*)",
"Bash(git checkout:*)",
"Bash(sort:*)",
"Bash(cmake:*)",
"Bash(chmod:*)",
"Bash(python3:*)",
"Bash(make:*)",
"Bash(ldd:*)",
"WebSearch",
"Bash(find:*)",
"WebFetch(domain:github.com)",
"WebFetch(domain:raw.githubusercontent.com)",
"Bash(curl:*)",
"WebFetch(domain:fktn-k.github.io)",
"Bash(./jaildoctors_dilemma)",
"Bash(timeout 5 ./jaildoctors_dilemma:*)"
"Bash(clang-tidy:*)"
],
"deny": [],
"ask": []

View File

@@ -85,7 +85,7 @@ void Player::move(float delta_time) {
#ifdef _DEBUG
Debug::get()->add(std::string("X : " + std::to_string(static_cast<int>(x_))));
Debug::get()->add(std::string("Y : " + std::to_string(static_cast<int>(y_))));
Debug::get()->add(std::string("LGP: " + std::to_string(static_cast<int>(last_grounded_position_))));
Debug::get()->add(std::string("LGP: " + std::to_string(last_grounded_position_)));
#endif
}

View File

@@ -56,6 +56,46 @@ void TilemapRenderer::render() {
}
#ifdef _DEBUG
// Renderiza las superficies de colisión en modo debug (función helper estática)
static void renderDebugCollisionSurfaces(const CollisionMap* collision_map) {
auto surface = Screen::get()->getRendererSurface();
// BottomSurfaces
for (auto l : collision_map->getBottomFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::BLUE));
}
// TopSurfaces
for (auto l : collision_map->getTopFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::RED));
}
// LeftSurfaces
for (auto l : collision_map->getLeftWalls()) {
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::GREEN));
}
// RightSurfaces
for (auto l : collision_map->getRightWalls()) {
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::MAGENTA));
}
// LeftSlopes
for (auto l : collision_map->getLeftSlopes()) {
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::CYAN));
}
// RightSlopes
for (auto l : collision_map->getRightSlopes()) {
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::YELLOW));
}
// AutoSurfaces (Conveyor Belts)
for (auto l : collision_map->getConveyorBeltFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::WHITE));
}
}
// Redibuja el tilemap (para actualizar modo debug)
void TilemapRenderer::redrawMap(const CollisionMap* collision_map) {
fillMapTexture(collision_map);
@@ -98,58 +138,8 @@ void TilemapRenderer::fillMapTexture(const CollisionMap* collision_map) {
#ifdef _DEBUG
// Pinta las superficies en el modo debug
if (Debug::get()->isEnabled()) {
auto surface = Screen::get()->getRendererSurface();
// BottomSurfaces
{
for (auto l : collision_map->getBottomFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::BLUE));
renderDebugCollisionSurfaces(collision_map);
}
}
// TopSurfaces
{
for (auto l : collision_map->getTopFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::RED));
}
}
// LeftSurfaces
{
for (auto l : collision_map->getLeftWalls()) {
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::GREEN));
}
}
// RightSurfaces
{
for (auto l : collision_map->getRightWalls()) {
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::MAGENTA));
}
}
// LeftSlopes
{
for (auto l : collision_map->getLeftSlopes()) {
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::CYAN));
}
}
// RightSlopes
{
for (auto l : collision_map->getRightSlopes()) {
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::YELLOW));
}
}
// AutoSurfaces
{
for (auto l : collision_map->getConveyorBeltFloors()) {
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::WHITE));
}
}
}
#endif // _DEBUG
Screen::get()->setRendererSurface(previous_renderer);
}

View File

@@ -257,72 +257,13 @@ auto stringToGamepadButton(const std::string& str, int default_value) -> int {
}
auto isValidPalette(const std::string& palette) -> bool {
for (const auto& valid : VALID_PALETTES) {
if (valid == palette) {
return true;
}
}
return false;
return std::ranges::any_of(VALID_PALETTES, [&palette](const auto& valid) { return valid == palette; });
}
// Crea e inicializa las opciones del programa
void init() {
#ifdef _DEBUG
console = true;
#else
console = false;
#endif
}
// --- Funciones helper para loadFromFile() ---
// Establece la ruta del fichero de configuración
void setConfigFile(const std::string& path) {
config_file_path = path;
}
// Carga las opciones desde el fichero configurado
auto loadFromFile() -> bool {
// Versión esperada del fichero
const std::string CONFIG_VERSION = GameDefaults::VERSION;
version = "";
// Intenta abrir y leer el fichero
std::ifstream file(config_file_path);
if (!file.good()) {
if (console) {
std::cout << "Config file not found, creating default: " << config_file_path << '\n';
}
saveToFile();
return true;
}
// Lee todo el contenido del fichero
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
try {
if (console) {
std::cout << "Reading config file: " << config_file_path << '\n';
}
// Parsea el YAML
auto yaml = fkyaml::node::deserialize(content);
// Lee la versión
if (yaml.contains("version")) {
version = yaml["version"].get_value<std::string>();
}
// Si la versión no coincide, crea un fichero nuevo con valores por defecto
if (CONFIG_VERSION != version) {
if (console) {
std::cout << "Config version mismatch (expected: " << CONFIG_VERSION << ", got: " << version << "), creating new config\n";
}
init();
saveToFile();
return true;
}
// Lee window
// Carga configuración de ventana desde YAML
void loadWindowConfigFromYaml(const fkyaml::node& yaml) {
if (yaml.contains("window")) {
const auto& win = yaml["window"];
if (win.contains("zoom")) {
@@ -334,11 +275,39 @@ auto loadFromFile() -> bool {
}
}
}
}
// Lee video
if (yaml.contains("video")) {
const auto& vid = yaml["video"];
// Carga configuración de borde desde YAML
void loadBorderConfigFromYaml(const fkyaml::node& border) {
if (border.contains("enabled")) {
try {
video.border.enabled = border["enabled"].get_value<bool>();
} catch (...) {
video.border.enabled = GameDefaults::BORDER_ENABLED;
}
}
if (border.contains("width")) {
try {
auto val = border["width"].get_value<float>();
video.border.width = (val > 0) ? val : GameDefaults::BORDER_WIDTH;
} catch (...) {
video.border.width = GameDefaults::BORDER_WIDTH;
}
}
if (border.contains("height")) {
try {
auto val = border["height"].get_value<float>();
video.border.height = (val > 0) ? val : GameDefaults::BORDER_HEIGHT;
} catch (...) {
video.border.height = GameDefaults::BORDER_HEIGHT;
}
}
}
// Carga los campos básicos de configuración de video
void loadBasicVideoFieldsFromYaml(const fkyaml::node& vid) {
// fullscreen (antes era "mode")
if (vid.contains("fullscreen")) {
try {
@@ -402,40 +371,23 @@ auto loadFromFile() -> bool {
video.palette = GameDefaults::PALETTE_NAME;
}
}
}
// Carga configuración de video desde YAML
void loadVideoConfigFromYaml(const fkyaml::node& yaml) {
if (yaml.contains("video")) {
const auto& vid = yaml["video"];
loadBasicVideoFieldsFromYaml(vid);
// Lee border
if (vid.contains("border")) {
const auto& border = vid["border"];
loadBorderConfigFromYaml(vid["border"]);
}
}
}
if (border.contains("enabled")) {
try {
video.border.enabled = border["enabled"].get_value<bool>();
} catch (...) {
video.border.enabled = GameDefaults::BORDER_ENABLED;
}
}
if (border.contains("width")) {
try {
auto val = border["width"].get_value<float>();
video.border.width = (val > 0) ? val : GameDefaults::BORDER_WIDTH;
} catch (...) {
video.border.width = GameDefaults::BORDER_WIDTH;
}
}
if (border.contains("height")) {
try {
auto val = border["height"].get_value<float>();
video.border.height = (val > 0) ? val : GameDefaults::BORDER_HEIGHT;
} catch (...) {
video.border.height = GameDefaults::BORDER_HEIGHT;
}
}
}
}
// Lee keyboard_controls (antes era "controls")
// Carga controles de teclado desde YAML
void loadKeyboardControlsFromYaml(const fkyaml::node& yaml) {
if (yaml.contains("keyboard_controls")) {
const auto& ctrl = yaml["keyboard_controls"];
@@ -466,8 +418,10 @@ auto loadFromFile() -> bool {
}
}
}
}
// Lee gamepad_controls
// Carga controles de gamepad desde YAML
void loadGamepadControlsFromYaml(const fkyaml::node& yaml) {
if (yaml.contains("gamepad_controls")) {
const auto& gp = yaml["gamepad_controls"];
@@ -498,6 +452,70 @@ auto loadFromFile() -> bool {
}
}
}
}
// Crea e inicializa las opciones del programa
void init() {
#ifdef _DEBUG
console = true;
#else
console = false;
#endif
}
// Establece la ruta del fichero de configuración
void setConfigFile(const std::string& path) {
config_file_path = path;
}
// Carga las opciones desde el fichero configurado
auto loadFromFile() -> bool {
// Versión esperada del fichero
const std::string CONFIG_VERSION = GameDefaults::VERSION;
version = "";
// Intenta abrir y leer el fichero
std::ifstream file(config_file_path);
if (!file.good()) {
if (console) {
std::cout << "Config file not found, creating default: " << config_file_path << '\n';
}
saveToFile();
return true;
}
// Lee todo el contenido del fichero
std::string content((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>());
file.close();
try {
if (console) {
std::cout << "Reading config file: " << config_file_path << '\n';
}
// Parsea el YAML
auto yaml = fkyaml::node::deserialize(content);
// Lee la versión
if (yaml.contains("version")) {
version = yaml["version"].get_value<std::string>();
}
// Si la versión no coincide, crea un fichero nuevo con valores por defecto
if (CONFIG_VERSION != version) {
if (console) {
std::cout << "Config version mismatch (expected: " << CONFIG_VERSION << ", got: " << version << "), creating new config\n";
}
init();
saveToFile();
return true;
}
// Carga las diferentes secciones de configuración usando funciones helper
loadWindowConfigFromYaml(yaml);
loadVideoConfigFromYaml(yaml);
loadKeyboardControlsFromYaml(yaml);
loadGamepadControlsFromYaml(yaml);
if (console) {
std::cout << "Config file loaded successfully\n\n";

View File

@@ -129,7 +129,7 @@ inline GamepadControls gamepad_controls{}; // Botones del gamepad usados para
// Ruta completa del fichero de configuración (establecida mediante setConfigFile)
inline std::string config_file_path{};
// --- Funciones ---
// --- Funciones públicas ---
void init(); // Crea e inicializa las opciones del programa
void setConfigFile(const std::string& path); // Establece la ruta del fichero de configuración
auto loadFromFile() -> bool; // Carga las opciones desde el fichero configurado