#pragma once #include #include #include #include // Clase Asset: gestor optimizado de recursos (singleton) class Asset { public: // Tipos de recursos enum class Type : int { BITMAP, MUSIC, SOUND, FONT, LANG, DATA, DEMODATA, ANIMATION, PALETTE, SIZE, }; // --- Métodos de singleton --- static void init(const std::string &executable_path); static void destroy(); static auto get() -> Asset *; Asset(const Asset &) = delete; auto operator=(const Asset &) -> Asset & = delete; // --- Métodos para la gestión de recursos --- void add(const std::string &file_path, Type type, bool required = true, bool absolute = false); void loadFromFile(const std::string &config_file_path, const std::string &prefix = "", const std::string &system_folder = ""); // Con soporte para variables [[nodiscard]] auto get(const std::string &filename) const -> std::string; // Mantener nombre original [[nodiscard]] auto check() const -> bool; [[nodiscard]] auto getListByType(Type type) const -> std::vector; [[nodiscard]] auto exists(const std::string &filename) const -> bool; // Nueva función para verificar existencia private: // --- Estructura interna para almacenar información de cada recurso --- struct Item { std::string file; // Ruta completa del archivo (mantener nombre original) Type type; // Tipo de recurso bool required; // Indica si el archivo es obligatorio Item(std::string path, Type asset_type, bool is_required) : file(std::move(path)), type(asset_type), required(is_required) {} }; // --- Variables internas --- std::unordered_map file_list_; // Mapa para búsqueda O(1) (mantener nombre original) std::string executable_path_; // Ruta del ejecutable // --- Métodos internos --- [[nodiscard]] static auto checkFile(const std::string &path) -> bool; [[nodiscard]] static auto getTypeName(Type type) -> std::string; [[nodiscard]] static auto parseAssetType(const std::string &type_str) -> Type; void addToMap(const std::string &file_path, Type type, bool required, bool absolute); [[nodiscard]] static auto replaceVariables(const std::string &path, const std::string &prefix, const std::string &system_folder) -> std::string; static auto parseOptions(const std::string &options, bool &required, bool &absolute) -> void; // --- Patrón Singleton --- explicit Asset(std::string executable_path) : executable_path_(std::move(executable_path)) {} ~Asset() = default; static Asset *instance; };