This commit is contained in:
2025-10-27 18:56:24 +01:00
parent 3179a08dac
commit 5f47c88770
8 changed files with 121 additions and 119 deletions

View File

@@ -28,7 +28,7 @@ auto Input::get() -> Input* {
// Constructor // Constructor
Input::Input(const std::string& game_controller_db_path) Input::Input(const std::string& game_controller_db_path)
: game_controller_db_path_(std::move(game_controller_db_path)) { : game_controller_db_path_(game_controller_db_path) {
// Busca si hay mandos conectados // Busca si hay mandos conectados
discoverGameControllers(); discoverGameControllers();

View File

@@ -1,9 +1,9 @@
#include "core/rendering/screen.hpp" #include "core/rendering/screen.hpp"
#include <SDL3/SDL.h> #include <SDL3/SDL.h>
#include <ctype.h> // Para toupper
#include <algorithm> // Para max, min, transform #include <algorithm> // Para max, min, transform
#include <cctype> // Para toupper
#include <fstream> // Para basic_ostream, operator<<, endl, basic_... #include <fstream> // Para basic_ostream, operator<<, endl, basic_...
#include <iostream> // Para cerr #include <iostream> // Para cerr
#include <iterator> // Para istreambuf_iterator, operator== #include <iterator> // Para istreambuf_iterator, operator==
@@ -15,7 +15,7 @@
#include "core/rendering/text.hpp" // Para Text #include "core/rendering/text.hpp" // Para Text
#include "core/resources/asset.hpp" // Para Asset, AssetType #include "core/resources/asset.hpp" // Para Asset, AssetType
#include "core/resources/resource.hpp" // Para Resource #include "core/resources/resource.hpp" // Para Resource
#include "game/options.hpp" // Para Options, options, OptionsVideo, Border #include "game/options.hpp" // Para Options, options, OptionsVideo, Border
#include "game/ui/notifier.hpp" // Para Notifier #include "game/ui/notifier.hpp" // Para Notifier
// [SINGLETON] // [SINGLETON]
@@ -32,7 +32,7 @@ void Screen::destroy() {
} }
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Screen* Screen::get() { auto Screen::get() -> Screen* {
return Screen::screen; return Screen::screen;
} }
@@ -43,7 +43,7 @@ Screen::Screen()
initSDLVideo(); initSDLVideo();
// Ajusta los tamaños // Ajusta los tamaños
game_surface_dstrect_ = {Options::video.border.width, Options::video.border.height, Options::game.width, Options::game.height}; game_surface_dstrect_ = {.x = Options::video.border.width, .y = Options::video.border.height, .w = Options::game.width, .h = Options::game.height};
// adjustWindowSize(); // adjustWindowSize();
current_palette_ = findPalette(Options::video.palette); current_palette_ = findPalette(Options::video.palette);
@@ -55,7 +55,7 @@ Screen::Screen()
if (game_texture_ == nullptr) { if (game_texture_ == nullptr) {
// Registrar el error si está habilitado // Registrar el error si está habilitado
if (Options::console) { if (Options::console) {
std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl; std::cerr << "Error: game_texture_ could not be created!\nSDL Error: " << SDL_GetError() << '\n';
} }
} }
SDL_SetTextureScaleMode(game_texture_, SDL_SCALEMODE_NEAREST); SDL_SetTextureScaleMode(game_texture_, SDL_SCALEMODE_NEAREST);
@@ -65,7 +65,7 @@ Screen::Screen()
if (border_texture_ == nullptr) { if (border_texture_ == nullptr) {
// Registrar el error si está habilitado // Registrar el error si está habilitado
if (Options::console) { if (Options::console) {
std::cerr << "Error: border_texture_ could not be created!\nSDL Error: " << SDL_GetError() << std::endl; std::cerr << "Error: border_texture_ could not be created!\nSDL Error: " << SDL_GetError() << '\n';
} }
} }
SDL_SetTextureScaleMode(border_texture_, SDL_SCALEMODE_NEAREST); SDL_SetTextureScaleMode(border_texture_, SDL_SCALEMODE_NEAREST);
@@ -142,7 +142,7 @@ void Screen::toggleVideoMode() {
} }
// Reduce el tamaño de la ventana // Reduce el tamaño de la ventana
bool Screen::decWindowZoom() { auto Screen::decWindowZoom() -> bool {
if (static_cast<int>(Options::video.fullscreen) == 0) { if (static_cast<int>(Options::video.fullscreen) == 0) {
const int PREVIOUS_ZOOM = Options::window.zoom; const int PREVIOUS_ZOOM = Options::window.zoom;
--Options::window.zoom; --Options::window.zoom;
@@ -158,7 +158,7 @@ bool Screen::decWindowZoom() {
} }
// Aumenta el tamaño de la ventana // Aumenta el tamaño de la ventana
bool Screen::incWindowZoom() { auto Screen::incWindowZoom() -> bool {
if (static_cast<int>(Options::video.fullscreen) == 0) { if (static_cast<int>(Options::video.fullscreen) == 0) {
const int PREVIOUS_ZOOM = Options::window.zoom; const int PREVIOUS_ZOOM = Options::window.zoom;
++Options::window.zoom; ++Options::window.zoom;
@@ -235,7 +235,7 @@ void Screen::adjustRenderLogicalSize() {
} }
// Establece el renderizador para las surfaces // Establece el renderizador para las surfaces
void Screen::setRendererSurface(std::shared_ptr<Surface> surface) { void Screen::setRendererSurface(const std::shared_ptr<Surface> &surface) {
(surface) ? renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(surface) : renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_); (surface) ? renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(surface) : renderer_surface_ = std::make_shared<std::shared_ptr<Surface>>(game_surface_);
} }
@@ -274,7 +274,7 @@ void Screen::setPalete() {
} }
// Convertir a mayúsculas // Convertir a mayúsculas
std::transform(Options::video.palette.begin(), Options::video.palette.end(), Options::video.palette.begin(), ::toupper); std::ranges::transform(Options::video.palette, Options::video.palette.begin(), ::toupper);
} }
// Extrae los nombres de las paletas // Extrae los nombres de las paletas
@@ -316,7 +316,7 @@ void Screen::renderOverlays() {
} }
// Localiza la paleta dentro del vector de paletas // Localiza la paleta dentro del vector de paletas
size_t Screen::findPalette(const std::string& name) { auto Screen::findPalette(const std::string& name) -> size_t {
std::string upper_name = toUpper(name + ".pal"); std::string upper_name = toUpper(name + ".pal");
for (size_t i = 0; i < palettes_.size(); ++i) { for (size_t i = 0; i < palettes_.size(); ++i) {
@@ -373,11 +373,11 @@ void Screen::toggleIntegerScale() {
} }
// Getters // Getters
SDL_Renderer* Screen::getRenderer() { return renderer_; } auto Screen::getRenderer() -> SDL_Renderer* { return renderer_; }
std::shared_ptr<Surface> Screen::getRendererSurface() { return (*renderer_surface_); } auto Screen::getRendererSurface() -> std::shared_ptr<Surface> { return (*renderer_surface_); }
std::shared_ptr<Surface> Screen::getBorderSurface() { return border_surface_; } auto Screen::getBorderSurface() -> std::shared_ptr<Surface> { return border_surface_; }
std::vector<uint8_t> loadData(const std::string& filepath) { auto loadData(const std::string& filepath) -> std::vector<uint8_t> {
// Fallback a filesystem // Fallback a filesystem
std::ifstream file(filepath, std::ios::binary | std::ios::ate); std::ifstream file(filepath, std::ios::binary | std::ios::ate);
if (!file) { if (!file) {

View File

@@ -39,7 +39,7 @@ class Screen {
// Constructor para inicializar la estructura. // Constructor para inicializar la estructura.
FPS() FPS()
{} = default;
// Incrementador que se llama en cada frame. // Incrementador que se llama en cada frame.
void increment() { void increment() {
@@ -192,7 +192,7 @@ class Screen {
void hide(); void hide();
// Establece el renderizador para las surfaces // Establece el renderizador para las surfaces
void setRendererSurface(std::shared_ptr<Surface> surface = nullptr); void setRendererSurface(const std::shared_ptr<Surface> &surface = nullptr);
// Cambia la paleta // Cambia la paleta
void nextPalette(); void nextPalette();

View File

@@ -21,7 +21,7 @@ struct AnimationData {
AnimationData() AnimationData()
{} = default;
}; };
using Animations = std::vector<std::string>; using Animations = std::vector<std::string>;

View File

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

View File

@@ -2,6 +2,7 @@
#include <memory> // Para shared_ptr #include <memory> // Para shared_ptr
#include <string> // Para string #include <string> // Para string
#include <utility>
#include <vector> // Para vector #include <vector> // Para vector
#include "core/rendering/surface.hpp" // Para Surface #include "core/rendering/surface.hpp" // Para Surface
@@ -17,8 +18,8 @@ struct ResourceSound {
JA_Sound_t* sound; // Objeto con el sonido JA_Sound_t* sound; // Objeto con el sonido
// Constructor // Constructor
ResourceSound(const std::string& name, JA_Sound_t* sound) ResourceSound(std::string name, JA_Sound_t* sound)
: name(name), : name(std::move(name)),
sound(sound) {} sound(sound) {}
}; };
@@ -28,8 +29,8 @@ struct ResourceMusic {
JA_Music_t* music; // Objeto con la música JA_Music_t* music; // Objeto con la música
// Constructor // Constructor
ResourceMusic(const std::string& name, JA_Music_t* music) ResourceMusic(std::string name, JA_Music_t* music)
: name(name), : name(std::move(name)),
music(music) {} music(music) {}
}; };
@@ -39,9 +40,9 @@ struct ResourceSurface {
std::shared_ptr<Surface> surface; // Objeto con la surface std::shared_ptr<Surface> surface; // Objeto con la surface
// Constructor // Constructor
ResourceSurface(const std::string& name, std::shared_ptr<Surface> surface) ResourceSurface(std::string name, std::shared_ptr<Surface> surface)
: name(name), : name(std::move(name)),
surface(surface) {} surface(std::move(std::move(surface))) {}
}; };
// Estructura para almacenar objetos Palette y su nombre // Estructura para almacenar objetos Palette y su nombre
@@ -50,8 +51,8 @@ struct ResourcePalette {
Palette palette; // Paleta Palette palette; // Paleta
// Constructor // Constructor
ResourcePalette(const std::string& name, Palette palette) ResourcePalette(std::string name, Palette palette)
: name(name), : name(std::move(name)),
palette(palette) {} palette(palette) {}
}; };
@@ -61,9 +62,9 @@ struct ResourceTextFile {
std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto std::shared_ptr<TextFile> text_file; // Objeto con los descriptores de la fuente de texto
// Constructor // Constructor
ResourceTextFile(const std::string& name, std::shared_ptr<TextFile> text_file) ResourceTextFile(std::string name, std::shared_ptr<TextFile> text_file)
: name(name), : name(std::move(name)),
text_file(text_file) {} text_file(std::move(std::move(text_file))) {}
}; };
// Estructura para almacenar objetos Text y su nombre // Estructura para almacenar objetos Text y su nombre
@@ -72,9 +73,9 @@ struct ResourceText {
std::shared_ptr<Text> text; // Objeto std::shared_ptr<Text> text; // Objeto
// Constructor // Constructor
ResourceText(const std::string& name, std::shared_ptr<Text> text) ResourceText(std::string name, std::shared_ptr<Text> text)
: name(name), : name(std::move(name)),
text(text) {} text(std::move(std::move(text))) {}
}; };
// Estructura para almacenar ficheros animaciones y su nombre // Estructura para almacenar ficheros animaciones y su nombre
@@ -83,9 +84,9 @@ struct ResourceAnimation {
Animations animation; // Objeto con las animaciones Animations animation; // Objeto con las animaciones
// Constructor // Constructor
ResourceAnimation(const std::string& name, const Animations& animation) ResourceAnimation(std::string name, Animations animation)
: name(name), : name(std::move(name)),
animation(animation) {} animation(std::move(animation)) {}
}; };
// Estructura para almacenar ficheros con el mapa de tiles de una habitación y su nombre // Estructura para almacenar ficheros con el mapa de tiles de una habitación y su nombre
@@ -94,8 +95,8 @@ struct ResourceTileMap {
std::vector<int> tile_map; // Vector con los indices del mapa de tiles std::vector<int> tile_map; // Vector con los indices del mapa de tiles
// Constructor // Constructor
ResourceTileMap(const std::string& name, const std::vector<int>& tile_map) ResourceTileMap(std::string name, const std::vector<int>& tile_map)
: name(name), : name(std::move(name)),
tile_map(tile_map) {} tile_map(tile_map) {}
}; };
@@ -105,9 +106,9 @@ struct ResourceRoom {
std::shared_ptr<RoomData> room; // Habitación std::shared_ptr<RoomData> room; // Habitación
// Constructor // Constructor
ResourceRoom(const std::string& name, std::shared_ptr<RoomData> room) ResourceRoom(std::string name, std::shared_ptr<RoomData> room)
: name(name), : name(std::move(name)),
room(room) {} room(std::move(std::move(room))) {}
}; };
// Estructura para llevar la cuenta de los recursos cargados // Estructura para llevar la cuenta de los recursos cargados
@@ -131,7 +132,7 @@ struct ResourceCount {
} }
// Obtiene el porcentaje de recursos cargados // Obtiene el porcentaje de recursos cargados
float getPercentage() const { [[nodiscard]] auto getPercentage() const -> float {
return static_cast<float>(loaded) / static_cast<float>(total); return static_cast<float>(loaded) / static_cast<float>(total);
} }
}; };
@@ -220,37 +221,37 @@ class Resource {
static void destroy(); static void destroy();
// [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él // [SINGLETON] Con este método obtenemos el objeto resource y podemos trabajar con él
static Resource* get(); static auto get() -> Resource*;
// Obtiene el sonido a partir de un nombre // Obtiene el sonido a partir de un nombre
JA_Sound_t* getSound(const std::string& name); auto getSound(const std::string& name) -> JA_Sound_t*;
// Obtiene la música a partir de un nombre // Obtiene la música a partir de un nombre
JA_Music_t* getMusic(const std::string& name); auto getMusic(const std::string& name) -> JA_Music_t*;
// Obtiene la surface a partir de un nombre // Obtiene la surface a partir de un nombre
std::shared_ptr<Surface> getSurface(const std::string& name); auto getSurface(const std::string& name) -> std::shared_ptr<Surface>;
// Obtiene la paleta a partir de un nombre // Obtiene la paleta a partir de un nombre
Palette getPalette(const std::string& name); auto getPalette(const std::string& name) -> Palette;
// Obtiene el fichero de texto a partir de un nombre // Obtiene el fichero de texto a partir de un nombre
std::shared_ptr<TextFile> getTextFile(const std::string& name); auto getTextFile(const std::string& name) -> std::shared_ptr<TextFile>;
// Obtiene el objeto de texto a partir de un nombre // Obtiene el objeto de texto a partir de un nombre
std::shared_ptr<Text> getText(const std::string& name); auto getText(const std::string& name) -> std::shared_ptr<Text>;
// Obtiene la animación a partir de un nombre // Obtiene la animación a partir de un nombre
Animations& getAnimations(const std::string& name); auto getAnimations(const std::string& name) -> Animations&;
// Obtiene el mapa de tiles a partir de un nombre // Obtiene el mapa de tiles a partir de un nombre
std::vector<int>& getTileMap(const std::string& name); auto getTileMap(const std::string& name) -> std::vector<int>&;
// Obtiene la habitación a partir de un nombre // Obtiene la habitación a partir de un nombre
std::shared_ptr<RoomData> getRoom(const std::string& name); auto getRoom(const std::string& name) -> std::shared_ptr<RoomData>;
// Obtiene todas las habitaciones // Obtiene todas las habitaciones
std::vector<ResourceRoom>& getRooms(); auto getRooms() -> std::vector<ResourceRoom>&;
// Recarga todos los recursos // Recarga todos los recursos
void reload(); void reload();

View File

@@ -21,7 +21,7 @@ void Debug::destroy() {
} }
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él // [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
Debug* Debug::get() { auto Debug::get() -> Debug* {
return Debug::debug; return Debug::debug;
} }

