canviat Options de struct a namespace

This commit is contained in:
2025-10-26 14:01:08 +01:00
parent 8f49e442de
commit df4965a84b
59 changed files with 1470 additions and 1533 deletions

View File

@@ -4,30 +4,30 @@
#include <vector> // Para vector
#include "core/resources/asset.hpp" // Para Asset
#include "game/gameplay/cheevos.hpp" // Para Cheevos
#include "core/system/debug.hpp" // Para Debug
#include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
#include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
#include "utils/global_events.hpp" // Para check
#include "core/input/global_inputs.hpp" // Para check
#include "core/input/input.hpp" // Para Input, InputAction, INPUT_DO_NOT_ALLOW_REPEAT
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/options.hpp" // Para Options, options, Cheat, SectionState
#include "core/resources/resource.hpp" // Para ResourceRoom, Resource
#include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
#include "game/gameplay/scoreboard.hpp" // Para ScoreboardData, Scoreboard
#include "core/rendering/screen.hpp" // Para Screen
#include "game/gameplay/stats.hpp" // Para Stats
#include "core/rendering/surface.hpp" // Para Surface
#include "core/rendering/text.hpp" // Para Text, TEXT_CENTER, TEXT_COLOR
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
#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/debug.hpp" // Para Debug
#include "external/jail_audio.h" // Para JA_PauseMusic, JA_GetMusicState, JA_P...
#include "game/gameplay/cheevos.hpp" // Para Cheevos
#include "game/gameplay/item_tracker.hpp" // Para ItemTracker
#include "game/gameplay/options.hpp" // Para Options, options, Cheat, SectionState
#include "game/gameplay/room.hpp" // Para Room, RoomData
#include "game/gameplay/room_tracker.hpp" // Para RoomTracker
#include "game/gameplay/scoreboard.hpp" // Para ScoreboardData, Scoreboard
#include "game/gameplay/stats.hpp" // Para Stats
#include "game/ui/notifier.hpp" // Para Notifier, NotificationText, CHEEVO_NO...
#include "utils/defines.hpp" // Para BLOCK, PLAY_AREA_HEIGHT, RoomBorder::BOTTOM
#include "utils/global_events.hpp" // Para check
#include "utils/utils.hpp" // Para PaletteColor, stringToColor
// Constructor
Game::Game(GameMode mode)
: board_(std::make_shared<ScoreboardData>(0, 9, 0, true, 0, SDL_GetTicks(), options.cheats.jail_is_open == Cheat::CheatState::ENABLED)),
: board_(std::make_shared<ScoreboardData>(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"))),
@@ -55,11 +55,11 @@ Game::Game(GameMode mode)
createRoomNameTexture();
changeRoom(current_room_);
Cheevos::get()->enable(!options.cheats.enabled()); // Deshabilita los logros si hay trucos activados
Cheevos::get()->enable(!Options::cheats.enabled()); // Deshabilita los logros si hay trucos activados
Cheevos::get()->clearUnobtainableState();
options.section.section = (mode_ == GameMode::GAME) ? Section::GAME : Section::DEMO;
options.section.subsection = Subsection::NONE;
Options::section.section = (mode_ == GameMode::GAME) ? Options::Scene::GAME : Options::Scene::DEMO;
Options::section.subsection = Options::SceneOptions::NONE;
}
Game::~Game() {
@@ -100,7 +100,7 @@ void Game::run() {
JA_PauseMusic();
}
while (options.section.section == Section::GAME || options.section.section == Section::DEMO) {
while (Options::section.section == Options::Scene::GAME || Options::section.section == Options::Scene::DEMO) {
update();
checkEvents();
render();
@@ -219,7 +219,7 @@ void Game::checkDebugEvents(const SDL_Event& event) {
switch (event.key.key) {
case SDL_SCANCODE_G:
Debug::get()->toggleEnabled();
options.cheats.invincible = static_cast<Cheat::CheatState>(Debug::get()->getEnabled());
Options::cheats.invincible = static_cast<Options::Cheat::State>(Debug::get()->getEnabled());
board_->music = !Debug::get()->getEnabled();
board_->music ? JA_ResumeMusic() : JA_PauseMusic();
break;
@@ -282,7 +282,7 @@ bool Game::changeRoom(const std::string& room_path) {
if (room_tracker_->addRoom(room_path)) {
// Incrementa el contador de habitaciones visitadas
board_->rooms++;
options.stats.rooms = board_->rooms;
Options::stats.rooms = board_->rooms;
// Actualiza las estadisticas
stats_->addVisit(room_->getName());
@@ -335,18 +335,18 @@ void Game::checkIfPlayerIsAlive() {
// Comprueba si ha terminado la partida
void Game::checkGameOver() {
if (board_->lives < 0 && black_screen_counter_ > 17) {
options.section.section = Section::GAME_OVER;
Options::section.section = Options::Scene::GAME_OVER;
}
}
// Mata al jugador
void Game::killPlayer() {
if (options.cheats.invincible == Cheat::CheatState::ENABLED) {
if (Options::cheats.invincible == Options::Cheat::State::ENABLED) {
return;
}
// Resta una vida al jugador
if (options.cheats.infinite_lives == Cheat::CheatState::DISABLED) {
if (Options::cheats.infinite_lives == Options::Cheat::State::DISABLED) {
--board_->lives;
}
@@ -415,9 +415,9 @@ void Game::setScoreBoardColor() {
// Comprueba si ha finalizado el juego
bool Game::checkEndGame() {
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
const bool haveTheItems = board_->items >= int(total_items_ * 0.9f) || options.cheats.jail_is_open == Cheat::CheatState::ENABLED; // Con mas del 90% de los items recogidos
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
const bool isOnTheRoom = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
const bool haveTheItems = board_->items >= int(total_items_ * 0.9f) || Options::cheats.jail_is_open == Options::Cheat::State::ENABLED; // Con mas del 90% de los items recogidos
const bool isOnTheDoor = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
if (haveTheItems) {
board_->jail_is_open = true;
@@ -427,7 +427,7 @@ bool Game::checkEndGame() {
// Comprueba los logros de completar el juego
checkEndGameCheevos();
options.section.section = Section::ENDING;
Options::section.section = Options::Scene::ENDING;
return true;
}
@@ -569,8 +569,8 @@ void Game::checkEndGameCheevos() {
// Inicializa al jugador
void Game::initPlayer(const PlayerSpawn& spawn_point, std::shared_ptr<Room> room) {
std::string player_texture = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.gif" : "player.gif";
std::string player_animations = options.cheats.alternate_skin == Cheat::CheatState::ENABLED ? "player2.ani" : "player.ani";
std::string player_texture = Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif";
std::string player_animations = Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.ani" : "player.ani";
const PlayerData player(spawn_point, player_texture, player_animations, room);
player_ = std::make_shared<Player>(player);
}
@@ -578,10 +578,10 @@ void Game::initPlayer(const PlayerSpawn& spawn_point, std::shared_ptr<Room> room
// Crea la textura para poner el nombre de la habitación
void Game::createRoomNameTexture() {
auto text = Resource::get()->getText("smb2");
room_name_surface_ = std::make_shared<Surface>(options.game.width, text->getCharacterSize() * 2);
room_name_surface_ = std::make_shared<Surface>(Options::game.width, text->getCharacterSize() * 2);
// Establece el destino de la textura
room_name_rect_ = {0.0F, PLAY_AREA_HEIGHT, options.game.width, text->getCharacterSize() * 2.0F};
room_name_rect_ = {0.0F, PLAY_AREA_HEIGHT, Options::game.width, text->getCharacterSize() * 2.0F};
}
// Hace sonar la música
@@ -610,8 +610,8 @@ void Game::DEMO_checkRoomChange() {
demo_.counter = 0;
demo_.room_index++;
if (demo_.room_index == (int)demo_.rooms.size()) {
options.section.section = Section::LOGO;
options.section.subsection = Subsection::LOGO_TO_TITLE;
Options::section.section = Options::Scene::LOGO;
Options::section.subsection = Options::SceneOptions::LOGO_TO_TITLE;
} else {
changeRoom(demo_.rooms[demo_.room_index]);
}