format de fitxers room
This commit is contained in:
@@ -8,15 +8,31 @@
|
||||
#include "utils/defines.hpp" // Para TILE_SIZE
|
||||
#include "utils/utils.hpp" // Para stringToColor
|
||||
|
||||
// Convierte room connection de YAML a formato con extensión
|
||||
// Convierte room connection de YAML a formato interno
|
||||
auto RoomLoader::convertRoomConnection(const std::string& value) -> std::string {
|
||||
if (value == "null" || value.empty()) {
|
||||
return "0";
|
||||
}
|
||||
// "02" → "02.yaml"
|
||||
// Si ya tiene .yaml, devolverlo tal cual; si no, añadirlo
|
||||
if (value.size() > 5 && value.substr(value.size() - 5) == ".yaml") {
|
||||
return value;
|
||||
}
|
||||
return value + ".yaml";
|
||||
}
|
||||
|
||||
// Convierte string de autoSurface a int
|
||||
auto RoomLoader::convertAutoSurface(const fkyaml::node& node) -> int {
|
||||
if (node.is_integer()) {
|
||||
return node.get_value<int>();
|
||||
}
|
||||
if (node.is_string()) {
|
||||
const std::string value = node.get_value<std::string>();
|
||||
if (value == "left") return -1;
|
||||
if (value == "right") return 1;
|
||||
}
|
||||
return 0; // "none" o default
|
||||
}
|
||||
|
||||
// Convierte un tilemap 2D a vector 1D flat
|
||||
auto RoomLoader::flattenTilemap(const std::vector<std::vector<int>>& tilemap_2d) -> std::vector<int> {
|
||||
std::vector<int> tilemap_flat;
|
||||
@@ -114,9 +130,9 @@ auto RoomLoader::loadYAML(const std::string& file_path, bool verbose) -> Room::D
|
||||
room.item_color2 = "magenta";
|
||||
}
|
||||
|
||||
// Conveyor belt direction
|
||||
// Conveyor belt direction (puede ser int o string "left"/"none"/"right")
|
||||
if (room_node.contains("autoSurface")) {
|
||||
room.conveyor_belt_direction = room_node["autoSurface"].get_value_or<int>(0);
|
||||
room.conveyor_belt_direction = convertAutoSurface(room_node["autoSurface"]);
|
||||
} else {
|
||||
room.conveyor_belt_direction = 0;
|
||||
}
|
||||
@@ -186,8 +202,31 @@ auto RoomLoader::loadYAML(const std::string& file_path, bool verbose) -> Room::D
|
||||
}
|
||||
|
||||
// Boundaries (in tiles, convert to pixels)
|
||||
// Soporta formato nuevo (position1/position2) y antiguo (x1/y1/x2/y2)
|
||||
if (enemy_node.contains("boundaries")) {
|
||||
const auto& bounds = enemy_node["boundaries"];
|
||||
|
||||
// Nuevo formato: position1 y position2
|
||||
if (bounds.contains("position1")) {
|
||||
const auto& pos1 = bounds["position1"];
|
||||
if (pos1.contains("x")) {
|
||||
enemy.x1 = pos1["x"].get_value<int>() * TILE_SIZE;
|
||||
}
|
||||
if (pos1.contains("y")) {
|
||||
enemy.y1 = pos1["y"].get_value<int>() * TILE_SIZE;
|
||||
}
|
||||
}
|
||||
if (bounds.contains("position2")) {
|
||||
const auto& pos2 = bounds["position2"];
|
||||
if (pos2.contains("x")) {
|
||||
enemy.x2 = pos2["x"].get_value<int>() * TILE_SIZE;
|
||||
}
|
||||
if (pos2.contains("y")) {
|
||||
enemy.y2 = pos2["y"].get_value<int>() * TILE_SIZE;
|
||||
}
|
||||
}
|
||||
|
||||
// Formato antiguo: x1/y1/x2/y2 (compatibilidad)
|
||||
if (bounds.contains("x1")) {
|
||||
enemy.x1 = bounds["x1"].get_value<int>() * TILE_SIZE;
|
||||
}
|
||||
|
||||
@@ -3,9 +3,10 @@
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "game/entities/enemy.hpp" // Para Enemy::Data
|
||||
#include "game/entities/item.hpp" // Para Item::Data
|
||||
#include "game/gameplay/room.hpp" // Para Room::Data
|
||||
#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/gameplay/room.hpp" // Para Room::Data
|
||||
|
||||
/**
|
||||
* @brief Cargador de archivos de habitaciones en formato YAML
|
||||
@@ -48,12 +49,19 @@ class RoomLoader {
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Convierte room connection de YAML a formato con extensión
|
||||
* @param value Valor del YAML (null o "02")
|
||||
* @return String con extensión YAML ("0" para null, "02.yaml" para "02")
|
||||
* @brief Convierte room connection de YAML a formato interno
|
||||
* @param value Valor del YAML (vacío, "02" o "02.yaml")
|
||||
* @return "0" para sin conexión, o nombre del archivo con extensión
|
||||
*/
|
||||
static auto convertRoomConnection(const std::string& value) -> std::string;
|
||||
|
||||
/**
|
||||
* @brief Convierte autoSurface de YAML a int
|
||||
* @param node Nodo YAML (puede ser int o string "left"/"none"/"right")
|
||||
* @return -1 para left, 0 para none, 1 para right
|
||||
*/
|
||||
static auto convertAutoSurface(const fkyaml::node& node) -> int;
|
||||
|
||||
/**
|
||||
* @brief Convierte un tilemap 2D a vector 1D flat
|
||||
* @param tilemap_2d Array 2D de tiles (16 rows × 32 cols)
|
||||
|
||||
Reference in New Issue
Block a user