revisió de capçaleres

This commit is contained in:
2025-05-29 09:58:23 +02:00
parent 677e4d465d
commit 0fc8224ef8
45 changed files with 1870 additions and 2684 deletions

View File

@@ -1,9 +1,11 @@
#pragma once
#include <string> // Para manejar cadenas de texto
#include <vector> // Para estructuras dinámicas de datos
#include "utils.h" // Para la función getPath
#include <string>
#include <vector>
#include "utils.h"
// === Enumeraciones ===
enum class AssetType : int
{
BITMAP,
@@ -18,57 +20,52 @@ enum class AssetType : int
MAX_ASSET_TYPE,
};
// Clase Asset
class Asset
{
public:
// Obtención de la instancia única (*Meyers Singleton*)
static Asset &get()
// === Singleton ===
static Asset &get() // Obtención de la instancia única (Meyers Singleton)
{
static Asset instance;
return instance;
}
// === Inicialización ===
void init(const std::string &executable_path)
{
executable_path_ = getPath(executable_path);
}
// Manejo de archivos
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); // Añade un recurso
std::string get(const std::string &text) const; // Devuelve la ruta completa de un recurso
bool check() const; // Verifica la existencia de todos los elementos
std::vector<std::string> getListByType(AssetType type) const; // Obtiene lista de recursos de un tipo específico
// === Gestión de Recursos ===
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); // Añadir recurso
std::string get(const std::string &text) const; // Obtener ruta completa
bool check() const; // Verificar existencia
std::vector<std::string> getListByType(AssetType type) const; // Lista por tipo
private:
// Estructura para definir un recurso
// === Estructura Interna ===
struct AssetItem
{
std::string file; // Ruta del fichero desde la raíz del directorio
AssetType type; // Tipo de recurso
bool required; // Indica si el fichero es obligatorio
// Constructor
AssetItem(const std::string &filePath, AssetType assetType, bool isRequired)
: file(filePath), type(assetType), required(isRequired) {}
};
// Variables internas
int longest_name_ = 0; // Longitud del nombre de archivo más largo
std::vector<AssetItem> file_list_; // Lista con todas las rutas de los archivos
// === Variables Internas ===
int longest_name_ = 0; // Longitud del nombre más largo
std::vector<AssetItem> file_list_; // Lista con todas las rutas
std::string executable_path_; // Ruta del ejecutable
// Métodos internos
bool checkFile(const std::string &path) const; // Verifica si un archivo existe
std::string getTypeName(AssetType type) const; // Obtiene el nombre textual del tipo de recurso
// === Métodos Internos ===
bool checkFile(const std::string &path) const; // Verificar si archivo existe
std::string getTypeName(AssetType type) const; // Obtener nombre textual del tipo
// Constructor privado
Asset() = default;
// Destructor privado
~Asset() = default;
// Evita copia y asignación
Asset(const Asset &) = delete;
Asset &operator=(const Asset &) = delete;
};
// === Patrón Singleton ===
Asset() = default; // Constructor privado
~Asset() = default; // Destructor privado
Asset(const Asset &) = delete; // Evitar copia
Asset &operator=(const Asset &) = delete; // Evitar asignación
};