diff --git a/data/room/01.yaml b/data/room/01.yaml index 25fcda7..2088d06 100644 --- a/data/room/01.yaml +++ b/data/room/01.yaml @@ -1,4 +1,5 @@ room: + zone: neighborhood tileSetFile: standard.gif # Conexiones de la habitación (null = sin conexión) diff --git a/data/room/02.yaml b/data/room/02.yaml index e176951..986a729 100644 --- a/data/room/02.yaml +++ b/data/room/02.yaml @@ -1,4 +1,5 @@ room: + zone: neighborhood tileSetFile: standard.gif # Conexiones de la habitación (null = sin conexión) diff --git a/data/room/03.yaml b/data/room/03.yaml index 4ca855e..7e43c58 100644 --- a/data/room/03.yaml +++ b/data/room/03.yaml @@ -1,4 +1,5 @@ room: + zone: neighborhood tileSetFile: standard.gif # Conexiones de la habitación (null = sin conexión) diff --git a/data/room/04.yaml b/data/room/04.yaml index a3a2cda..71501a6 100644 --- a/data/room/04.yaml +++ b/data/room/04.yaml @@ -1,4 +1,5 @@ room: + zone: neighborhood tileSetFile: standard.gif # Conexiones de la habitación (null = sin conexión) diff --git a/data/room/05.yaml b/data/room/05.yaml index 80d8cca..cd9829f 100644 --- a/data/room/05.yaml +++ b/data/room/05.yaml @@ -1,4 +1,5 @@ room: + zone: neighborhood tileSetFile: standard.gif # Conexiones de la habitación (null = sin conexión) diff --git a/source/core/system/director.cpp b/source/core/system/director.cpp index c4c4095..5d0e369 100644 --- a/source/core/system/director.cpp +++ b/source/core/system/director.cpp @@ -22,6 +22,7 @@ #include "core/resources/resource_loader.hpp" // Para ResourceLoader #include "core/system/event_buffer.hpp" // Para EventBuffer #include "game/gameplay/cheevos.hpp" // Para Cheevos +#include "game/gameplay/zone_manager.hpp" // Para ZoneManager #include "game/options.hpp" // Para Options, options, OptionsVideo #include "game/scene_manager.hpp" // Para SceneManager #include "game/scenes/game.hpp" // Para Game, GameMode @@ -163,6 +164,12 @@ Director::Director() { Debug::get()->loadFromFile(); #endif + // ZoneManager debe inicializarse antes que Resource::Cache: el cache carga + // las rooms en eager loading, y RoomLoader necesita consultar las zonas para + // resolver tileSetFile/music. ZoneManager carga su yaml directamente del + // filesystem (vía Resource::Helper::loadFile) así que no depende del cache. + ZoneManager::init(); + // Initialize resources (works for both release and development) #ifdef _DEBUG Resource::Cache::init(Debug::get()->getLazyLoading() @@ -238,6 +245,7 @@ Director::~Director() { RenderInfo::destroy(); Notifier::destroy(); Resource::Cache::destroy(); + ZoneManager::destroy(); Resource::Helper::shutdownResourceSystem(); // Shutdown resource pack system Audio::destroy(); Screen::destroy(); diff --git a/source/game/editor/map_editor.cpp b/source/game/editor/map_editor.cpp index aa95ff9..46afc84 100644 --- a/source/game/editor/map_editor.cpp +++ b/source/game/editor/map_editor.cpp @@ -1214,7 +1214,7 @@ void MapEditor::updateStatusBarInfo() { // NOLINT(readability-function-cognitiv conv = "right"; } - line2 = "conv:" + conv; + line2 = "zone:" + room_data_.zone + " conv:" + conv; line3 = "u:" + conn(room_data_.upper_room) + " d:" + conn(room_data_.lower_room) + " l:" + conn(room_data_.left_room) + " r:" + conn(room_data_.right_room) + " itm:" + std::to_string(room_data_.item_color1) + "/" + std::to_string(room_data_.item_color2); diff --git a/source/game/gameplay/room.cpp b/source/game/gameplay/room.cpp index 86d0aae..a6c2742 100644 --- a/source/game/gameplay/room.cpp +++ b/source/game/gameplay/room.cpp @@ -61,7 +61,9 @@ void Room::initializeRoom(const Data& room) { lower_room_ = room.lower_room; left_room_ = room.left_room; right_room_ = room.right_room; + zone_ = room.zone; tile_set_file_ = room.tile_set_file; + music_ = room.music; conveyor_belt_direction_ = room.conveyor_belt_direction; tile_map_ = room.tile_map; // Tilemap viene embebido en el YAML surface_ = Resource::Cache::get()->getSurface(room.tile_set_file); diff --git a/source/game/gameplay/room.hpp b/source/game/gameplay/room.hpp index a31b30b..06329ae 100644 --- a/source/game/gameplay/room.hpp +++ b/source/game/gameplay/room.hpp @@ -44,7 +44,11 @@ class Room { std::string lower_room; std::string left_room; std::string right_room; - std::string tile_set_file; + std::string zone; // Nombre de la zona a la que pertenece + std::string tile_set_file; // Resuelto: zona o override del yaml + std::string music; // Resuelto: zona o override del yaml + bool tile_set_overridden{false}; // True si el yaml tenía tileSetFile explícito + bool music_overridden{false}; // True si el yaml tenía music explícito int conveyor_belt_direction{0}; std::vector tile_map; std::vector collision_tile_map; @@ -62,6 +66,9 @@ class Room { // --- Funciones --- [[nodiscard]] auto getNumber() const -> const std::string& { return number_; } [[nodiscard]] auto getBGColor() const -> Uint8 { return bg_color_; } + [[nodiscard]] auto getZone() const -> const std::string& { return zone_; } + [[nodiscard]] auto getMusic() const -> const std::string& { return music_; } + [[nodiscard]] auto getTileSetFile() const -> const std::string& { return tile_set_file_; } void renderMap(); void renderEnemies(); void renderPlatforms(); @@ -83,7 +90,6 @@ class Room { void setConnection(Border border, const std::string& room_name); void setTileSet(const std::string& tile_set_file); void setConveyorBeltDirection(int direction); - [[nodiscard]] auto getTileSetFile() const -> const std::string& { return tile_set_file_; } [[nodiscard]] auto getTileSetWidth() const -> int { return tile_set_width_; } #endif void update(float delta_time); @@ -125,7 +131,9 @@ class Room { std::string lower_room_; std::string left_room_; std::string right_room_; + std::string zone_; std::string tile_set_file_; + std::string music_; std::vector tile_map_; int conveyor_belt_direction_{0}; bool is_paused_{false}; diff --git a/source/game/gameplay/room_loader.cpp b/source/game/gameplay/room_loader.cpp index 65186c1..0e616c2 100644 --- a/source/game/gameplay/room_loader.cpp +++ b/source/game/gameplay/room_loader.cpp @@ -5,6 +5,8 @@ #include "core/resources/resource_helper.hpp" // Para Resource::Helper #include "external/fkyaml_node.hpp" // Para fkyaml::node +#include "game/gameplay/zone.hpp" // Para Zone::Data +#include "game/gameplay/zone_manager.hpp" // Para ZoneManager #include "utils/defines.hpp" // Para Tile::SIZE #include "utils/utils.hpp" @@ -71,8 +73,40 @@ void RoomLoader::parseRoomConfig(const fkyaml::node& yaml, Room::Data& room, con // Basic properties // bgColor ya no se lee del YAML; bg_color queda siempre a 0 + + // --- Resolución de zona + overrides (tileSetFile, music) --- + // Obtener zona declarada (o caer al default si no existe) + std::string zone_name; + if (room_node.contains("zone")) { + zone_name = room_node["zone"].get_value(); + } else { + std::cerr << "Warning: room " << file_name << " has no 'zone' field, using default\n"; + const Zone::Data* default_zone = ZoneManager::get()->getDefaultZone(); + if (default_zone != nullptr) { zone_name = default_zone->name; } + } + room.zone = zone_name; + + // Localizar la zona en el catálogo (fallback al default si no existe) + const Zone::Data* zone = ZoneManager::get()->getZone(zone_name); + if (zone == nullptr) { + std::cerr << "Warning: unknown zone '" << zone_name << "' in " << file_name << ", using default\n"; + zone = ZoneManager::get()->getDefaultZone(); + } + + // tileSetFile: zona, override si está en el yaml if (room_node.contains("tileSetFile")) { room.tile_set_file = room_node["tileSetFile"].get_value(); + room.tile_set_overridden = true; + } else if (zone != nullptr) { + room.tile_set_file = zone->tile_set_file; + } + + // music: zona, override si está en el yaml + if (room_node.contains("music")) { + room.music = room_node["music"].get_value(); + room.music_overridden = true; + } else if (zone != nullptr) { + room.music = zone->music; } // Room connections diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index c75c7e0..49d71c8 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -25,7 +25,6 @@ #include "game/gameplay/item_tracker.hpp" // Para ItemTracker #include "game/gameplay/key_tracker.hpp" // Para KeyTracker #include "game/gameplay/room.hpp" // Para Room, RoomData -#include "game/gameplay/zone_manager.hpp" // Para ZoneManager #include "game/gameplay/room_tracker.hpp" // Para RoomTracker #include "game/gameplay/scoreboard.hpp" // Para Scoreboard::Data, Scoreboard #include "game/options.hpp" // Para Options, options, Cheat, SectionState @@ -69,7 +68,7 @@ Game::Game(Mode mode) #endif // Crea objetos e inicializa variables - ZoneManager::init(); + // ZoneManager se inicializa en Director (antes que Resource::Cache, que carga rooms) ItemTracker::init(); KeyTracker::init(); DoorTracker::init(); @@ -175,7 +174,7 @@ Game::~Game() { KeyTracker::destroy(); DoorTracker::destroy(); Inventory::destroy(); - ZoneManager::destroy(); + // ZoneManager lo destruye Director if (Console::get() != nullptr) { Console::get()->on_toggle = nullptr; }