clang-tidy: animated_sprite, asset

This commit is contained in:
2025-07-18 21:27:21 +02:00
parent dabba41179
commit f9877dc82b
5 changed files with 191 additions and 144 deletions

View File

@@ -18,7 +18,7 @@ void Asset::init(const std::string &executable_path) { Asset::instance_ = new As
void Asset::destroy() { delete Asset::instance_; }
// Obtiene la instancia
Asset *Asset::get() { return Asset::instance_; }
auto Asset::get() -> Asset * { return Asset::instance_; }
// Añade un elemento a la lista
void Asset::add(const std::string &file, AssetType type, bool required, bool absolute) {
@@ -27,21 +27,20 @@ void Asset::add(const std::string &file, AssetType type, bool required, bool abs
}
// Devuelve la ruta completa a un fichero a partir de una cadena
std::string Asset::get(const std::string &text) const {
auto it = std::find_if(file_list_.begin(), file_list_.end(), [&text](const auto &f) {
return getFileName(f.file) == text;
auto Asset::get(const std::string &text) const -> std::string {
auto iterator = std::ranges::find_if(file_list_, [&text](const auto &file) {
return getFileName(file.file) == text;
});
if (it != file_list_.end()) {
return it->file;
} else {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s not found", text.c_str());
return "";
if (iterator != file_list_.end()) {
return iterator->file;
}
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION, "Warning: file %s not found", text.c_str());
return "";
}
// Comprueba que existen todos los elementos
bool Asset::check() const {
auto Asset::check() const -> bool {
bool success = true;
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n** CHECKING FILES");
@@ -51,8 +50,8 @@ bool Asset::check() const {
// Comprueba si hay ficheros de ese tipo
bool any = false;
for (const auto &f : file_list_) {
if (f.required && f.type == static_cast<AssetType>(type)) {
for (const auto &file : file_list_) {
if (file.required && file.type == static_cast<AssetType>(type)) {
any = true;
}
}
@@ -61,13 +60,14 @@ bool Asset::check() const {
if (any) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> %s FILES", getTypeName(static_cast<AssetType>(type)).c_str());
for (const auto &f : file_list_) {
if (f.required && f.type == static_cast<AssetType>(type)) {
success &= checkFile(f.file);
for (const auto &file : file_list_) {
if (file.required && file.type == static_cast<AssetType>(type)) {
success &= checkFile(file.file);
}
}
if (success)
if (success) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, " All files are OK.");
}
}
}
@@ -82,7 +82,7 @@ bool Asset::check() const {
}
// Comprueba que existe un fichero
bool Asset::checkFile(const std::string &path) const {
auto Asset::checkFile(const std::string &path) -> bool {
std::ifstream file(path);
bool success = file.good();
file.close();
@@ -95,7 +95,7 @@ bool Asset::checkFile(const std::string &path) const {
}
// Devuelve el nombre del tipo de recurso
std::string Asset::getTypeName(AssetType type) const {
auto Asset::getTypeName(AssetType type) -> std::string {
switch (type) {
case AssetType::BITMAP:
return "BITMAP";
@@ -121,12 +121,12 @@ std::string Asset::getTypeName(AssetType type) const {
}
// Devuelve la lista de recursos de un tipo
std::vector<std::string> Asset::getListByType(AssetType type) const {
auto Asset::getListByType(AssetType type) const -> std::vector<std::string> {
std::vector<std::string> list;
for (auto f : file_list_) {
if (f.type == type) {
list.push_back(f.file);
for (auto file : file_list_) {
if (file.type == type) {
list.push_back(file.file);
}
}