forked from jaildesigner-jailgames/jaildoctors_dilemma
migrant .ani a .yaml
This commit is contained in:
@@ -148,12 +148,12 @@ auto Cache::getText(const std::string& name) -> std::shared_ptr<Text> {
|
||||
throw std::runtime_error("Texto no encontrado: " + name);
|
||||
}
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
auto Cache::getAnimations(const std::string& name) -> SurfaceAnimatedSprite::Animations& {
|
||||
// Obtiene los datos de animación parseados a partir de un nombre
|
||||
auto Cache::getAnimationData(const std::string& name) -> const ResourceAnimation& {
|
||||
auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; });
|
||||
|
||||
if (it != animations_.end()) {
|
||||
return it->animation;
|
||||
return *it;
|
||||
}
|
||||
|
||||
std::cerr << "Error: Animación no encontrada " << name << '\n';
|
||||
@@ -300,7 +300,14 @@ void Cache::loadAnimations() {
|
||||
|
||||
for (const auto& l : list) {
|
||||
auto name = getFileName(l);
|
||||
animations_.emplace_back(name, SurfaceAnimatedSprite::loadAnimationsFromFile(l));
|
||||
|
||||
// Parsear YAML y almacenar datos pre-cargados
|
||||
std::shared_ptr<Surface> surface;
|
||||
float frame_width = 0.0F;
|
||||
float frame_height = 0.0F;
|
||||
auto animation_data = SurfaceAnimatedSprite::loadAnimationsFromYAML(l, surface, frame_width, frame_height);
|
||||
|
||||
animations_.emplace_back(name, animation_data, surface, frame_width, frame_height);
|
||||
updateLoadingProgress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,13 +80,19 @@ struct ResourceText {
|
||||
|
||||
// Estructura para almacenar ficheros animaciones y su nombre
|
||||
struct ResourceAnimation {
|
||||
std::string name; // Nombre del fichero
|
||||
SurfaceAnimatedSprite::Animations animation; // Objeto con las animaciones
|
||||
std::string name; // Nombre del fichero
|
||||
std::vector<SurfaceAnimatedSprite::AnimationData> animations; // Datos de animaciones parseadas desde YAML
|
||||
std::shared_ptr<Surface> surface; // Surface asociada al sprite sheet
|
||||
float frame_width{0.0F}; // Ancho de cada frame
|
||||
float frame_height{0.0F}; // Alto de cada frame
|
||||
|
||||
// Constructor
|
||||
ResourceAnimation(std::string name, SurfaceAnimatedSprite::Animations animation)
|
||||
ResourceAnimation(std::string name, std::vector<SurfaceAnimatedSprite::AnimationData> animations, std::shared_ptr<Surface> surface, float frame_width, float frame_height)
|
||||
: name(std::move(name)),
|
||||
animation(std::move(animation)) {}
|
||||
animations(std::move(animations)),
|
||||
surface(std::move(surface)),
|
||||
frame_width(frame_width),
|
||||
frame_height(frame_height) {}
|
||||
};
|
||||
|
||||
// Estructura para almacenar ficheros con el mapa de tiles de una habitación y su nombre
|
||||
@@ -244,8 +250,8 @@ class Cache {
|
||||
// Obtiene el objeto de texto a partir de un nombre
|
||||
auto getText(const std::string& name) -> std::shared_ptr<Text>;
|
||||
|
||||
// Obtiene la animación a partir de un nombre
|
||||
auto getAnimations(const std::string& name) -> SurfaceAnimatedSprite::Animations&;
|
||||
// Obtiene los datos de animación parseados a partir de un nombre
|
||||
auto getAnimationData(const std::string& name) -> const ResourceAnimation&;
|
||||
|
||||
// Obtiene el mapa de tiles a partir de un nombre
|
||||
auto getTileMap(const std::string& name) -> std::vector<int>&;
|
||||
|
||||
Reference in New Issue
Block a user