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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user