#include "classicdyinganimationscenario.h"
#include "graphics/classicnotegraphics.h"

void ClassicDyingAnimationScenario::launch(const std::shared_ptr<ClassicNoteGraphics> sprite, const kku::microsec& time_begin, const kku::microsec &time_end)
{
    _sprite = sprite;
    _time_begin = time_begin;
    _time_end = time_end;

    _sprite->setColor(kku::Color{140, 140, 140, 255});
    _sprite->setTrailColor(kku::Color{0, 0, 0, 255});
    _sprite->setTrailPosition(kku::Point{0, 0});
}

void ClassicDyingAnimationScenario::update(const kku::microsec& music_offset)
{
    (void) music_offset;

    auto fill_color = _sprite->getColor();

    if (fill_color.alpha == 0)
    {
        fill_color.alpha = 0;
        _sprite->setColor(fill_color);
        return;
    }

    auto new_alpha = (int(fill_color.alpha) - 15) < 0 ? 0 : int(fill_color.alpha) - 15;
    fill_color.alpha = new_alpha;

    _sprite->setColor(fill_color);
}

bool ClassicDyingAnimationScenario::isDone() const
{
    return _sprite->getColor().alpha == 0;
}
