forked from jaildesigner-jailgames/jaildoctors_dilemma
migrats els fitxers .room i .tmx a .yaml unificats
This commit is contained in:
@@ -1,22 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <istream> // Para istream
|
||||
#include <string> // Para string
|
||||
#include <utility> // Para pair
|
||||
#include <vector> // Para vector
|
||||
#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
|
||||
|
||||
/**
|
||||
* @brief Cargador de archivos de habitaciones
|
||||
* @brief Cargador de archivos de habitaciones en formato YAML
|
||||
*
|
||||
* Responsabilidades:
|
||||
* - Cargar archivos de room (.room)
|
||||
* - Cargar archivos de tilemap (.tmx)
|
||||
* - Parsear datos de room, enemy e item
|
||||
* - Validar y convertir valores de configuración
|
||||
* - Cargar archivos de room en formato YAML unificado (.yaml)
|
||||
* - Parsear datos de room, tilemap, enemies e items
|
||||
* - Convertir tipos de datos (tiles, posiciones, colores)
|
||||
* - Validar y propagar errores de carga
|
||||
*
|
||||
* Esta clase contiene solo métodos estáticos y no debe instanciarse.
|
||||
*/
|
||||
@@ -31,86 +29,35 @@ class RoomLoader {
|
||||
auto operator=(RoomLoader&&) -> RoomLoader& = delete;
|
||||
|
||||
/**
|
||||
* @brief Carga un archivo de room (.room)
|
||||
* @param file_path Ruta al archivo de room
|
||||
* @brief Carga un archivo de room en formato YAML
|
||||
* @param file_path Ruta al archivo YAML de habitación
|
||||
* @param verbose Si true, muestra información de debug
|
||||
* @return Room::Data con todos los datos de la habitación
|
||||
* @return Room::Data con todos los datos de la habitación incluyendo:
|
||||
* - Configuración de la habitación (nombre, colores, etc.)
|
||||
* - Tilemap completo (convertido de 2D a 1D)
|
||||
* - Lista de enemigos con todas sus propiedades
|
||||
* - Lista de items con todas sus propiedades
|
||||
*
|
||||
* Parsea un archivo .room que contiene:
|
||||
* - Variables de configuración (name, colors, borders, etc.)
|
||||
* - Bloques [enemy]...[/enemy] con datos de enemigos
|
||||
* - Bloques [item]...[/item] con datos de items
|
||||
* El formato YAML esperado incluye:
|
||||
* - room: configuración general
|
||||
* - tilemap: array 2D de 16x32 tiles (convertido a vector 1D de 512 elementos)
|
||||
* - enemies: lista de enemigos (opcional)
|
||||
* - items: lista de items (opcional)
|
||||
*/
|
||||
static auto loadRoomFile(const std::string& file_path, bool verbose = false) -> Room::Data;
|
||||
|
||||
/**
|
||||
* @brief Carga un archivo de tilemap (.tmx)
|
||||
* @param file_path Ruta al archivo de tilemap
|
||||
* @param verbose Si true, muestra información de debug
|
||||
* @return Vector de índices de tiles
|
||||
*
|
||||
* Parsea un archivo .tmx en formato CSV generado por Tiled
|
||||
*/
|
||||
static auto loadRoomTileFile(const std::string& file_path, bool verbose = false) -> std::vector<int>;
|
||||
static auto loadYAML(const std::string& file_path, bool verbose = false) -> Room::Data;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Asigna valores a una estructura Room::Data
|
||||
* @param room Estructura a modificar
|
||||
* @param key Nombre de la variable
|
||||
* @param value Valor a asignar
|
||||
* @return true si la variable fue reconocida y asignada, false si no
|
||||
* @brief Convierte room connection de YAML a formato legacy
|
||||
* @param value Valor del YAML (null o "02")
|
||||
* @return String en formato legacy ("0" para null, "02.room" para "02")
|
||||
*/
|
||||
static auto setRoom(Room::Data& room, const std::string& key, const std::string& value) -> bool;
|
||||
static auto convertRoomConnection(const std::string& value) -> std::string;
|
||||
|
||||
/**
|
||||
* @brief Asigna valores a una estructura Enemy::Data
|
||||
* @param enemy Estructura a modificar
|
||||
* @param key Nombre de la variable
|
||||
* @param value Valor a asignar
|
||||
* @return true si la variable fue reconocida y asignada, false si no
|
||||
* @brief Convierte un tilemap 2D a vector 1D flat
|
||||
* @param tilemap_2d Array 2D de tiles (16 rows × 32 cols)
|
||||
* @return Vector 1D flat con 512 elementos
|
||||
*/
|
||||
static auto setEnemy(Enemy::Data& enemy, const std::string& key, const std::string& value) -> bool;
|
||||
|
||||
/**
|
||||
* @brief Asigna valores a una estructura Item::Data
|
||||
* @param item Estructura a modificar
|
||||
* @param key Nombre de la variable
|
||||
* @param value Valor a asignar
|
||||
* @return true si la variable fue reconocida y asignada, false si no
|
||||
*/
|
||||
static auto setItem(Item::Data& item, const std::string& key, const std::string& value) -> bool;
|
||||
|
||||
/**
|
||||
* @brief Parsea una línea en formato "key=value"
|
||||
* @param line Línea a parsear
|
||||
* @return Par {key, value}. Si no hay '=', devuelve {"", ""}
|
||||
*/
|
||||
static auto parseKeyValue(const std::string& line) -> std::pair<std::string, std::string>;
|
||||
|
||||
/**
|
||||
* @brief Registra un parámetro desconocido en la consola
|
||||
* @param file_name Nombre del archivo siendo parseado
|
||||
* @param key Nombre del parámetro desconocido
|
||||
* @param verbose Si true, muestra el mensaje
|
||||
*/
|
||||
static void logUnknownParameter(const std::string& file_name, const std::string& key, bool verbose);
|
||||
|
||||
/**
|
||||
* @brief Carga un bloque [enemy]...[/enemy] desde un stream
|
||||
* @param file Stream del archivo
|
||||
* @param file_name Nombre del archivo (para debug)
|
||||
* @param verbose Si true, muestra información de debug
|
||||
* @return Enemy::Data con los datos del enemigo
|
||||
*/
|
||||
static auto loadEnemyFromFile(std::istream& file, const std::string& file_name, bool verbose) -> Enemy::Data;
|
||||
|
||||
/**
|
||||
* @brief Carga un bloque [item]...[/item] desde un stream
|
||||
* @param file Stream del archivo
|
||||
* @param file_name Nombre del archivo (para debug)
|
||||
* @param verbose Si true, muestra información de debug
|
||||
* @return Item::Data con los datos del item
|
||||
*/
|
||||
static auto loadItemFromFile(std::istream& file, const std::string& file_name, bool verbose) -> Item::Data;
|
||||
static auto flattenTilemap(const std::vector<std::vector<int>>& tilemap_2d) -> std::vector<int>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user