unificats els resources en un namespace

This commit is contained in:
2025-11-11 10:04:57 +01:00
parent 1821b84e73
commit 54fc6d2902
35 changed files with 356 additions and 341 deletions

View File

@@ -11,7 +11,7 @@
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/system/global_events.hpp" // Para check
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
#include "game/scene_manager.hpp" // Para SceneManager
@@ -23,7 +23,7 @@
Credits::Credits()
: text_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
cover_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("shine.ani"))),
shining_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations("shine.ani"))),
delta_timer_(std::make_unique<DeltaTimer>()) {
// Configura la escena
SceneManager::current = SceneManager::Scene::CREDITS;
@@ -111,7 +111,7 @@ void Credits::fillTexture() {
Screen::get()->setRendererSurface(text_surface_);
text_surface_->clear(static_cast<Uint8>(PaletteColor::BLACK));
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
// Escribe el texto en la textura
const int SIZE = text->getCharacterSize();

View File

@@ -11,7 +11,7 @@
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/surface_sprite.hpp" // Para SSprite
#include "core/rendering/text.hpp" // Para Text, TEXT_STROKE
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/system/global_events.hpp" // Para check
#include "game/options.hpp" // Para Options, options, OptionsGame, SectionS...
#include "game/scene_manager.hpp" // Para SceneManager
@@ -209,7 +209,7 @@ void Ending::iniTexts() {
sprite_texts_.clear();
for (const auto& txt : texts) {
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
const float WIDTH = text->lenght(txt.caption, 1) + 2 + 2;
const float HEIGHT = text->getCharacterSize() + 2 + 2;
@@ -284,7 +284,7 @@ void Ending::iniPics() {
EndingSurface sp;
// Crea la texture
sp.image_surface = Resource::get()->getSurface(pic.caption);
sp.image_surface = Resource::Cache::get()->getSurface(pic.caption);
sp.image_surface->setTransparentColor();
const float WIDTH = sp.image_surface->getWidth();
const float HEIGHT = sp.image_surface->getHeight();

View File

@@ -12,7 +12,7 @@
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
#include "core/rendering/surface_moving_sprite.hpp" // Para SMovingSprite
#include "core/rendering/text.hpp" // Para Text
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/system/global_events.hpp" // Para check
#include "game/options.hpp" // Para Options, options, OptionsGame, Sectio...
#include "game/scene_manager.hpp" // Para SceneManager
@@ -34,13 +34,12 @@ Ending2::Ending2()
colors_.push_back(stringToColor(color));
}
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));// Cambia el color del borde
iniSpriteList();// Inicializa la lista de sprites
loadSprites();// Carga todos los sprites desde una lista
placeSprites();// Coloca los sprites en su sito
createSpriteTexts();// Crea los sprites con las texturas con los textos
createTexts();// Crea los sprites con las texturas con los textos del final
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
iniSpriteList(); // Inicializa la lista de sprites
loadSprites(); // Carga todos los sprites desde una lista
placeSprites(); // Coloca los sprites en su sito
createSpriteTexts(); // Crea los sprites con las texturas con los textos
createTexts(); // Crea los sprites con las texturas con los textos del final
}
// Actualiza el objeto
@@ -288,7 +287,7 @@ void Ending2::loadSprites() {
// Carga los sprites
for (const auto& file : sprite_list_) {
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations(file + ".ani")));
sprites_.emplace_back(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations(file + ".ani")));
sprite_max_width_ = std::max(sprites_.back()->getWidth(), sprite_max_width_);
sprite_max_height_ = std::max(sprites_.back()->getHeight(), sprite_max_height_);
}
@@ -358,7 +357,7 @@ void Ending2::renderTexts() {
void Ending2::placeSprites() {
for (int i = 0; i < static_cast<int>(sprites_.size()); ++i) {
const float X = i % 2 == 0 ? FIRST_COL : SECOND_COL;
const float Y = ((i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT + Resource::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE)) + Options::game.height + INITIAL_Y_OFFSET;
const float Y = ((i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT + Resource::Cache::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE)) + Options::game.height + INITIAL_Y_OFFSET;
const float W = sprites_.at(i)->getWidth();
const float H = sprites_.at(i)->getHeight();
const float DX = -(W / 2);
@@ -379,7 +378,7 @@ void Ending2::placeSprites() {
void Ending2::createSpriteTexts() {
// Crea los sprites de texto a partir de la lista
for (size_t i = 0; i < sprite_list_.size(); ++i) {
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
// Procesa y ajusta el texto del sprite actual
std::string txt = sprite_list_[i];
@@ -420,7 +419,7 @@ void Ending2::createTexts() {
std::vector<std::string> list;
list.emplace_back("STARRING");
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
// Crea los sprites de texto a partir de la lista
for (size_t i = 0; i < list.size(); ++i) {

View File

@@ -5,26 +5,26 @@
#include <utility>
#include <vector> // Para vector
#include "core/audio/audio.hpp" // Para Audio
#include "core/input/global_inputs.hpp" // Para check
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "core/resources/asset.hpp" // Para Asset
#include "core/resources/resource.hpp" // Para ResourceRoom, Resource
#include "core/system/global_events.hpp" // Para check
#include "game/gameplay/cheevos.hpp" // Para Cheevos
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data, Scoreboard
#include "game/gameplay/stats.hpp" // Para Stats
#include "game/options.hpp" // Para Options, options, Cheat, SectionState
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/defines.hpp" // Para TILE_SIZE, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#include "core/audio/audio.hpp" // Para Audio
#include "core/input/global_inputs.hpp" // Para check
#include "core/input/input.hpp" // Para Input, InputAction, Input::DO_NOT_ALLOW_REPEAT
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "core/resources/resource_cache.hpp" // Para ResourceRoom, Resource
#include "core/resources/resource_list.hpp" // Para Asset
#include "core/system/global_events.hpp" // Para check
#include "game/gameplay/cheevos.hpp" // Para Cheevos
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
#include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data, Scoreboard
#include "game/gameplay/stats.hpp" // Para Stats
#include "game/options.hpp" // Para Options, options, Cheat, SectionState
#include "game/scene_manager.hpp" // Para SceneManager
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/defines.hpp" // Para TILE_SIZE, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#ifdef _DEBUG
#include "core/system/debug.hpp" // Para Debug
@@ -35,7 +35,7 @@ Game::Game(Mode mode)
: board_(std::make_shared<Scoreboard::Data>(0, 9, 0, true, 0, SDL_GetTicks(), Options::cheats.jail_is_open == Options::Cheat::State::ENABLED)),
scoreboard_(std::make_shared<Scoreboard>(board_)),
room_tracker_(std::make_shared<RoomTracker>()),
stats_(std::make_shared<Stats>(Asset::get()->get("stats.csv"), Asset::get()->get("stats_buffer.csv"))),
stats_(std::make_shared<Stats>(Resource::List::get()->get("stats.csv"), Resource::List::get()->get("stats_buffer.csv"))),
mode_(mode),
#ifdef _DEBUG
current_room_("03.room"),
@@ -229,7 +229,7 @@ void Game::handleDebugEvents(const SDL_Event& event) {
break;
case SDL_SCANCODE_R:
Resource::get()->reload();
Resource::Cache::get()->reload();
break;
case SDL_SCANCODE_W:
@@ -273,7 +273,7 @@ auto Game::changeRoom(const std::string& room_path) -> bool {
}
// Verifica que exista el fichero que se va a cargar
if (!Asset::get()->get(room_path).empty()) {
if (!Resource::List::get()->get(room_path).empty()) {
// Crea un objeto habitación nuevo a partir del fichero
room_ = std::make_shared<Room>(room_path, board_);
@@ -441,7 +441,7 @@ auto Game::checkEndGame() -> bool {
// Obtiene la cantidad total de items que hay en el mapeado del juego
auto Game::getTotalItems() -> int {
int items = 0;
auto rooms = Resource::get()->getRooms();
auto rooms = Resource::Cache::get()->getRooms();
for (const auto& room : rooms) {
items += room.room->items.size();
@@ -486,7 +486,7 @@ void Game::checkRestoringJail(float delta_time) {
// Inicializa el diccionario de las estadísticas
void Game::initStats() {
auto list = Resource::get()->getRooms();
auto list = Resource::Cache::get()->getRooms();
for (const auto& room : list) {
stats_->addDictionary(room.room->number, room.room->name);
@@ -505,7 +505,7 @@ void Game::fillRoomNameTexture() {
room_name_surface_->clear(stringToColor("white"));
// Escribe el texto en la textura
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, text->getCharacterSize() / 2, room_->getName(), 1, room_->getBGColor());
// Deja el renderizador por defecto
@@ -580,7 +580,7 @@ void Game::initPlayer(const Player::SpawnData& spawn_point, std::shared_ptr<Room
// Crea la textura para poner el nombre de la habitación
void Game::createRoomNameTexture() {
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
room_name_surface_ = std::make_shared<Surface>(Options::game.width, text->getCharacterSize() * 2);
// Establece el destino de la textura

View File

@@ -11,7 +11,7 @@
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
#include "core/rendering/text.hpp" // Para TEXT_CENTER, TEXT_COLOR, Text
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/system/global_events.hpp" // Para check
#include "game/options.hpp" // Para Options, options, OptionsStats, Secti...
#include "game/scene_manager.hpp" // Para SceneManager
@@ -21,8 +21,8 @@
// Constructor
GameOver::GameOver()
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("player_game_over.ani"))),
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getAnimations("tv.ani"))),
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations("player_game_over.ani"))),
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::Cache::get()->getAnimations("tv.ani"))),
delta_timer_(std::make_shared<DeltaTimer>()) {
SceneManager::current = SceneManager::Scene::GAME_OVER;
SceneManager::options = SceneManager::Options::NONE;
@@ -65,7 +65,7 @@ void GameOver::render() {
Screen::get()->start();
Screen::get()->clearSurface(static_cast<Uint8>(PaletteColor::BLACK));
auto text = Resource::get()->getText("smb2");
auto text = Resource::Cache::get()->getText("smb2");
// Escribe el texto de GAME OVER
text->writeDX(TEXT_CENTER | TEXT_COLOR, GAMECANVAS_CENTER_X, TEXT_Y, "G A M E O V E R", 1, color_);

View File

@@ -11,7 +11,7 @@
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/surface_sprite.hpp" // Para SSprite
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/system/global_events.hpp" // Para check
#include "game/options.hpp" // Para Options, options, SectionState, Options...
#include "game/scene_manager.hpp" // Para SceneManager
@@ -20,11 +20,11 @@
// Constructor
LoadingScreen::LoadingScreen()
: mono_loading_screen_surface_(Resource::get()->getSurface("loading_screen_bn.gif")),
color_loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
: mono_loading_screen_surface_(Resource::Cache::get()->getSurface("loading_screen_bn.gif")),
color_loading_screen_surface_(Resource::Cache::get()->getSurface("loading_screen_color.gif")),
mono_loading_screen_sprite_(std::make_unique<SurfaceSprite>(mono_loading_screen_surface_, 0, 0, mono_loading_screen_surface_->getWidth(), mono_loading_screen_surface_->getHeight())),
color_loading_screen_sprite_(std::make_unique<SurfaceSprite>(color_loading_screen_surface_, 0, 0, color_loading_screen_surface_->getWidth(), color_loading_screen_surface_->getHeight())),
program_sprite_(std::make_unique<SurfaceSprite>(Resource::get()->getSurface("program_jaildoc.gif"))),
program_sprite_(std::make_unique<SurfaceSprite>(Resource::Cache::get()->getSurface("program_jaildoc.gif"))),
screen_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
delta_timer_(std::make_unique<DeltaTimer>()) {
// Configura la superficie donde se van a pintar los sprites
@@ -312,7 +312,7 @@ void LoadingScreen::renderHeaderBorder() const {
const auto COLOR = carrier_.toggle ? static_cast<Uint8>(PaletteColor::RED) : static_cast<Uint8>(PaletteColor::CYAN);
const int WIDTH = Options::game.width + (Options::video.border.width * 2);
const int HEIGHT = Options::game.height + (Options::video.border.height * 2);
// Primera linea (con el color y tamaño de la portadora)
int row = 0;
const int FIRST_ROW_HEIGHT = static_cast<int>(carrier_.offset);
@@ -320,7 +320,7 @@ void LoadingScreen::renderHeaderBorder() const {
border->drawLine(0, i, WIDTH, i, COLOR);
}
row += FIRST_ROW_HEIGHT;
// Resto de lineas (siguen a la portadora)
bool draw_enabled = false;
while (row < HEIGHT) {

View File

@@ -12,7 +12,7 @@
#include "core/rendering/screen.hpp" // Para Screen
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/surface_sprite.hpp" // Para SSprite
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/system/global_events.hpp" // Para check
#include "game/options.hpp" // Para Options, SectionState, options, Section
#include "game/scene_manager.hpp" // Para SceneManager
@@ -22,8 +22,8 @@
// Constructor
Logo::Logo()
: jailgames_surface_(Resource::get()->getSurface("jailgames.gif")),
since_1998_surface_(Resource::get()->getSurface("since_1998.gif")),
: jailgames_surface_(Resource::Cache::get()->getSurface("jailgames.gif")),
since_1998_surface_(Resource::Cache::get()->getSurface("since_1998.gif")),
since_1998_sprite_(std::make_shared<SurfaceSprite>(since_1998_surface_, (256 - since_1998_surface_->getWidth()) / 2, 83 + jailgames_surface_->getHeight() + 5, since_1998_surface_->getWidth(), since_1998_surface_->getHeight())),
delta_timer_(std::make_unique<DeltaTimer>()) {
// Configura variables

View File

@@ -11,8 +11,8 @@
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/surface_sprite.hpp" // Para SSprite
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "core/resources/asset.hpp" // Para Asset
#include "core/resources/resource.hpp" // Para Resource
#include "core/resources/resource_cache.hpp" // Para Resource
#include "core/resources/resource_list.hpp" // Para Asset
#include "core/system/global_events.hpp" // Para check
#include "game/gameplay/cheevos.hpp" // Para Cheevos, Achievement
#include "game/options.hpp" // Para Options, options, SectionState, Section
@@ -22,14 +22,14 @@
// Constructor
Title::Title()
: game_logo_surface_(Resource::get()->getSurface("title_logo.gif")),
: game_logo_surface_(Resource::Cache::get()->getSurface("title_logo.gif")),
game_logo_sprite_(std::make_unique<SurfaceSprite>(game_logo_surface_, 29, 9, game_logo_surface_->getWidth(), game_logo_surface_->getHeight())),
loading_screen_surface_(Resource::get()->getSurface("loading_screen_color.gif")),
loading_screen_surface_(Resource::Cache::get()->getSurface("loading_screen_color.gif")),
loading_screen_sprite_(std::make_unique<SurfaceSprite>(loading_screen_surface_, 0, 0, loading_screen_surface_->getWidth(), loading_screen_surface_->getHeight())),
title_surface_(std::make_shared<Surface>(Options::game.width, Options::game.height)),
delta_timer_(std::make_unique<DeltaTimer>()),
marquee_text_(Resource::get()->getText("gauntlet")),
menu_text_(Resource::get()->getText("gauntlet")) {
marquee_text_(Resource::Cache::get()->getText("gauntlet")),
menu_text_(Resource::Cache::get()->getText("gauntlet")) {
// Inicializa arrays con valores por defecto
temp_keys_.fill(SDL_SCANCODE_UNKNOWN);
temp_buttons_.fill(-1);
@@ -437,7 +437,7 @@ void Title::createCheevosTexture() {
// Crea la textura con el listado de logros
const auto CHEEVOS_LIST = Cheevos::get()->list();
const auto TEXT = Resource::get()->getText("subatomic");
const auto TEXT = Resource::Cache::get()->getText("subatomic");
constexpr int CHEEVOS_TEXTURE_WIDTH = 200;
constexpr int CHEEVOS_TEXTURE_VIEW_HEIGHT = MENU_ZONE_HEIGHT;
constexpr int CHEEVOS_PADDING = 10;
@@ -653,7 +653,7 @@ void Title::applyKeyboardRemap() {
Input::get()->applyKeyboardBindingsFromOptions();
// Guardar a archivo de configuracion
Options::saveToFile(Asset::get()->get("config.txt"));
Options::saveToFile(Resource::List::get()->get("config.txt"));
}
// Dibuja la pantalla de redefinir teclado
@@ -836,7 +836,7 @@ void Title::applyJoystickRemap() {
Input::get()->applyGamepadBindingsFromOptions();
// Guardar a archivo de configuracion
Options::saveToFile(Asset::get()->get("config.txt"));
Options::saveToFile(Resource::List::get()->get("config.txt"));
}
// Retorna el nombre amigable del botón del gamepad