afegit el namespace Logger

This commit is contained in:
2025-10-19 18:10:55 +02:00
parent df6e7e5155
commit 413c3c30a6
17 changed files with 107 additions and 96 deletions

View File

@@ -12,6 +12,7 @@
#include "resource_helper.hpp" // Para ResourceHelper
#include "texture.hpp" // Para Texture
#include "utils.hpp" // Para printWithDots
#include "ui/logger.hpp"
// Carga las animaciones en un vector(Animations) desde un fichero
auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffer {
@@ -38,7 +39,7 @@ auto loadAnimationsFromFile(const std::string& file_path) -> AnimationsFileBuffe
std::istream& input_stream = using_resource_data ? stream : static_cast<std::istream&>(file);
printWithDots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
Logger::dots("Animation : ", file_path.substr(file_path.find_last_of("\\/") + 1), "[ LOADED ]");
std::vector<std::string> buffer;
std::string line;

View File

@@ -49,7 +49,6 @@ void Asset::add(const std::string& file_path, Type type, bool required, bool abs
addToMap(file_path, type, required, absolute);
}
// Carga recursos desde un archivo de configuración con soporte para variables
// Carga recursos desde un archivo de configuración con soporte para variables
void Asset::loadFromFile(const std::string& config_file_path, const std::string& prefix, const std::string& system_folder) {
std::ifstream file(config_file_path);
@@ -125,10 +124,7 @@ void Asset::loadFromFile(const std::string& config_file_path, const std::string&
}
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Loaded %d assets from config file",
static_cast<int>(file_list_.size()));
std::cout << "Loaded " << file_list_.size() << " assets from config file" << std::endl;
file.close();
}
@@ -180,9 +176,7 @@ auto Asset::check() const -> bool {
Type asset_type = static_cast<Type>(type);
if (by_type.find(asset_type) != by_type.end()) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"\n>> %s FILES",
getTypeName(asset_type).c_str());
Logger::info(getTypeName(asset_type) + " FILES");
bool type_success = true;
for (const auto* item : by_type[asset_type]) {
@@ -193,18 +187,10 @@ auto Asset::check() const -> bool {
}
if (type_success) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " All files are OK.");
Logger::info("All files are OK.\n");
}
}
}
// Resultado
if (success) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES COMPLETED.\n");
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES FAILED.\n");
}
return success;
}

View File

@@ -7,6 +7,7 @@
#include "external/jail_audio.h" // Para JA_FadeOutMusic, JA_Init, JA_PauseM...
#include "options.hpp" // Para AudioOptions, audio, MusicOptions
#include "resource.hpp" // Para Resource
#include "ui/logger.hpp" // Para logger
// Singleton
Audio* Audio::instance = nullptr;
@@ -144,6 +145,6 @@ void Audio::initSDLAudio() {
JA_Init(FREQUENCY, SDL_AUDIO_S16LE, 2);
enable(Options::audio.enabled);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Audio system initialized successfully");
Logger::info("Audio system initialized successfully");
}
}

View File

