clang-tidy: animated_sprite, asset
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // Para string, basic_string
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
// Tipos de recursos gestionados por Asset
|
||||
@@ -18,28 +19,30 @@ enum class AssetType : int {
|
||||
};
|
||||
|
||||
// Clase Asset: gestor de recursos (singleton)
|
||||
class Asset {
|
||||
class Asset { // Gestor de recursos (singleton)
|
||||
public:
|
||||
// --- Métodos de singleton ---
|
||||
static void init(const std::string &executable_path); // Inicializa el objeto Asset
|
||||
static void destroy(); // Libera el objeto Asset
|
||||
static Asset *get(); // Obtiene el puntero al objeto Asset
|
||||
static auto get() -> Asset *; // Obtiene el puntero al objeto Asset
|
||||
Asset(const Asset &) = delete; // No se permite copiar
|
||||
auto operator=(const Asset &) -> Asset & = delete; // No se permite asignar
|
||||
|
||||
// --- Métodos para la gestión de recursos ---
|
||||
void add(const std::string &file, AssetType type, bool required = true, bool absolute = false); // Añade un recurso a la lista
|
||||
std::string get(const std::string &text) const; // Obtiene la ruta completa de un recurso a partir de su nombre
|
||||
bool check() const; // Verifica la existencia de todos los recursos requeridos
|
||||
std::vector<std::string> getListByType(AssetType type) const; // Devuelve una lista de archivos de un tipo concreto
|
||||
[[nodiscard]] auto get(const std::string &text) const -> std::string; // Obtiene la ruta completa de un recurso a partir de su nombre
|
||||
[[nodiscard]] auto check() const -> bool; // Verifica la existencia de todos los recursos requeridos
|
||||
[[nodiscard]] auto getListByType(AssetType type) const -> std::vector<std::string>; // Devuelve una lista de archivos de un tipo concreto
|
||||
|
||||
private:
|
||||
// --- Estructura interna para almacenar información de cada recurso ---
|
||||
struct AssetItem {
|
||||
struct AssetItem { // Estructura para cada recurso
|
||||
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) {}
|
||||
AssetItem(std::string filePath, AssetType assetType, bool isRequired)
|
||||
: file(std::move(filePath)), type(assetType), required(isRequired) {} // Constructor
|
||||
};
|
||||
|
||||
// --- Variables internas ---
|
||||
@@ -48,16 +51,14 @@ class Asset {
|
||||
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
|
||||
[[nodiscard]] static auto checkFile(const std::string &path) -> bool; // Verifica si un archivo existe (interno)
|
||||
[[nodiscard]] static auto getTypeName(AssetType type) -> std::string; // Devuelve el nombre textual del tipo de recurso (interno)
|
||||
|
||||
// --- Patrón Singleton ---
|
||||
explicit Asset(const std::string &executable_path)
|
||||
: executable_path_(executable_path) {}
|
||||
~Asset() = default;
|
||||
Asset(const Asset &) = delete;
|
||||
Asset &operator=(const Asset &) = delete;
|
||||
explicit Asset(std::string executable_path)
|
||||
: executable_path_(std::move(executable_path)) {} // Constructor privado
|
||||
~Asset() = default; // Destructor
|
||||
|
||||
// --- Singleton ---
|
||||
static Asset *instance_;
|
||||
static Asset *instance_; // Instancia singleton
|
||||
};
|
||||
Reference in New Issue
Block a user