renombrades extensions .h a .hpp

This commit is contained in:
2025-10-17 21:45:19 +02:00
parent 50ccb2ccc2
commit 46974ef2eb
144 changed files with 1758 additions and 1783 deletions

View File

@@ -1,4 +1,4 @@
#include "asset.h"
#include "asset.hpp"
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
@@ -10,14 +10,14 @@
#include <sstream> // Para basic_istringstream
#include <stdexcept> // Para runtime_error
#include "resource_helper.h" // Para ResourceHelper
#include "utils.h" // Para getFileName
#include "ui/logger.h" // Pâra Logger
#include "resource_helper.hpp" // Para ResourceHelper
#include "ui/logger.hpp" // Pâra Logger
#include "utils.hpp" // Para getFileName
// Singleton
Asset *Asset::instance = nullptr;
Asset* Asset::instance = nullptr;
void Asset::init(const std::string &executable_path) {
void Asset::init(const std::string& executable_path) {
Asset::instance = new Asset(executable_path);
}
@@ -25,12 +25,12 @@ void Asset::destroy() {
delete Asset::instance;
}
auto Asset::get() -> Asset * {
auto Asset::get() -> Asset* {
return Asset::instance;
}
// Añade un elemento al mapa (función auxiliar)
void Asset::addToMap(const std::string &file_path, Type type, bool required, bool absolute) {
void Asset::addToMap(const std::string& file_path, Type type, bool required, bool absolute) {
std::string full_path = absolute ? file_path : executable_path_ + file_path;
std::string filename = getFileName(full_path);
@@ -45,13 +45,13 @@ void Asset::addToMap(const std::string &file_path, Type type, bool required, boo
}
// Añade un elemento a la lista
void Asset::add(const std::string &file_path, Type type, bool required, bool absolute) {
void Asset::add(const std::string& file_path, Type type, bool required, bool absolute) {
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) {
void Asset::loadFromFile(const std::string& config_file_path, const std::string& prefix, const std::string& system_folder) {
std::ifstream file(config_file_path);
if (!file.is_open()) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
@@ -96,7 +96,7 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
}
try {
const std::string &type_str = parts[0];
const std::string& type_str = parts[0];
std::string path = parts[1];
// Valores por defecto
@@ -117,7 +117,7 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
// Añadir al mapa
addToMap(path, type, required, absolute);
} catch (const std::exception &e) {
} catch (const std::exception& e) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Error parsing line %d in config file: %s",
line_number,
@@ -133,7 +133,7 @@ void Asset::loadFromFile(const std::string &config_file_path, const std::string
}
// Devuelve la ruta completa a un fichero (búsqueda O(1))
auto Asset::get(const std::string &filename) const -> std::string {
auto Asset::get(const std::string& filename) const -> std::string {
auto it = file_list_.find(filename);
if (it != file_list_.end()) {
return it->second.file;
@@ -144,7 +144,7 @@ auto Asset::get(const std::string &filename) const -> std::string {
}
// Carga datos del archivo usando ResourceHelper
auto Asset::loadData(const std::string &filename) const -> std::vector<uint8_t> {
auto Asset::loadData(const std::string& filename) const -> std::vector<uint8_t> {
auto it = file_list_.find(filename);
if (it != file_list_.end()) {
return ResourceHelper::loadFile(it->second.file);
@@ -155,7 +155,7 @@ auto Asset::loadData(const std::string &filename) const -> std::vector<uint8_t>
}
// Verifica si un recurso existe
auto Asset::exists(const std::string &filename) const -> bool {
auto Asset::exists(const std::string& filename) const -> bool {
return file_list_.find(filename) != file_list_.end();
}
@@ -163,13 +163,13 @@ auto Asset::exists(const std::string &filename) const -> bool {
auto Asset::check() const -> bool {
bool success = true;
//SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
// SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
Logger::section("CHECKING FILES", Logger::CYAN);
// Agrupar por tipo para mostrar organizado
std::unordered_map<Type, std::vector<const Item *>> by_type;
std::unordered_map<Type, std::vector<const Item*>> by_type;
for (const auto &[filename, item] : file_list_) {
for (const auto& [filename, item] : file_list_) {
if (item.required) {
by_type[item.type].push_back(&item);
}
@@ -185,7 +185,7 @@ auto Asset::check() const -> bool {
getTypeName(asset_type).c_str());
bool type_success = true;
for (const auto *item : by_type[asset_type]) {
for (const auto* item : by_type[asset_type]) {
if (!checkFile(item->file)) {
success = false;
type_success = false;
@@ -209,7 +209,7 @@ auto Asset::check() const -> bool {
}
// Comprueba que existe un fichero
auto Asset::checkFile(const std::string &path) const -> bool {
auto Asset::checkFile(const std::string& path) const -> bool {
// Construir ruta del pack usando executable_path_
std::string pack_path = executable_path_ + "resources.pack";
bool pack_exists = std::filesystem::exists(pack_path);
@@ -226,7 +226,8 @@ auto Asset::checkFile(const std::string &path) const -> bool {
if (!success) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
"Error: Could not open file: %s", path.c_str());
"Error: Could not open file: %s",
path.c_str());
}
return success;
@@ -234,7 +235,7 @@ auto Asset::checkFile(const std::string &path) const -> bool {
}
// Parsea string a Type
auto Asset::parseAssetType(const std::string &type_str) -> Type {
auto Asset::parseAssetType(const std::string& type_str) -> Type {
if (type_str == "BITMAP") {
return Type::BITMAP;
}
@@ -296,7 +297,7 @@ auto Asset::getTypeName(Type type) -> std::string {
auto Asset::getListByType(Type type) const -> std::vector<std::string> {
std::vector<std::string> list;
for (const auto &[filename, item] : file_list_) {
for (const auto& [filename, item] : file_list_) {
if (item.type == type) {
list.push_back(item.file);
}
@@ -309,7 +310,7 @@ auto Asset::getListByType(Type type) const -> std::vector<std::string> {
}
// Reemplaza variables en las rutas
auto Asset::replaceVariables(const std::string &path, const std::string &prefix, const std::string &system_folder) -> std::string {
auto Asset::replaceVariables(const std::string& path, const std::string& prefix, const std::string& system_folder) -> std::string {
std::string result = path;
// Reemplazar ${PREFIX}
@@ -330,7 +331,7 @@ auto Asset::replaceVariables(const std::string &path, const std::string &prefix,
}
// Parsea las opciones de una línea de configuración
auto Asset::parseOptions(const std::string &options, bool &required, bool &absolute) -> void {
auto Asset::parseOptions(const std::string& options, bool& required, bool& absolute) -> void {
if (options.empty()) {
return;
}