Passant std::cout a SDL_Log

This commit is contained in:
2025-03-27 19:57:30 +01:00
parent c6288918b2
commit 8afca398e9
27 changed files with 588 additions and 764 deletions

View File

@@ -1,9 +1,9 @@
#include "asset.h"
#include <algorithm> // Para find_if, max
#include <fstream> // Para basic_ostream, operator<<, basic_ifstream, endl
#include <iostream> // Para cout
#include <string> // Para allocator, char_traits, string, operator+, oper...
#include "utils.h" // Para getFileName, printWithDots
#include <SDL3/SDL_log.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_LogError
#include <algorithm> // Para find_if, max
#include <fstream> // Para basic_ifstream, ifstream
#include <string> // Para allocator, string, char_traits, operator+
#include "utils.h" // Para getFileName
// [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado
Asset *Asset::asset_ = nullptr;
@@ -48,7 +48,7 @@ std::string Asset::get(const std::string &text) const
}
else
{
std::cout << "Warning: file " << text << " not found" << std::endl;
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s not found", text.c_str());
return "";
}
}
@@ -58,12 +58,9 @@ bool Asset::check() const
{
bool success = true;
std::cout << "\n** CHECKING FILES" << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
// std::cout << "Executable path is: " << executable_path_ << std::endl;
// std::cout << "Sample filepath: " << file_list_.back().file << std::endl;
// Comprueba la lista de ficheros clasificandolos por tipo
// Comprueba la lista de ficheros clasificándolos por tipo
for (int type = 0; type < static_cast<int>(AssetType::MAX_ASSET_TYPE); ++type)
{
// Comprueba si hay ficheros de ese tipo
@@ -80,7 +77,7 @@ bool Asset::check() const
// Si hay ficheros de ese tipo, comprueba si existen
if (any)
{
std::cout << "\n>> " << getTypeName(static_cast<AssetType>(type)).c_str() << " FILES" << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> %s FILES", getTypeName(static_cast<AssetType>(type)).c_str());
for (const auto &f : file_list_)
{
@@ -90,12 +87,19 @@ bool Asset::check() const
}
}
if (success)
std::cout << " All files are OK." << std::endl;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " All files are OK.");
}
}
// Resultado
std::cout << (success ? "\n** CHECKING FILES COMPLETED.\n" : "\n** CHECKING FILES FAILED.\n") << std::endl;
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;
}
@@ -108,7 +112,9 @@ bool Asset::checkFile(const std::string &path) const
file.close();
if (!success)
printWithDots("Checking file : ", getFileName(path), "[ ERROR ]");
{
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Checking file: %s [ ERROR ]", getFileName(path).c_str());
}
return success;
}
@@ -120,43 +126,24 @@ std::string Asset::getTypeName(AssetType type) const
{
case AssetType::BITMAP:
return "BITMAP";
break;
case AssetType::MUSIC:
return "MUSIC";
break;
case AssetType::SOUND:
return "SOUND";
break;
case AssetType::FONT:
return "FONT";
break;
case AssetType::LANG:
return "LANG";
break;
case AssetType::DATA:
return "DATA";
break;
case AssetType::ANIMATION:
return "ANIMATION";
break;
case AssetType::PALETTE:
return "PALETTE";
break;
case AssetType::ITEM:
return "ITEM";
break;
default:
return "ERROR";
break;
}
}