@@ -6,6 +6,7 @@
#include "resource_helper.hpp" // Para ResourceHelper
#include "utils.hpp" // Para printWithDots, getFileName
#include "ui/logger.hpp"
// Carga el fichero de datos para la demo
auto loadDemoDataFromFile(const std::string& file_path) -> DemoData {
@@ -26,7 +27,7 @@ auto loadDemoDataFromFile(const std::string& file_path) -> DemoData {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", file_path.c_str());
throw std::runtime_error("Fichero no encontrado: " + file_path);
}
printWithDots("DemoData : ", getFileName(file_path), "[ LOADED ]");
Logger::dots("DemoData : ", getFileName(file_path), "[ LOADED ]");
// Lee todos los datos del fichero y los deja en el destino
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) {

View File

@@ -35,6 +35,7 @@
#include "ui/notifier.hpp" // Para Notifier
#include "ui/service_menu.hpp" // Para ServiceMenu
#include "utils.hpp" // Para Overrides, overrides, getPath
#include "ui/logger.hpp"
// Constructor
Director::Director(int argc, std::span<char*> argv) {
@@ -54,7 +55,7 @@ Director::Director(int argc, std::span<char*> argv) {
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
SDL_SetLogPriority(SDL_LOG_CATEGORY_TEST, SDL_LOG_PRIORITY_ERROR);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Game start");
Logger::put("Game start\n");
// Inicia la semilla aleatoria usando el tiempo actual en segundos
std::srand(static_cast<unsigned int>(std::time(nullptr)));
@@ -71,7 +72,7 @@ Director::Director(int argc, std::span<char*> argv) {
Director::~Director() {
close();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nBye!");
Logger::put("\nBye!");
}
// Inicializa todo
@@ -85,17 +86,28 @@ void Director::init() {
ResourceHelper::initializeResourceSystem(executable_path_ + "resources.pack");
#endif
loadAssets(); // Crea el índice de archivos
Logger::section("INIT INPUT");
Input::init(Asset::get()->get("gamecontrollerdb.txt"), Asset::get()->get("controllers.json")); // Carga configuración de controles
Logger::section("INIT CONFIG");
Options::setConfigFile(Asset::get()->get("config_v2.txt")); // Establece el fichero de configuración
Options::setControllersFile(Asset::get()->get("controllers.json")); // Establece el fichero de configuración de mandos
Options::loadFromFile(); // Carga el archivo de configuración
loadParams(); // Carga los parámetros del programa
loadScoreFile(); // Carga el archivo de puntuaciones
// Inicialización de subsistemas principales
Lang::setLanguage(Options::settings.language); // Carga el archivo de idioma
Logger::section("INIT VIDEO");
Screen::init(); // Inicializa la pantalla y el sistema de renderizado
Logger::section("INIT AUDIO");
Audio::init(); // Activa el sistema de audio
Logger::section("INIT RESOURCES");
#ifdef _DEBUG
Resource::init(Resource::LoadingMode::PRELOAD); // Inicializa el sistema de gestión de recursos
#else
@@ -104,6 +116,8 @@ void Director::init() {
ServiceMenu::init(); // Inicializa el menú de servicio
Notifier::init(std::string(), Resource::get()->getText("8bithud")); // Inicialización del sistema de notificaciones
Screen::get()->getSingletons(); // Obtiene los punteros al resto de singletones
Logger::section("GAME LOG");
}
// Cierra todo y libera recursos del sistema y de los singletons
@@ -164,7 +178,7 @@ void Director::loadAssets() {
std::string config_path = executable_path_ + PREFIX + "/config/assets.txt";
Asset::get()->loadFromFile(config_path, PREFIX, system_folder_);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Assets configuration loaded successfully");
Logger::put("Assets configuration loaded successfully");
// Si falta algun fichero, sale del programa
if (!Asset::get()->check()) {

View File

@@ -118,21 +118,16 @@ void JA_Init(const int freq, const SDL_AudioFormat format, const int num_channel
SDL_SetLogPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_DEBUG);
#endif
SDL_Log("Iniciant JailAudio...");
JA_audioSpec = {format, num_channels, freq };
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &JA_audioSpec);
SDL_Log( (sdlAudioDevice==0) ? "Failed to initialize SDL audio!\n" : "OK!\n");
if (sdlAudioDevice==0) SDL_Log("Failed to initialize SDL audio!");
for (int i=0; i<JA_MAX_SIMULTANEOUS_CHANNELS; ++i) channels[i].state = JA_CHANNEL_FREE;
for (int i=0; i<JA_MAX_GROUPS; ++i) JA_soundVolume[i] = 0.5f;
//SDL_PauseAudioDevice(sdlAudioDevice);
//JA_timerID = SDL_AddTimer(30, JA_UpdateCallback, nullptr);
}
void JA_Quit()
{
//if (JA_timerID) SDL_RemoveTimer(JA_timerID);
if (!sdlAudioDevice) SDL_CloseAudioDevice(sdlAudioDevice);
sdlAudioDevice = 0;
}

View File

@@ -7,6 +7,7 @@
#include <memory> // Para shared_ptr, __shared_ptr_access, allocator, operator==, make_shared
#include <unordered_map> // Para unordered_map, operator==, _Node_iterator_base, _Node_iterator, _Node_const_iterator
#include <utility> // Para pair, move
#include "ui/logger.hpp"
// Singleton
Input* Input::instance = nullptr;
@@ -318,7 +319,7 @@ void Input::initSDLGamePad() {
addGamepadMappingsFromFile();
loadGamepadConfigs();
discoverGamepads();
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Input System initialized successfully\n");
Logger::info("Input System initialized successfully");
}
}
}

View File

@@ -6,6 +6,7 @@
#include <iterator> // Para distance
#include "utils.hpp" // Para getFileName
#include "ui/logger.hpp"
// Resetea la tabla a los valores por defecto
void ManageHiScoreTable::clear() {
@@ -169,7 +170,8 @@ auto ManageHiScoreTable::saveToFile(const std::string& file_path) -> bool {
SDL_WriteIO(file, &occ_value, sizeof(int));
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(file_path).c_str());
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(file_path).c_str());
Logger::info("Writing file: " + getFileName(file_path));
SDL_CloseIO(file);
} else {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Unable to save %s file! %s", getFileName(file_path).c_str(), SDL_GetError());

View File

@@ -17,6 +17,7 @@
#include "difficulty.hpp" // Para Code, init
#include "input.hpp" // Para InputDevice
#include "lang.hpp" // Para Code
#include "ui/logger.hpp" // Para Logger
#include "utils.hpp" // Para boolToString, stringToBool, getFileName
namespace Options {
@@ -64,7 +65,8 @@ auto loadFromFile() -> bool {
// 2. Si el fichero existe, lo leemos para obtener los nombres de los mandos.
if (file_exists) {
// --- CASO: EL FICHERO EXISTE ---
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(settings.config_file).c_str());
// SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(settings.config_file).c_str());
Logger::info("Reading file: " + getFileName(settings.config_file));
std::string line;
std::string param_name;
std::string param_value;
@@ -114,7 +116,8 @@ auto saveToFile() -> bool {
return false;
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(settings.config_file).c_str());
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Writing file: %s", getFileName(settings.config_file).c_str());
Logger::info("Writing file: " + getFileName(settings.config_file));
applyPendingChanges();

View File

@@ -12,6 +12,7 @@
#include "color.hpp"
#include "ui/notifier.hpp" // Para Notifier::Position
#include "utils.hpp"
#include "ui/logger.hpp" // Para Logger
// Variable global - ahora se inicializa automáticamente con valores por defecto
Param param;
@@ -52,7 +53,8 @@ void loadParamsFromFile(const std::string& file_path) {
throw std::runtime_error("No se pudo abrir el archivo: " + file_path);
}
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str());
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\nReading file: %s", getFileName(file_path).c_str());
Logger::info("Reading file: " + getFileName(file_path));
std::string line;
std::string param_name;
@@ -69,7 +71,7 @@ void loadParamsFromFile(const std::string& file_path) {
std::istringstream iss(line);
if (iss >> param_name >> param_value) {
if (!setParams(param_name, param_value)) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Parámetro desconocido: %s", param_name.c_str());
Logger::info("WARNING: Parámetro desconocido: " + param_name, Logger::YELLOW);
}
}
}

View File

@@ -19,6 +19,7 @@
#include "screen.hpp" // Para Screen
#include "text.hpp" // Para Text
#include "version.h" // Para Version::APP_NAME y Version::GIT_HASH
#include "ui/logger.hpp" // Para Logger
struct JA_Music_t; // lines 11-11
struct JA_Sound_t; // lines 12-12
@@ -445,7 +446,7 @@ void Resource::load() {
auto vsync = Screen::getVSync();
screen->setVSync(false);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** LOADING RESOURCES");
loadSounds(); // Carga sonidos
loadMusics(); // Carga músicas
loadTextures(); // Carga texturas
@@ -455,7 +456,7 @@ void Resource::load() {
createText(); // Crea objetos de texto
createTextTextures(); // Crea texturas a partir de texto
createPlayerTextures(); // Crea las texturas de jugadores con todas sus variantes de paleta
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** RESOURCES LOADED");
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** RESOURCES LOADED");
// Restablece el sincronismo vertical a su valor original
screen->setVSync(vsync);
@@ -473,7 +474,7 @@ void Resource::reload() {
// Carga los sonidos del juego
void Resource::loadSounds() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> SOUND FILES");
Logger::info("SOUND FILES");
auto list = Asset::get()->getListByType(Asset::Type::SOUND);
sounds_.clear();
@@ -482,13 +483,14 @@ void Resource::loadSounds() {
updateLoadingProgress(name);
std::string audio_path = createTempAudioFile(l, temp_audio_files_);
sounds_.emplace_back(name, JA_LoadSound(audio_path.c_str()));
printWithDots("Sound : ", name, "[ LOADED ]");
Logger::dots("Sound : ", name, "[ LOADED ]");
}
}
// Carga las músicas del juego
void Resource::loadMusics() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> MUSIC FILES");
Logger::CR();
Logger::info("MUSIC FILES");
auto list = Asset::get()->getListByType(Asset::Type::MUSIC);
musics_.clear();
@@ -497,13 +499,14 @@ void Resource::loadMusics() {
updateLoadingProgress(name);
std::string audio_path = createTempAudioFile(l, temp_audio_files_);
musics_.emplace_back(name, JA_LoadMusic(audio_path.c_str()));
printWithDots("Music : ", name, "[ LOADED ]");
Logger::dots("Music : ", name, "[ LOADED ]");
}
}
// Carga las texturas del juego
void Resource::loadTextures() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXTURES");
Logger::CR();
Logger::info("TEXTURES");
auto list = Asset::get()->getListByType(Asset::Type::BITMAP);
textures_.clear();
@@ -516,7 +519,8 @@ void Resource::loadTextures() {
// Carga los ficheros de texto del juego
void Resource::loadTextFiles() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> TEXT FILES");
Logger::CR();
Logger::info("TEXT FILES");
auto list = Asset::get()->getListByType(Asset::Type::FONT);
text_files_.clear();
@@ -529,7 +533,8 @@ void Resource::loadTextFiles() {
// Carga las animaciones del juego
void Resource::loadAnimations() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> ANIMATIONS");
Logger::CR();
Logger::info("ANIMATIONS");
auto list = Asset::get()->getListByType(Asset::Type::ANIMATION);
animations_.clear();
@@ -542,7 +547,8 @@ void Resource::loadAnimations() {
// Carga los datos para el modo demostración
void Resource::loadDemoData() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES");
Logger::CR();
Logger::info("DEMO FILES");
auto list = Asset::get()->getListByType(Asset::Type::DEMODATA);
demos_.clear();
@@ -555,7 +561,8 @@ void Resource::loadDemoData() {
// Crea las texturas de jugadores con todas sus variantes de paleta
void Resource::createPlayerTextures() {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING PLAYER TEXTURES");
Logger::CR();
Logger::info("CREATING PLAYER TEXTURES");
// Configuración de jugadores y sus paletas
struct PlayerConfig {
@@ -627,7 +634,7 @@ void Resource::createPlayerTextures() {
// Guardar con nombre específico
std::string texture_name = player.name_prefix + "_pal" + std::to_string(palette_idx);
textures_.emplace_back(texture_name, texture);
printWithDots("Player Texture : ", texture_name, "[ DONE ]");
Logger::dots("Player Texture : ", texture_name, "[ DONE ]");
}
}
}
@@ -643,7 +650,8 @@ void Resource::createTextTextures() {
text(std::move(text_init)) {}
};
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING TEXTURES");
Logger::CR();
Logger::info("CREATING TEXTURES");
// Texturas de tamaño normal con outline
std::vector<NameAndText> strings1 = {
@@ -658,7 +666,7 @@ void Resource::createTextTextures() {
auto text1 = getText("04b_25_enhanced");
for (const auto& s : strings1) {
textures_.emplace_back(s.name, text1->writeDXToTexture(Text::STROKE, s.text, -2, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color));
printWithDots("Texture : ", s.name, "[ DONE ]");
Logger::dots("Texture : ", s.name, "[ DONE ]");
}
// Texturas de tamaño doble
@@ -673,7 +681,7 @@ void Resource::createTextTextures() {
auto text2 = getText("04b_25_2x_enhanced");
for (const auto& s : strings2) {
textures_.emplace_back(s.name, text2->writeDXToTexture(Text::STROKE, s.text, -4, Colors::NO_COLOR_MOD, 1, param.game.item_text_outline_color));
printWithDots("Texture : ", s.name, "[ DONE ]");
Logger::dots("Texture : ", s.name, "[ DONE ]");
}
}
@@ -692,7 +700,8 @@ void Resource::createText() {
white_texture_file(std::move(w_file)) {}
};
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING TEXT OBJECTS");
Logger::CR();
Logger::info("CREATING TEXT OBJECTS");
std::vector<ResourceInfo> resources = {
{"04b_25", "04b_25.png", "04b_25.txt"},
@@ -719,7 +728,7 @@ void Resource::createText() {
// Crear texto normal
texts_.emplace_back(resource.key, std::make_shared<Text>(getTexture(resource.texture_file), getTextFile(resource.text_file)));
}
printWithDots("Text : ", resource.key, "[ DONE ]");
Logger::dots("Text : ", resource.key, "[ DONE ]");
}
}
@@ -881,7 +890,7 @@ void Resource::cleanupTempAudioFiles() {
try {
if (std::filesystem::exists(temp_path)) {
std::filesystem::remove(temp_path);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Removed temp audio file: %s", temp_path.c_str());
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Removed temp audio file: %s", temp_path.c_str());
}
} catch (const std::exception& e) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Failed to remove temp audio file %s: %s", temp_path.c_str(), e.what());

View File

@@ -15,6 +15,7 @@
#include "rendering/opengl/opengl_shader.hpp" // Para OpenGLShader
#include "text.hpp" // Para Text, Text::COLOR, Text::STROKE
#include "texture.hpp" // Para Texture
#include "ui/logger.hpp" // Para Logger
#include "ui/notifier.hpp" // Para Notifier
#include "ui/service_menu.hpp" // Para ServiceMenu
#include "utils.hpp" // Para Zone
@@ -279,8 +280,7 @@ void Screen::initShaders() {
#else
// En macOS, OpenGL está deprecated y rinde mal
// TODO: Implementar backend de Metal para shaders en macOS
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"Shaders no disponibles en macOS (OpenGL deprecated). Usa Metal backend.");
Logger::info("WARNING: Shaders no disponibles en macOS (OpenGL deprecated). Usa Metal backend.", Logger::YELLOW);
#endif
}
@@ -407,7 +407,7 @@ auto Screen::initSDLVideo() -> bool {
SDL_SetRenderDrawBlendMode(renderer_, SDL_BLENDMODE_BLEND);
SDL_SetRenderVSync(renderer_, Options::video.vsync ? 1 : SDL_RENDERER_VSYNC_DISABLED);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "** Video system initialized successfully");
Logger::info("Video system initialized successfully");
return true;
}
@@ -421,7 +421,8 @@ void Screen::getDisplayInfo() {
SDL_DisplayID instance_id = displays[i];
const char* name = SDL_GetDisplayName(instance_id);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Display %" SDL_PRIu32 ": %s", instance_id, (name != nullptr) ? name : "Unknown");
// SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Display %" SDL_PRIu32 ": %s", instance_id, (name != nullptr) ? name : "Unknown");
Logger::info(std::string("Display ") + std::to_string(instance_id) + ": " + (name != nullptr ? name : "Unknown"));
}
const auto* dm = SDL_GetCurrentDisplayMode(displays[0]);
@@ -437,15 +438,20 @@ void Screen::getDisplayInfo() {
Options::window.max_zoom = std::min(dm->w / param.game.width, dm->h / param.game.height);
Options::window.zoom = std::min(Options::window.zoom, Options::window.max_zoom);
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz", static_cast<int>(dm->w), static_cast<int>(dm->h), static_cast<int>(dm->refresh_rate));
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.zoom);
Options::video.info = std::to_string(static_cast<int>(dm->w)) + "x" +
std::to_string(static_cast<int>(dm->h)) + " @ " +
// Obtiene la cadena con la información sobre la resolución y el refresco
Options::video.info = std::to_string(dm->w) + "x" +
std::to_string(dm->h) + " @ " +
std::to_string(static_cast<int>(dm->refresh_rate)) + " Hz";
// Muestra información sobre el tamaño de la pantalla y de la ventana de juego
// SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Current display mode: %dx%d @ %dHz", static_cast<int>(dm->w), static_cast<int>(dm->h), static_cast<int>(dm->refresh_rate));
Logger::info("Current display mode: " + Options::video.info);
// SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Window resolution: %dx%d x%d", static_cast<int>(param.game.width), static_cast<int>(param.game.height), Options::window.zoom);
Logger::info("Window resolution: " + std::to_string(static_cast<int>(param.game.width)) + "x" + std::to_string(static_cast<int>(param.game.height)) + "x" + std::to_string(Options::window.zoom));
// Calcula el máximo factor de zoom que se puede aplicar a la pantalla
const int MAX_ZOOM = std::min(dm->w / param.game.width, (dm->h - WINDOWS_DECORATIONS) / param.game.height);

View File

@@ -14,6 +14,7 @@
#include "sprite.hpp" // Para Sprite
#include "texture.hpp" // Para Texture
#include "utils.hpp" // Para getFileName, printWithDots
#include "ui/logger.hpp"
// Constructor
Text::Text(const std::shared_ptr<Texture>& texture, const std::string& text_file) {
@@ -419,8 +420,8 @@ auto Text::loadFile(const std::string& file_path) -> std::shared_ptr<Text::File>
line_read++;
};
Logger::dots("Text File : ", getFileName(file_path), "[ LOADED ]");
// Cierra el fichero si se usó
printWithDots("Text File : ", getFileName(file_path), "[ LOADED ]");
if (!using_resource_data && file.is_open()) {
file.close();
}

View File

@@ -17,6 +17,7 @@
#include "resource_helper.hpp" // Para ResourceHelper
#include "stb_image.h" // Para stbi_image_free, stbi_load, STBI_rgb_alpha
#include "utils.hpp"
#include "ui/logger.hpp"
// Constructor
Texture::Texture(SDL_Renderer* renderer, std::string path)
@@ -82,7 +83,7 @@ auto Texture::loadFromFile(const std::string& file_path) -> bool {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error: Fichero no encontrado %s", getFileName(file_path).c_str());
throw std::runtime_error("Fichero no encontrado: " + getFileName(file_path));
}
printWithDots("Texture : ", getFileName(file_path), "[ LOADED ]");
Logger::dots("Texture : ", getFileName(file_path), "[ LOADED ]");
int pitch;
SDL_PixelFormat pixel_format;
@@ -330,7 +331,7 @@ auto Texture::loadPaletteFromFile(const std::string& file_path, bool quiet) -> P
}
if (!quiet) {
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
Logger::dots("Palette : ", getFileName(file_path), "[ LOADED ]");
}
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t>

View File

@@ -33,6 +33,21 @@ inline void info(const std::string& msg, const std::string& color = WHITE) {
std::cout << " " << color << msg << RESET << "\n";
}
// Put
inline void put(const std::string& msg, const std::string& color = WHITE) {
std::cout << color << msg << RESET << "\n";
}
// Error
inline void error(const std::string& msg) {
std::cout << RED << msg << RESET << "\n";
}
// CR
inline void CR() {
std::cout << "\n";
}
// Dots genérico
inline void dots(const std::string& prefix,
const std::string& middle,
@@ -49,7 +64,7 @@ inline void dots(const std::string& prefix,
field_text = middle.substr(0, field_width);
}
std::cout << prefix << field_text
std::cout << " " << prefix << field_text
<< suffixColor << suffix << RESET
<< "\n";
}

View File

@@ -294,32 +294,6 @@ auto stringInVector(const std::vector<std::string>& vec, const std::string& str)
return std::ranges::find(vec, str) != vec.end();
}
// Imprime por pantalla una línea de texto de tamaño fijo rellena con puntos
void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3) {
constexpr size_t TOTAL_WIDTH = 52;
// Calcula el ancho del campo para text2 restando la longitud de text1 y text3
size_t field_width = TOTAL_WIDTH > (text1.size() + text3.size())
? TOTAL_WIDTH - text1.size() - text3.size()
: 0;
// Prepara el bloque a imprimir a partir de text2
std::string field_text;
if (text2.size() < field_width) {
// Si text2 es más corto, lo rellenamos a la derecha con puntos
field_text = text2 + std::string(field_width - text2.size(), '.');
} else {
// Si es demasiado largo, lo cortamos
field_text = text2.substr(0, field_width);
}
// Concatena todo
std::string formatted_text = text1 + field_text + text3;
// Imprime la línea formateada usando SDL_LogInfo
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s", formatted_text.c_str());
}
// Obtiene el nombre de un fichero a partir de una ruta completa
auto getFileName(const std::string& path) -> std::string {
return std::filesystem::path(path).filename().string();

View File

@@ -84,7 +84,6 @@ auto easeInCubic(double time) -> double;
// Utilidades varias
auto stringInVector(const std::vector<std::string>& vec, const std::string& str) -> bool; // Comprueba si un vector contiene una cadena
void printWithDots(const std::string& text1, const std::string& text2, const std::string& text3); // Imprime una línea con puntos
auto truncateWithEllipsis(const std::string& input, size_t length) -> std::string; // Trunca un string y le añade puntos suspensivos
// Ficheros y rutas