View File

@@ -4,6 +4,7 @@
#include <algorithm> // Para remove_if #include <algorithm> // Para remove_if
#include <iterator> // Para prev #include <iterator> // Para prev
#include <ranges> // Para reverse_view
#include <string> // Para string, basic_string #include <string> // Para string, basic_string
#include <vector> // Para vector #include <vector> // Para vector
@@ -44,8 +45,8 @@ Notifier::Notifier(const std::string& icon_file, const std::string& text)
// Dibuja las notificaciones por pantalla // Dibuja las notificaciones por pantalla
void Notifier::render() { void Notifier::render() {
for (auto it = notifications_.rbegin(); it != notifications_.rend(); ++it) { for (auto& notification : std::ranges::reverse_view(notifications_)) {
it->sprite->render(); notification.sprite->render();
} }
} }
@@ -104,11 +105,10 @@ void Notifier::update() {
// Elimina las notificaciones finalizadas // Elimina las notificaciones finalizadas
void Notifier::clearFinishedNotifications() { void Notifier::clearFinishedNotifications() {
notifications_.erase( auto result = std::ranges::remove_if(notifications_, [](const Notification& notification) {
std::remove_if(notifications_.begin(), notifications_.end(), [](const Notification& notification) { return notification.state == Status::FINISHED;
return notification.state == Status::FINISHED; });
}), notifications_.erase(result.begin(), result.end());
notifications_.end());
} }
void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Uint32 display_duration, int icon, bool can_be_removed, const std::string& code) { void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Uint32 display_duration, int icon, bool can_be_removed, const std::string& code) {
@@ -123,8 +123,8 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
} }
// Elimina las cadenas vacías // Elimina las cadenas vacías
texts.erase(std::remove_if(texts.begin(), texts.end(), [](const std::string& s) { return s.empty(); }), auto result = std::ranges::remove_if(texts, [](const std::string& s) { return s.empty(); });
texts.end()); texts.erase(result.begin(), result.end());
// Encuentra la cadena más larga // Encuentra la cadena más larga
std::string longest; std::string longest;