#pragma once #include #include #include #include "utils.h" // Tipos de recursos gestionados por Asset enum class AssetType : int { BITMAP, MUSIC, SOUND, FONT, LANG, DATA, ANIMATION, PALETTE, ITEM, MAX_ASSET_TYPE, }; // Clase Asset: gestor de recursos (singleton) class Asset { public: // Inicializa la instancia única del singleton static void init(const std::string &executable_path); // Libera la instancia única static void destroy(); // Obtiene la instancia única static Asset *get(); // 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 getListByType(AssetType type) const; private: friend std::unique_ptr::deleter_type; // Estructura interna para almacenar información de cada recurso 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 AssetItem(const std::string &filePath, AssetType assetType, bool isRequired) : file(filePath), type(assetType), required(isRequired) {} }; // Variables internas int longest_name_ = 0; // Longitud del nombre más largo std::vector 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; // Verifica si un archivo existe std::string getTypeName(AssetType type) const; // Devuelve el nombre textual del tipo de recurso // Patrón Singleton: constructor y destructor privados, sin copia ni asignación Asset(const std::string &executable_path) : executable_path_(executable_path) {}; ~Asset() = default; Asset(const Asset &) = delete; Asset &operator=(const Asset &) = delete; static std::unique_ptr instance_; };