convertit Asset i Audio

This commit is contained in:
2025-05-27 11:06:17 +02:00
parent 9bc07b2bcb
commit ada141cb09
29 changed files with 493 additions and 472 deletions

View File

@@ -1,8 +1,8 @@
#pragma once
#include <string> // Para string
#include <vector> // Para vector
#include "utils.h" // Para getPath
#include <string> // Para manejar cadenas de texto
#include <vector> // Para estructuras dinámicas de datos
#include "utils.h" // Para la función getPath
enum class AssetType : int
{
@@ -21,59 +21,54 @@ enum class AssetType : int
// Clase Asset
class Asset
{
private:
// [SINGLETON] Objeto asset privado
static Asset *asset_;
public:
// Obtención de la instancia única (*Meyers Singleton*)
static Asset &get()
{
static Asset instance;
return instance;
}
// Estructura para definir un item
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
private:
// Estructura para definir un recurso
struct AssetItem
{
std::string file; // Ruta del fichero desde la raíz del directorio
AssetType type; // Indica el tipo de recurso
bool required; // Indica si es un fichero que debe de existir
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
int longest_name_ = 0; // Contiene la longitud del nombre de fichero mas largo
std::vector<AssetItem> file_list_; // Listado con todas las rutas a los ficheros
std::string executable_path_; // Ruta al ejecutable
// 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
std::string executable_path_; // Ruta del ejecutable
// Comprueba que existe un fichero
bool checkFile(const std::string &path) const;
// 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
// Devuelve el nombre del tipo de recurso
std::string getTypeName(AssetType type) const;
// Constructor privado
Asset() = default;
// Constructor
explicit Asset(const std::string &executable_path)
: executable_path_(getPath(executable_path)) {}
// Destructor
// Destructor privado
~Asset() = default;
public:
// [SINGLETON] Crearemos el objeto con esta función estática
static void init(const std::string &executable_path);
// [SINGLETON] Destruiremos el objeto con esta función estática
static void destroy();
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
static Asset *get();
// Añade un elemento a la lista
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false);
// Devuelve la ruta completa a un fichero a partir de una cadena
std::string get(const std::string &text) const;
// Comprueba que existen todos los elementos
bool check() const;
// Devuelve la lista de recursos de un tipo
std::vector<std::string> getListByType(AssetType type) const;
};
// Evita copia y asignación
Asset(const Asset &) = delete;
Asset &operator=(const Asset &) = delete;
};