commit de merda pa llevar la branch

This commit is contained in:
2025-05-29 12:25:19 +02:00
parent 0fc8224ef8
commit 5fd987c6a1
4 changed files with 60 additions and 53 deletions

View File

@@ -2,10 +2,9 @@
#include <string>
#include <vector>
#include "utils.h"
// === Enumeraciones ===
// Tipos de recursos gestionados por Asset
enum class AssetType : int
{
BITMAP,
@@ -20,30 +19,37 @@ enum class AssetType : int
MAX_ASSET_TYPE,
};
// Clase Asset: gestor de recursos (singleton)
class Asset
{
public:
// === Singleton ===
static Asset &get() // Obtención de la instancia única (Meyers Singleton)
// Obtención de la instancia única (Meyers Singleton)
static Asset &get()
{
static Asset instance;
return instance;
}
// === Inicialización ===
// Inicializa el gestor de recursos con la ruta del ejecutable
void init(const std::string &executable_path)
{
executable_path_ = getPath(executable_path);
}
// === 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
// Añade un recurso a la lista
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
// Obtiene la ruta completa de un recurso a partir de su nombre
std::string get(const std::string &text) const;
// Verifica la existencia de todos los recursos requeridos
bool check() const;
// Devuelve una lista de archivos de un tipo concreto
std::vector<std::string> getListByType(AssetType type) const;
private:
// === Estructura Interna ===
// Estructura interna para almacenar información de cada recurso
struct AssetItem
{
std::string file; // Ruta del fichero desde la raíz del directorio
@@ -54,18 +60,18 @@ private:
: file(filePath), type(assetType), required(isRequired) {}
};
// === Variables Internas ===
// Variables internas
int longest_name_ = 0; // Longitud del nombre más largo
std::vector<AssetItem> file_list_; // Lista con todas las rutas
std::vector<AssetItem> file_list_; // Lista con todas las rutas de recursos
std::string executable_path_; // Ruta del ejecutable
// === 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
// Métodos internos
bool checkFile(const std::string &path) const; // Verifica si un archivo existe
std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso
// === 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
// Patrón Singleton: constructor y destructor privados, sin copia ni asignación
Asset() = default;
~Asset() = default;
Asset(const Asset &) = delete;
Asset &operator=(const Asset &) = delete;
};