forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -1,18 +1,19 @@
|
||||
#include "core/resources/resource.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h> // Para exit, size_t
|
||||
|
||||
#include <algorithm> // Para find_if
|
||||
#include <cstdlib> // Para exit, size_t
|
||||
#include <iostream> // Para basic_ostream, operator<<, endl, cout
|
||||
#include <stdexcept> // Para runtime_error
|
||||
#include <utility>
|
||||
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/text.hpp" // Para Text, loadTextFile
|
||||
#include "core/resources/asset.hpp" // Para AssetType, Asset
|
||||
#include "external/jail_audio.h" // Para JA_DeleteMusic, JA_DeleteSound, JA_Loa...
|
||||
#include "game/options.hpp" // Para Options, OptionsGame, options
|
||||
#include "game/gameplay/room.hpp" // Para RoomData, loadRoomFile, loadRoomTileFile
|
||||
#include "game/options.hpp" // Para Options, OptionsGame, options
|
||||
#include "utils/utils.hpp" // Para getFileName, printWithDots, PaletteColor
|
||||
struct JA_Music_t; // lines 17-17
|
||||
struct JA_Sound_t; // lines 18-18
|
||||
@@ -27,7 +28,7 @@ void Resource::init() { Resource::resource = new Resource(); }
|
||||
void Resource::destroy() { delete Resource::resource; }
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto screen y podemos trabajar con él
|
||||
Resource* Resource::get() { return Resource::resource; }
|
||||
auto Resource::get() -> Resource* { return Resource::resource; }
|
||||
|
||||
// Constructor
|
||||
Resource::Resource() { load(); }
|
||||
@@ -47,7 +48,7 @@ void Resource::clear() {
|
||||
void Resource::load() {
|
||||
calculateTotal();
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
||||
std::cout << "** LOADING RESOURCES" << std::endl;
|
||||
std::cout << "** LOADING RESOURCES" << '\n';
|
||||
loadSounds();
|
||||
loadMusics();
|
||||
loadSurfaces();
|
||||
@@ -57,7 +58,7 @@ void Resource::load() {
|
||||
loadTileMaps();
|
||||
loadRooms();
|
||||
createText();
|
||||
std::cout << "\n** RESOURCES LOADED" << std::endl;
|
||||
std::cout << "\n** RESOURCES LOADED" << '\n';
|
||||
}
|
||||
|
||||
// Recarga todos los recursos
|
||||
@@ -67,127 +68,127 @@ void Resource::reload() {
|
||||
}
|
||||
|
||||
// Obtiene el sonido a partir de un nombre
|
||||
JA_Sound_t* Resource::getSound(const std::string& name) {
|
||||
auto it = std::find_if(sounds_.begin(), sounds_.end(), [&name](const auto& s) { return s.name == name; });
|
||||
auto Resource::getSound(const std::string& name) -> JA_Sound_t* {
|
||||
auto it = std::ranges::find_if(sounds_, [&name](const auto& s) { return s.name == name; });
|
||||
|
||||
if (it != sounds_.end()) {
|
||||
return it->sound;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Sonido no encontrado " << name << std::endl;
|
||||
std::cerr << "Error: Sonido no encontrado " << name << '\n';
|
||||
throw std::runtime_error("Sonido no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la música a partir de un nombre
|
||||
JA_Music_t* Resource::getMusic(const std::string& name) {
|
||||
auto it = std::find_if(musics_.begin(), musics_.end(), [&name](const auto& m) { return m.name == name; });
|
||||
auto Resource::getMusic(const std::string& name) -> JA_Music_t* {
|
||||
auto it = std::ranges::find_if(musics_, [&name](const auto& m) { return m.name == name; });
|
||||
|
||||
if (it != musics_.end()) {
|
||||
return it->music;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Música no encontrada " << name << std::endl;
|
||||
std::cerr << "Error: Música no encontrada " << name << '\n';
|
||||
throw std::runtime_error("Música no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la surface a partir de un nombre
|
||||
std::shared_ptr<Surface> Resource::getSurface(const std::string& name) {
|
||||
auto it = std::find_if(surfaces_.begin(), surfaces_.end(), [&name](const auto& t) { return t.name == name; });
|
||||
auto Resource::getSurface(const std::string& name) -> std::shared_ptr<Surface> {
|
||||
auto it = std::ranges::find_if(surfaces_, [&name](const auto& t) { return t.name == name; });
|
||||
|
||||
if (it != surfaces_.end()) {
|
||||
return it->surface;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Imagen no encontrada " << name << std::endl;
|
||||
std::cerr << "Error: Imagen no encontrada " << name << '\n';
|
||||
throw std::runtime_error("Imagen no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la paleta a partir de un nombre
|
||||
Palette Resource::getPalette(const std::string& name) {
|
||||
auto it = std::find_if(palettes_.begin(), palettes_.end(), [&name](const auto& t) { return t.name == name; });
|
||||
auto Resource::getPalette(const std::string& name) -> Palette {
|
||||
auto it = std::ranges::find_if(palettes_, [&name](const auto& t) { return t.name == name; });
|
||||
|
||||
if (it != palettes_.end()) {
|
||||
return it->palette;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Paleta no encontrada " << name << std::endl;
|
||||
std::cerr << "Error: Paleta no encontrada " << name << '\n';
|
||||
throw std::runtime_error("Paleta no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el fichero de texto a partir de un nombre
|
||||
std::shared_ptr<TextFile> Resource::getTextFile(const std::string& name) {
|
||||
auto it = std::find_if(text_files_.begin(), text_files_.end(), [&name](const auto& t) { return t.name == name; });
|
||||
auto Resource::getTextFile(const std::string& name) -> std::shared_ptr<TextFile> {
|
||||
auto it = std::ranges::find_if(text_files_, [&name](const auto& t) { return t.name == name; });
|
||||
|
||||
if (it != text_files_.end()) {
|
||||
return it->text_file;
|
||||
}
|
||||
|
||||
std::cerr << "Error: TextFile no encontrado " << name << std::endl;
|
||||
std::cerr << "Error: TextFile no encontrado " << name << '\n';
|
||||
throw std::runtime_error("TextFile no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
std::shared_ptr<Text> Resource::getText(const std::string& name) {
|
||||
auto it = std::find_if(texts_.begin(), texts_.end(), [&name](const auto& t) { return t.name == name; });
|
||||
auto Resource::getText(const std::string& name) -> std::shared_ptr<Text> {
|
||||
auto it = std::ranges::find_if(texts_, [&name](const auto& t) { return t.name == name; });
|
||||
|
||||
if (it != texts_.end()) {
|
||||
return it->text;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Text no encontrado " << name << std::endl;
|
||||
std::cerr << "Error: Text no encontrado " << name << '\n';
|
||||
throw std::runtime_error("Texto no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
Animations& Resource::getAnimations(const std::string& name) {
|
||||
auto it = std::find_if(animations_.begin(), animations_.end(), [&name](const auto& a) { return a.name == name; });
|
||||
auto Resource::getAnimations(const std::string& name) -> Animations& {
|
||||
auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; });
|
||||
|
||||
if (it != animations_.end()) {
|
||||
return it->animation;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Animación no encontrada " << name << std::endl;
|
||||
std::cerr << "Error: Animación no encontrada " << name << '\n';
|
||||
throw std::runtime_error("Animación no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene el mapa de tiles a partir de un nombre
|
||||
std::vector<int>& Resource::getTileMap(const std::string& name) {
|
||||
auto it = std::find_if(tile_maps_.begin(), tile_maps_.end(), [&name](const auto& t) { return t.name == name; });
|
||||
auto Resource::getTileMap(const std::string& name) -> std::vector<int>& {
|
||||
auto it = std::ranges::find_if(tile_maps_, [&name](const auto& t) { return t.name == name; });
|
||||
|
||||
if (it != tile_maps_.end()) {
|
||||
return it->tile_map;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Mapa de tiles no encontrado " << name << std::endl;
|
||||
std::cerr << "Error: Mapa de tiles no encontrado " << name << '\n';
|
||||
throw std::runtime_error("Mapa de tiles no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la habitación a partir de un nombre
|
||||
std::shared_ptr<RoomData> Resource::getRoom(const std::string& name) {
|
||||
auto it = std::find_if(rooms_.begin(), rooms_.end(), [&name](const auto& r) { return r.name == name; });
|
||||
auto Resource::getRoom(const std::string& name) -> std::shared_ptr<RoomData> {
|
||||
auto it = std::ranges::find_if(rooms_, [&name](const auto& r) { return r.name == name; });
|
||||
|
||||
if (it != rooms_.end()) {
|
||||
return it->room;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Habitación no encontrada " << name << std::endl;
|
||||
std::cerr << "Error: Habitación no encontrada " << name << '\n';
|
||||
throw std::runtime_error("Habitación no encontrada: " + name);
|
||||
}
|
||||
|
||||
// Obtiene todas las habitaciones
|
||||
std::vector<ResourceRoom>& Resource::getRooms() {
|
||||
auto Resource::getRooms() -> std::vector<ResourceRoom>& {
|
||||
return rooms_;
|
||||
}
|
||||
|
||||
// Carga los sonidos
|
||||
void Resource::loadSounds() {
|
||||
std::cout << "\n>> SOUND FILES" << std::endl;
|
||||
std::cout << "\n>> SOUND FILES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::SOUND);
|
||||
sounds_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
sounds_.emplace_back(ResourceSound(name, JA_LoadSound(l.c_str())));
|
||||
sounds_.emplace_back(name, JA_LoadSound(l.c_str()));
|
||||
printWithDots("Sound : ", name, "[ LOADED ]");
|
||||
updateLoadingProgress();
|
||||
}
|
||||
@@ -195,13 +196,13 @@ void Resource::loadSounds() {
|
||||
|
||||
// Carga las musicas
|
||||
void Resource::loadMusics() {
|
||||
std::cout << "\n>> MUSIC FILES" << std::endl;
|
||||
std::cout << "\n>> MUSIC FILES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::MUSIC);
|
||||
musics_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
musics_.emplace_back(ResourceMusic(name, JA_LoadMusic(l.c_str())));
|
||||
musics_.emplace_back(name, JA_LoadMusic(l.c_str()));
|
||||
printWithDots("Music : ", name, "[ LOADED ]");
|
||||
updateLoadingProgress(1);
|
||||
}
|
||||
@@ -209,13 +210,13 @@ void Resource::loadMusics() {
|
||||
|
||||
// Carga las texturas
|
||||
void Resource::loadSurfaces() {
|
||||
std::cout << "\n>> SURFACES" << std::endl;
|
||||
std::cout << "\n>> SURFACES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::BITMAP);
|
||||
surfaces_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
surfaces_.emplace_back(ResourceSurface(name, std::make_shared<Surface>(l)));
|
||||
surfaces_.emplace_back(name, std::make_shared<Surface>(l));
|
||||
surfaces_.back().surface->setTransparentColor(0);
|
||||
updateLoadingProgress();
|
||||
}
|
||||
@@ -232,52 +233,52 @@ void Resource::loadSurfaces() {
|
||||
|
||||
// Carga las paletas
|
||||
void Resource::loadPalettes() {
|
||||
std::cout << "\n>> PALETTES" << std::endl;
|
||||
std::cout << "\n>> PALETTES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::PALETTE);
|
||||
palettes_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
palettes_.emplace_back(ResourcePalette(name, readPalFile(l)));
|
||||
palettes_.emplace_back(name, readPalFile(l));
|
||||
updateLoadingProgress();
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los ficheros de texto
|
||||
void Resource::loadTextFiles() {
|
||||
std::cout << "\n>> TEXT FILES" << std::endl;
|
||||
std::cout << "\n>> TEXT FILES" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::FONT);
|
||||
text_files_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
text_files_.emplace_back(ResourceTextFile(name, loadTextFile(l)));
|
||||
text_files_.emplace_back(name, loadTextFile(l));
|
||||
updateLoadingProgress();
|
||||
}
|
||||
}
|
||||
|
||||
// Carga las animaciones
|
||||
void Resource::loadAnimations() {
|
||||
std::cout << "\n>> ANIMATIONS" << std::endl;
|
||||
std::cout << "\n>> ANIMATIONS" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::ANIMATION);
|
||||
animations_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
animations_.emplace_back(ResourceAnimation(name, loadAnimationsFromFile(l)));
|
||||
animations_.emplace_back(name, loadAnimationsFromFile(l));
|
||||
updateLoadingProgress();
|
||||
}
|
||||
}
|
||||
|
||||
// Carga los mapas de tiles
|
||||
void Resource::loadTileMaps() {
|
||||
std::cout << "\n>> TILE MAPS" << std::endl;
|
||||
std::cout << "\n>> TILE MAPS" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::TILEMAP);
|
||||
tile_maps_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
tile_maps_.emplace_back(ResourceTileMap(name, loadRoomTileFile(l)));
|
||||
tile_maps_.emplace_back(name, loadRoomTileFile(l));
|
||||
printWithDots("TileMap : ", name, "[ LOADED ]");
|
||||
updateLoadingProgress();
|
||||
}
|
||||
@@ -285,13 +286,13 @@ void Resource::loadTileMaps() {
|
||||
|
||||
// Carga las habitaciones
|
||||
void Resource::loadRooms() {
|
||||
std::cout << "\n>> ROOMS" << std::endl;
|
||||
std::cout << "\n>> ROOMS" << '\n';
|
||||
auto list = Asset::get()->getListByType(AssetType::ROOM);
|
||||
rooms_.clear();
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
rooms_.emplace_back(ResourceRoom(name, std::make_shared<RoomData>(loadRoomFile(l))));
|
||||
rooms_.emplace_back(name, std::make_shared<RoomData>(loadRoomFile(l)));
|
||||
printWithDots("Room : ", name, "[ LOADED ]");
|
||||
updateLoadingProgress();
|
||||
}
|
||||
@@ -304,13 +305,13 @@ void Resource::createText() {
|
||||
std::string text_file; // Nombre del archivo de texto
|
||||
|
||||
// Constructor para facilitar la creación de objetos ResourceInfo
|
||||
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)) {}
|
||||
};
|
||||
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << std::endl;
|
||||
std::cout << "\n>> CREATING TEXT_OBJECTS" << '\n';
|
||||
|
||||
std::vector<ResourceInfo> resources = {
|
||||
{"debug", "debug.gif", "debug.txt"},
|
||||
@@ -320,7 +321,7 @@ void Resource::createText() {
|
||||
{"8bithud", "8bithud.gif", "8bithud.txt"}};
|
||||
|
||||
for (const auto& resource : resources) {
|
||||
texts_.emplace_back(ResourceText(resource.key, std::make_shared<Text>(getSurface(resource.texture_file), getTextFile(resource.text_file))));
|
||||
texts_.emplace_back(resource.key, std::make_shared<Text>(getSurface(resource.texture_file), getTextFile(resource.text_file)));
|
||||
printWithDots("Text : ", resource.key, "[ DONE ]");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user