Solventat bug amb el punter a ScoreboardData

This commit is contained in:
2025-02-27 14:17:00 +01:00
parent c6474cb2da
commit 0cec9f8556
20 changed files with 246 additions and 223 deletions

View File

@@ -8,7 +8,7 @@
#include "utils.h" // Para printWithDots
// Carga las animaciones en un vector(Animations) desde un fichero
AnimationsFileBuffer loadAnimationsFromFile(const std::string &file_path)
Animations loadAnimationsFromFile(const std::string &file_path)
{
std::ifstream file(file_path);
if (!file)
@@ -37,18 +37,18 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const std::stri
// Carga las animaciones
if (!file_path.empty())
{
AnimationsFileBuffer v = loadAnimationsFromFile(file_path);
loadFromAnimationsFileBuffer(v);
Animations v = loadAnimationsFromFile(file_path);
setAnimations(v);
}
}
// Constructor
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const AnimationsFileBuffer &animations)
AnimatedSprite::AnimatedSprite(std::shared_ptr<Texture> texture, const Animations &animations)
: MovingSprite(texture)
{
if (!animations.empty())
{
loadFromAnimationsFileBuffer(animations);
setAnimations(animations);
}
}
@@ -122,6 +122,7 @@ void AnimatedSprite::setCurrentAnimation(const std::string &name)
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].completed = false;
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
}
}
@@ -135,6 +136,7 @@ void AnimatedSprite::setCurrentAnimation(int index)
animations_[current_animation_].current_frame = 0;
animations_[current_animation_].counter = 0;
animations_[current_animation_].completed = false;
setClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]);
}
}
@@ -154,7 +156,7 @@ void AnimatedSprite::resetAnimation()
}
// Carga la animación desde un vector de cadenas
void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &source)
void AnimatedSprite::setAnimations(const Animations &animations)
{
int frame_width = 1;
int frame_height = 1;
@@ -162,9 +164,9 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
int max_tiles = 1;
size_t index = 0;
while (index < source.size())
while (index < animations.size())
{
std::string line = source.at(index);
std::string line = animations.at(index);
// Parsea el fichero para buscar variables y valores
if (line != "[animation]")
@@ -194,11 +196,11 @@ void AnimatedSprite::loadFromAnimationsFileBuffer(const AnimationsFileBuffer &so
// Si la linea contiene el texto [animation] se realiza el proceso de carga de una animación
if (line == "[animation]")
{
Animation animation;
AnimationData animation;
do
{
index++;
line = source.at(index);
line = animations.at(index);
size_t pos = line.find("=");
if (pos != std::string::npos)