diff --git a/data/room/03.yaml b/data/room/03.yaml index a150d9f..dfbd896 100644 --- a/data/room/03.yaml +++ b/data/room/03.yaml @@ -1,568 +1,58 @@ -enemies: - - - animation: code.yaml - boundaries: - position1: - x: 3 - y: 2 - position2: - x: 20 - y: 2 - color: yellow - position: - x: 8 - y: 2 - velocity: - x: 24.0 - y: 0 -items: - - - counter: 1 - position: - x: 21 - y: 13 - tile: 42 - tileSetFile: items.gif +# VOID MAIN room: + name_en: "VOID MAIN" + name_ca: "VOID MAIN" bgColor: black border: magenta + tileSetFile: standard.gif + + # Conexiones de la habitación (null = sin conexión) connections: + up: null down: null left: 02.yaml right: null - up: null - conveyorBelt: left + + # Colores de los objetos itemColor1: bright_cyan itemColor2: yellow - name_ca: VOID MAIN - name_en: VOID MAIN - tileSetFile: standard.gif + + # Dirección de la cinta transportadora: left, none, right + conveyorBelt: left + +# Tilemap: 16 filas × 32 columnas (256×192 píxeles @ 8px/tile) +# Índices de tiles (-1 = vacío) tilemap: - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - -1 - - -1 - - 504 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - -1 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - -1 - - -1 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - -1 - - -1 - - -1 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 504 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - 24 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - 24 - - 24 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - 252 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 24 - - 24 - - - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 134 - - 24 - - - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 440 - - 440 - - 440 - - 440 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - -1 - - 134 - - 24 - - - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 - - 24 + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24] + - [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24] + - [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, 252, -1, -1, 504, 24, 24, 24, 24, 24, 24, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, 24, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, 24, -1, -1, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 504, -1, -1, -1, -1, -1, -1, -1, 24, 24, 24, -1, -1, -1, 24, 24] + - [24, 24, -1, -1, -1, -1, -1, -1, -1, 252, 252, 252, 252, 252, 252, 252, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 24, 24] + - [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 134, 24] + - [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 440, 440, 440, 440, -1, -1, -1, -1, -1, -1, -1, -1, 134, 24] + - [24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24] + +# Enemigos en esta habitación +enemies: + - animation: code.yaml + position: {x: 3, y: 2} + velocity: {x: 24.0, y: 0} + boundaries: + position1: {x: 3, y: 2} + position2: {x: 27, y: 2} + color: yellow + +# Objetos en esta habitación +items: + - tileSetFile: items.gif + tile: 42 + position: {x: 21, y: 13} + counter: 1 diff --git a/source/game/editor/map_editor.cpp b/source/game/editor/map_editor.cpp index 8fdc06c..ef7cf51 100644 --- a/source/game/editor/map_editor.cpp +++ b/source/game/editor/map_editor.cpp @@ -109,15 +109,13 @@ auto MapEditor::revert() -> std::string { if (!active_) { return "Editor not active"; } if (file_path_.empty()) { return "Error: No file path"; } - // Restaurar el YAML al backup original + // Restaurar el YAML original y reescribir el fichero yaml_ = yaml_backup_; - RoomSaver::saveYAML(file_path_, yaml_); - - // Recargar room_data_ desde el backup auto room_data_ptr = Resource::Cache::get()->getRoom(room_path_); if (room_data_ptr) { room_data_ = *room_data_ptr; } + RoomSaver::saveYAML(file_path_, yaml_, room_data_); // Resetear los sprites vivos a las posiciones originales room_->resetEnemyPositions(room_data_.enemies); @@ -131,10 +129,19 @@ auto MapEditor::revert() -> std::string { return "Reverted to original"; } -// Auto-guarda los cambios puntuales al YAML tras soltar una entidad +// Auto-guarda al YAML tras soltar una entidad void MapEditor::autosave() { if (file_path_.empty()) { return; } - RoomSaver::saveYAML(file_path_, yaml_); + + // Sincronizar posiciones de items desde los sprites vivos a room_data_ + auto* item_mgr = room_->getItemManager(); + for (int i = 0; i < item_mgr->getCount() && i < static_cast(room_data_.items.size()); ++i) { + SDL_FPoint pos = item_mgr->getItem(i)->getPos(); + room_data_.items[i].x = pos.x; + room_data_.items[i].y = pos.y; + } + + RoomSaver::saveYAML(file_path_, yaml_, room_data_); } // Actualiza el editor @@ -298,7 +305,6 @@ void MapEditor::handleMouseUp() { room_data_.enemies[IDX].x = drag_.snap_x; room_data_.enemies[IDX].y = drag_.snap_y; room_->getEnemyManager()->getEnemy(IDX)->resetToInitialPosition(room_data_.enemies[IDX]); - RoomSaver::updateEnemyPosition(yaml_, IDX, drag_.snap_x, drag_.snap_y); changed = true; } break; @@ -307,7 +313,6 @@ void MapEditor::handleMouseUp() { if (IDX >= 0 && IDX < static_cast(room_data_.enemies.size())) { room_data_.enemies[IDX].x1 = SNAP_X; room_data_.enemies[IDX].y1 = SNAP_Y; - RoomSaver::updateEnemyBound1(yaml_, IDX, SNAP_X, SNAP_Y); changed = true; } break; @@ -316,7 +321,6 @@ void MapEditor::handleMouseUp() { if (IDX >= 0 && IDX < static_cast(room_data_.enemies.size())) { room_data_.enemies[IDX].x2 = SNAP_X; room_data_.enemies[IDX].y2 = SNAP_Y; - RoomSaver::updateEnemyBound2(yaml_, IDX, SNAP_X, SNAP_Y); changed = true; } break; @@ -324,7 +328,6 @@ void MapEditor::handleMouseUp() { case DragTarget::ITEM: if (IDX >= 0 && IDX < room_->getItemManager()->getCount()) { room_->getItemManager()->getItem(IDX)->setPosition(drag_.snap_x, drag_.snap_y); - RoomSaver::updateItemPosition(yaml_, IDX, drag_.snap_x, drag_.snap_y); changed = true; } break; diff --git a/source/game/editor/room_saver.cpp b/source/game/editor/room_saver.cpp index 9b0eae8..f67664f 100644 --- a/source/game/editor/room_saver.cpp +++ b/source/game/editor/room_saver.cpp @@ -5,6 +5,7 @@ #include // Para std::round #include // Para ifstream, ofstream, istreambuf_iterator #include // Para cout, cerr +#include // Para ostringstream #include "utils/defines.hpp" // Para Tile::SIZE @@ -21,9 +22,144 @@ auto RoomSaver::loadYAML(const std::string& file_path) -> fkyaml::node { return fkyaml::node::deserialize(content); } -// Guarda el nodo YAML completo a disco -auto RoomSaver::saveYAML(const std::string& file_path, const fkyaml::node& yaml) -> std::string { - std::string content = fkyaml::node::serialize(yaml); +// Convierte una room connection al formato YAML +auto RoomSaver::roomConnectionToYAML(const std::string& connection) -> std::string { + if (connection == "0" || connection.empty()) { return "null"; } + return connection; +} + +// Convierte la dirección del conveyor belt a string +auto RoomSaver::conveyorBeltToString(int direction) -> std::string { + if (direction < 0) { return "left"; } + if (direction > 0) { return "right"; } + return "none"; +} + +// Genera el YAML completo como texto con formato compacto +auto RoomSaver::buildYAML(const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string { + std::ostringstream out; + + // --- Cabecera: nombre como comentario --- + out << "# " << room_data.name << "\n"; + + // --- Sección room --- + out << "room:\n"; + + // Escribir todos los campos name_* del YAML original (preserva name_ca, name_en, etc.) + if (original_yaml.contains("room")) { + const auto& room_node = original_yaml["room"]; + for (auto it = room_node.begin(); it != room_node.end(); ++it) { + const std::string key = it.key().get_value(); + if (key.substr(0, 5) == "name_") { + out << " " << key << ": \"" << it.value().get_value() << "\"\n"; + } + } + } + + out << " bgColor: " << room_data.bg_color << "\n"; + out << " border: " << room_data.border_color << "\n"; + out << " tileSetFile: " << room_data.tile_set_file << "\n"; + + // Conexiones + out << "\n"; + out << " # Conexiones de la habitación (null = sin conexión)\n"; + out << " connections:\n"; + out << " up: " << roomConnectionToYAML(room_data.upper_room) << "\n"; + out << " down: " << roomConnectionToYAML(room_data.lower_room) << "\n"; + out << " left: " << roomConnectionToYAML(room_data.left_room) << "\n"; + out << " right: " << roomConnectionToYAML(room_data.right_room) << "\n"; + + // Colores de items + out << "\n"; + out << " # Colores de los objetos\n"; + out << " itemColor1: " << (room_data.item_color1.empty() ? "yellow" : room_data.item_color1) << "\n"; + out << " itemColor2: " << (room_data.item_color2.empty() ? "magenta" : room_data.item_color2) << "\n"; + + // Conveyor belt + out << "\n"; + out << " # Dirección de la cinta transportadora: left, none, right\n"; + out << " conveyorBelt: " << conveyorBeltToString(room_data.conveyor_belt_direction) << "\n"; + + // --- Tilemap (16 filas × 32 columnas, formato flow) --- + out << "\n"; + out << "# Tilemap: 16 filas × 32 columnas (256×192 píxeles @ 8px/tile)\n"; + out << "# Índices de tiles (-1 = vacío)\n"; + out << "tilemap:\n"; + constexpr int MAP_WIDTH = 32; + constexpr int MAP_HEIGHT = 16; + for (int row = 0; row < MAP_HEIGHT; ++row) { + out << " - ["; + for (int col = 0; col < MAP_WIDTH; ++col) { + int index = row * MAP_WIDTH + col; + if (index < static_cast(room_data.tile_map.size())) { + out << room_data.tile_map[index]; + } else { + out << -1; + } + if (col < MAP_WIDTH - 1) { out << ", "; } + } + out << "]\n"; + } + + // --- Enemigos --- + if (!room_data.enemies.empty()) { + out << "\n"; + out << "# Enemigos en esta habitación\n"; + out << "enemies:\n"; + for (const auto& enemy : room_data.enemies) { + out << " - animation: " << enemy.animation_path << "\n"; + + int pos_x = static_cast(std::round(enemy.x / Tile::SIZE)); + int pos_y = static_cast(std::round(enemy.y / Tile::SIZE)); + out << " position: {x: " << pos_x << ", y: " << pos_y << "}\n"; + + out << " velocity: {x: " << enemy.vx << ", y: " << enemy.vy << "}\n"; + + int b1_x = enemy.x1 / Tile::SIZE; + int b1_y = enemy.y1 / Tile::SIZE; + int b2_x = enemy.x2 / Tile::SIZE; + int b2_y = enemy.y2 / Tile::SIZE; + out << " boundaries:\n"; + out << " position1: {x: " << b1_x << ", y: " << b1_y << "}\n"; + out << " position2: {x: " << b2_x << ", y: " << b2_y << "}\n"; + + if (!enemy.color.empty() && enemy.color != "white") { + out << " color: " << enemy.color << "\n"; + } + if (enemy.flip) { out << " flip: true\n"; } + if (enemy.mirror) { out << " mirror: true\n"; } + if (enemy.frame != -1) { out << " frame: " << enemy.frame << "\n"; } + + out << "\n"; + } + } + + // --- Items --- + if (!room_data.items.empty()) { + out << "# Objetos en esta habitación\n"; + out << "items:\n"; + for (const auto& item : room_data.items) { + out << " - tileSetFile: " << item.tile_set_file << "\n"; + out << " tile: " << item.tile << "\n"; + + int item_x = static_cast(std::round(item.x / Tile::SIZE)); + int item_y = static_cast(std::round(item.y / Tile::SIZE)); + out << " position: {x: " << item_x << ", y: " << item_y << "}\n"; + + if (item.counter != 0) { + out << " counter: " << item.counter << "\n"; + } + + out << "\n"; + } + } + + return out.str(); +} + +// Guarda el YAML a disco +auto RoomSaver::saveYAML(const std::string& file_path, const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string { + std::string content = buildYAML(original_yaml, room_data); std::ofstream file(file_path); if (!file.is_open()) { @@ -39,80 +175,4 @@ auto RoomSaver::saveYAML(const std::string& file_path, const fkyaml::node& yaml) return "Saved " + FILE_NAME; } -// Actualiza la posición inicial de un enemigo (pixels → tiles) -void RoomSaver::updateEnemyPosition(fkyaml::node& yaml, int index, float x, float y) { - if (!yaml.contains("enemies")) { return; } - auto& enemies = yaml["enemies"]; - if (index < 0 || index >= static_cast(enemies.size())) { return; } - - auto& enemy = enemies[index]; - int tile_x = static_cast(std::round(x / Tile::SIZE)); - int tile_y = static_cast(std::round(y / Tile::SIZE)); - - if (!enemy.contains("position")) { - enemy["position"] = fkyaml::node::mapping(); - } - enemy["position"]["x"] = tile_x; - enemy["position"]["y"] = tile_y; -} - -// Actualiza boundary1 de un enemigo (pixels → tiles) -void RoomSaver::updateEnemyBound1(fkyaml::node& yaml, int index, int x, int y) { - if (!yaml.contains("enemies")) { return; } - auto& enemies = yaml["enemies"]; - if (index < 0 || index >= static_cast(enemies.size())) { return; } - - auto& enemy = enemies[index]; - int tile_x = x / Tile::SIZE; - int tile_y = y / Tile::SIZE; - - if (!enemy.contains("boundaries")) { - enemy["boundaries"] = fkyaml::node::mapping(); - } - auto& bounds = enemy["boundaries"]; - if (!bounds.contains("position1")) { - bounds["position1"] = fkyaml::node::mapping(); - } - bounds["position1"]["x"] = tile_x; - bounds["position1"]["y"] = tile_y; -} - -// Actualiza boundary2 de un enemigo (pixels → tiles) -void RoomSaver::updateEnemyBound2(fkyaml::node& yaml, int index, int x, int y) { - if (!yaml.contains("enemies")) { return; } - auto& enemies = yaml["enemies"]; - if (index < 0 || index >= static_cast(enemies.size())) { return; } - - auto& enemy = enemies[index]; - int tile_x = x / Tile::SIZE; - int tile_y = y / Tile::SIZE; - - if (!enemy.contains("boundaries")) { - enemy["boundaries"] = fkyaml::node::mapping(); - } - auto& bounds = enemy["boundaries"]; - if (!bounds.contains("position2")) { - bounds["position2"] = fkyaml::node::mapping(); - } - bounds["position2"]["x"] = tile_x; - bounds["position2"]["y"] = tile_y; -} - -// Actualiza la posición de un item (pixels → tiles) -void RoomSaver::updateItemPosition(fkyaml::node& yaml, int index, float x, float y) { - if (!yaml.contains("items")) { return; } - auto& items = yaml["items"]; - if (index < 0 || index >= static_cast(items.size())) { return; } - - auto& item = items[index]; - int tile_x = static_cast(std::round(x / Tile::SIZE)); - int tile_y = static_cast(std::round(y / Tile::SIZE)); - - if (!item.contains("position")) { - item["position"] = fkyaml::node::mapping(); - } - item["position"]["x"] = tile_x; - item["position"]["y"] = tile_y; -} - #endif // _DEBUG diff --git a/source/game/editor/room_saver.hpp b/source/game/editor/room_saver.hpp index f76cb2e..0e6dbb7 100644 --- a/source/game/editor/room_saver.hpp +++ b/source/game/editor/room_saver.hpp @@ -5,32 +5,31 @@ #include // Para string #include "external/fkyaml_node.hpp" // Para fkyaml::node -#include "game/entities/enemy.hpp" // Para Enemy::Data -#include "game/entities/item.hpp" // Para Item::Data -#include "game/entities/player.hpp" // Para Player::SpawnData +#include "game/gameplay/room.hpp" // Para Room::Data /** - * @brief Edición parcial de archivos YAML de habitaciones + * @brief Guardado de archivos YAML de habitaciones para el editor de mapas * - * Lee el YAML original, modifica solo los campos editados y serializa. - * Preserva todos los campos que no se editan (name_ca, comentarios del formato, etc.) - * Solo se usa en builds de debug (editor de mapas). + * Lee el YAML original con fkyaml (para acceder a todos los campos: name_ca, name_en, etc.) + * Genera el YAML como texto formateado compacto (idéntico al formato original de los ficheros). + * Solo se usa en builds de debug. */ class RoomSaver { public: RoomSaver() = delete; - // Carga el YAML original desde disco (llamar al entrar al editor) + // Carga el YAML original desde disco como nodo fkyaml (lee del filesystem, no del pack) static auto loadYAML(const std::string& file_path) -> fkyaml::node; - // Guarda el nodo YAML completo a disco - static auto saveYAML(const std::string& file_path, const fkyaml::node& yaml) -> std::string; + // Genera y guarda el YAML completo a disco + // original_yaml: nodo fkyaml con los datos originales (para campos que no se editan: name_ca, etc.) + // room_data: datos editados (posiciones de enemigos, items, etc.) + static auto saveYAML(const std::string& file_path, const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string; - // Modificaciones puntuales sobre el nodo YAML (posiciones en pixels, se convierten a tiles) - static void updateEnemyPosition(fkyaml::node& yaml, int index, float x, float y); - static void updateEnemyBound1(fkyaml::node& yaml, int index, int x, int y); - static void updateEnemyBound2(fkyaml::node& yaml, int index, int x, int y); - static void updateItemPosition(fkyaml::node& yaml, int index, float x, float y); + private: + static auto buildYAML(const fkyaml::node& original_yaml, const Room::Data& room_data) -> std::string; + static auto roomConnectionToYAML(const std::string& connection) -> std::string; + static auto conveyorBeltToString(int direction) -> std::string; }; #endif // _DEBUG