clang-tidy modernize

This commit is contained in:
2025-07-20 12:51:24 +02:00
parent bfda842d3c
commit 1f0184fde2
74 changed files with 658 additions and 665 deletions

View File

@@ -1,11 +1,12 @@
#include "resource.h"
#include <SDL3/SDL.h> // Para SDL_LogInfo, SDL_LogCategory, SDL_L...
#include <stdlib.h> // Para exit
#include <algorithm> // Para find_if
#include <array> // Para array
#include <cstdlib> // Para exit
#include <stdexcept> // Para runtime_error
#include <utility>
#include "asset.h" // Para Asset, AssetType
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_...
@@ -27,7 +28,7 @@ void Resource::init() { Resource::instance = new Resource(); }
void Resource::destroy() { delete Resource::instance; }
// Obtiene la instancia
Resource *Resource::get() { return Resource::instance; }
auto Resource::get() -> Resource * { return Resource::instance; }
// Constructor
Resource::Resource() : loading_text_(Screen::get()->getText()) { load(); }
@@ -87,7 +88,7 @@ void Resource::reloadTextures() {
}
// Obtiene el sonido a partir de un nombre. Lanza excepción si no existe.
JA_Sound_t *Resource::getSound(const std::string &name) {
auto Resource::getSound(const std::string &name) -> JA_Sound_t * {
auto it = std::find_if(sounds_.begin(), sounds_.end(), [&name](const auto &s) { return s.name == name; });
if (it != sounds_.end()) {
@@ -99,7 +100,7 @@ JA_Sound_t *Resource::getSound(const std::string &name) {
}
// Obtiene la música a partir de un nombre. Lanza excepción si no existe.
JA_Music_t *Resource::getMusic(const std::string &name) {
auto Resource::getMusic(const std::string &name) -> JA_Music_t * {
auto it = std::find_if(musics_.begin(), musics_.end(), [&name](const auto &m) { return m.name == name; });
if (it != musics_.end()) {
@@ -111,7 +112,7 @@ JA_Music_t *Resource::getMusic(const std::string &name) {
}
// Obtiene la textura a partir de un nombre. Lanza excepción si no existe.
std::shared_ptr<Texture> Resource::getTexture(const std::string &name) {
auto Resource::getTexture(const std::string &name) -> std::shared_ptr<Texture> {
auto it = std::find_if(textures_.begin(), textures_.end(), [&name](const auto &t) { return t.name == name; });
if (it != textures_.end()) {
@@ -123,7 +124,7 @@ std::shared_ptr<Texture> Resource::getTexture(const std::string &name) {
}
// Obtiene el fichero de texto a partir de un nombre. Lanza excepción si no existe.
std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name) {
auto Resource::getTextFile(const std::string &name) -> std::shared_ptr<TextFile> {
auto it = std::find_if(text_files_.begin(), text_files_.end(), [&name](const auto &t) { return t.name == name; });
if (it != text_files_.end()) {
@@ -135,7 +136,7 @@ std::shared_ptr<TextFile> Resource::getTextFile(const std::string &name) {
}
// Obtiene el objeto de texto a partir de un nombre. Lanza excepción si no existe.
std::shared_ptr<Text> Resource::getText(const std::string &name) {
auto Resource::getText(const std::string &name) -> std::shared_ptr<Text> {
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto &t) { return t.name == name; });
if (it != texts_.end()) {
@@ -147,7 +148,7 @@ std::shared_ptr<Text> Resource::getText(const std::string &name) {
}
// Obtiene la animación a partir de un nombre. Lanza excepción si no existe.
AnimationsFileBuffer &Resource::getAnimation(const std::string &name) {
auto Resource::getAnimation(const std::string &name) -> AnimationsFileBuffer & {
auto it = std::find_if(animations_.begin(), animations_.end(), [&name](const auto &a) { return a.name == name; });
if (it != animations_.end()) {
@@ -159,7 +160,7 @@ AnimationsFileBuffer &Resource::getAnimation(const std::string &name) {
}
// Obtiene el fichero con los datos para el modo demostración a partir de un índice
DemoData &Resource::getDemoData(int index) {
auto Resource::getDemoData(int index) -> DemoData & {
return demos_.at(index);
}
@@ -172,7 +173,7 @@ void Resource::loadSounds() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
sounds_.emplace_back(Resource::ResourceSound(name, JA_LoadSound(l.c_str())));
sounds_.emplace_back(name, JA_LoadSound(l.c_str()));
printWithDots("Sound : ", name, "[ LOADED ]");
}
}
@@ -186,7 +187,7 @@ void Resource::loadMusics() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
musics_.emplace_back(Resource::ResourceMusic(name, JA_LoadMusic(l.c_str())));
musics_.emplace_back(name, JA_LoadMusic(l.c_str()));
printWithDots("Music : ", name, "[ LOADED ]");
}
}
@@ -200,7 +201,7 @@ void Resource::loadTextures() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
textures_.emplace_back(Resource::ResourceTexture(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l)));
textures_.emplace_back(name, std::make_shared<Texture>(Screen::get()->getRenderer(), l));
}
}
@@ -213,7 +214,7 @@ void Resource::loadTextFiles() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
text_files_.emplace_back(Resource::ResourceTextFile(name, loadTextFile(l)));
text_files_.emplace_back(name, loadTextFile(l));
}
}
@@ -226,7 +227,7 @@ void Resource::loadAnimations() {
for (const auto &l : list) {
auto name = getFileName(l);
updateLoadingProgress(name);
animations_.emplace_back(Resource::ResourceAnimation(name, loadAnimationsFromFile(l)));
animations_.emplace_back(name, loadAnimationsFromFile(l));
}
}
@@ -263,8 +264,8 @@ void Resource::createTextures() {
std::string name;
std::string text;
NameAndText(const std::string &name_init, const std::string &text_init)
: name(name_init), text(text_init) {}
NameAndText(std::string name_init, std::string text_init)
: name(std::move(name_init)), text(std::move(text_init)) {}
};
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING TEXTURES");
@@ -281,7 +282,7 @@ void Resource::createTextures() {
auto text = getText("04b_25");
for (const auto &s : strings) {
textures_.emplace_back(Resource::ResourceTexture(s.name, text->writeToTexture(s.text, 1, -2)));
textures_.emplace_back(s.name, text->writeToTexture(s.text, 1, -2));
printWithDots("Texture : ", s.name, "[ DONE ]");
}
@@ -295,7 +296,7 @@ void Resource::createTextures() {
auto text2 = getText("04b_25_2x");
for (const auto &s : strings2_x) {
textures_.emplace_back(Resource::ResourceTexture(s.name, text2->writeToTexture(s.text, 1, -4)));
textures_.emplace_back(s.name, text2->writeToTexture(s.text, 1, -4));
printWithDots("Texture : ", s.name, "[ DONE ]");
}
}
@@ -307,8 +308,8 @@ void Resource::createText() {
std::string texture_file;
std::string text_file;
ResourceInfo(const std::string &k, const std::string &t_file, const std::string &txt_file)
: key(k), texture_file(t_file), text_file(txt_file) {}
ResourceInfo(std::string k, std::string t_file, std::string txt_file)
: key(std::move(k)), texture_file(std::move(t_file)), text_file(std::move(txt_file)) {}
};
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> CREATING TEXT OBJECTS");
@@ -328,7 +329,7 @@ void Resource::createText() {
{"smb2_grad", "smb2_grad.png", "smb2.txt"}};
for (const auto &resource : resources) {
texts_.emplace_back(Resource::ResourceText(resource.key, std::make_shared<Text>(getTexture(resource.texture_file), getTextFile(resource.text_file))));
texts_.emplace_back(resource.key, std::make_shared<Text>(getTexture(resource.texture_file), getTextFile(resource.text_file)));
printWithDots("Text : ", resource.key, "[ DONE ]");
}
}