<commit_before>#include "Spritemap.h"
#include "Logging.h"

namespace ECSE
{

Spritemap::Spritemap()
    : callback(nullptr), m_texture(nullptr), m_animSet(nullptr), m_currentAnim(nullptr),
    m_currentTime(sf::Time::Zero), m_currentFrame(0)
{

}

Spritemap::Spritemap(const sf::Texture& texture)
    : Spritemap()
{
    setTexture(texture);
}

Spritemap::Spritemap(const sf::Texture& texture, const AnimationSet& animSet)
    : Spritemap(texture)
{
    setAnimationSet(animSet);
    setIndex(0);
}

void Spritemap::playAnimation(std::string name, bool reset)
{
    if (!m_animSet)
    {
        LOG(WARNING) << "Tried to play animation \"" + name + "\" on a Spritemap with no animations!";
    }

    const Animation &newAnim = m_animSet->getAnimation(name);

    // Already playing
    if (&newAnim == m_currentAnim && reset)
    {
        setIndex(0, true);
        return;
    }

    // Start playing
    m_currentAnim = &newAnim;
    m_currentTime = sf::Time::Zero;
    m_playing = true;
}

void Spritemap::stop()
{
    m_playing = false;
    m_currentAnim = nullptr;
}

void Spritemap::update(sf::Time deltaTime)
{
    if (!m_playing || !m_currentAnim) return;

    size_t frameCount = m_currentAnim->frames.size();
    sf::Time frameTime = m_currentAnim->frameTime;

    // Calculate new frame
    m_currentTime += deltaTime;
    if (m_currentTime > frameTime)
    {
        size_t frameIncrease = static_cast<size_t>(m_currentTime / frameTime);
        m_currentFrame += frameIncrease;

        // Reset time with remainder
        m_currentTime = m_currentTime % frameTime;
        
        if (m_currentFrame >= frameCount)
        {<commit_msg>Fixed sprites not working with frameTime = 0<commit_after>#include "Spritemap.h"
#include "Logging.h"

namespace ECSE
{

Spritemap::Spritemap()
    : callback(nullptr), m_texture(nullptr), m_animSet(nullptr), m_currentAnim(nullptr),
    m_currentTime(sf::Time::Zero), m_currentFrame(0)
{

}

Spritemap::Spritemap(const sf::Texture& texture)
    : Spritemap()
{
    setTexture(texture);
}

Spritemap::Spritemap(const sf::Texture& texture, const AnimationSet& animSet)
    : Spritemap(texture)
{
    setAnimationSet(animSet);
    setIndex(0);
}

void Spritemap::playAnimation(std::string name, bool reset)
{
    if (!m_animSet)
    {
        LOG(WARNING) << "Tried to play animation \"" + name + "\" on a Spritemap with no animations!";
    }

    const Animation &newAnim = m_animSet->getAnimation(name);

    // Already playing
    if (&newAnim == m_currentAnim && reset)
    {
        setIndex(0, true);
        return;
    }

    // Start playing
    m_currentAnim = &newAnim;
    m_currentTime = sf::Time::Zero;
    m_playing = true;
}

void Spritemap::stop()
{
    m_playing = false;
    m_currentAnim = nullptr;
}

void Spritemap::update(sf::Time deltaTime)
{
    if (!m_playing || !m_currentAnim) return;

    size_t frameCount = m_currentAnim->frames.size();
    sf::Time frameTime = m_currentAnim->frameTime;

    // Calculate new frame
    m_currentTime += deltaTime;

    // If frame time is 0, we just want the first frame
    if (frameTime == sf::seconds(0))
    {
        m_currentFrame = 0;
        setIndex(m_currentAnim->frames[m_currentFrame]);
        return;
    }

    if (m_currentTime > frameTime)
    {
        size_t frameIncrease = static_cast<size_t>(m_currentTime / frameTime);
        m_currentFrame += frameIncrease;

        // Reset time with remainder
        m_currentTime = m_currentTime % frameTime;
        
        if (m_currentFrame >= frameCount)
        {
{'fraction_non_alphanumeric': 0.1233455364686004, 'fraction_numerical': 0.0028161081385525205, 'mean_word_length': 3.2285714285714286, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4374037', 'n_tokens_mistral': 1216, 'n_tokens_neox': 1197, 'n_words': 244}