2021-09-28 05:48:06 +02:00
|
|
|
#include "classicarrownote.h"
|
2021-12-28 19:04:50 +01:00
|
|
|
#include "graphics/classicscenegraphicsmanager.h"
|
|
|
|
#include "graphics/animations/classicanimationscenario.h"
|
2021-10-04 17:30:21 +02:00
|
|
|
#include "holdmanager.h"
|
2021-09-28 05:48:06 +02:00
|
|
|
|
|
|
|
ClassicArrowNote::ClassicArrowNote(ArrowNoteInitializer&& init) :
|
|
|
|
ClassicNote(std::move(init.initializer)),
|
|
|
|
_is_hold(init.hold)
|
|
|
|
{
|
|
|
|
_elements.resize(init.elements.size());
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < _elements.size(); ++i)
|
|
|
|
{
|
2021-11-24 19:21:30 +01:00
|
|
|
_elements[i].keys = init.elements[i].keys;
|
2021-12-29 15:59:18 +01:00
|
|
|
_elements[i].position = init.elements[i].element.position;
|
2021-11-24 19:21:30 +01:00
|
|
|
_elements[i].type = init.elements[i].element.type;
|
2021-09-28 05:48:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-23 18:33:24 +01:00
|
|
|
void ClassicArrowNote::putToGame()
|
2021-09-28 05:48:06 +02:00
|
|
|
{
|
2021-12-23 18:33:24 +01:00
|
|
|
_state = State::FLYING;
|
2021-09-28 05:48:06 +02:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicArrowNote::input(kku::GameEvent&& input)
|
2021-09-28 05:48:06 +02:00
|
|
|
{
|
|
|
|
auto grade = ClassicNote::Grade::BAD;
|
|
|
|
|
|
|
|
bool input_valid = std::any_of(_elements.begin(), _elements.end(),
|
2021-12-29 15:59:18 +01:00
|
|
|
[input=input](auto& element)
|
2021-09-28 05:48:06 +02:00
|
|
|
{
|
|
|
|
if (element.pressed)
|
|
|
|
return false;
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
const char code = std::get<kku::SystemEvent::Key>(input.event.data).view;
|
|
|
|
auto key_iterator = std::find(element.keys.begin(), element.keys.end(), code);
|
|
|
|
|
2021-09-28 05:48:06 +02:00
|
|
|
bool found_key = key_iterator != element.keys.end();
|
|
|
|
if (found_key)
|
|
|
|
{
|
|
|
|
element.pressed = true;
|
2021-12-29 15:59:18 +01:00
|
|
|
element.pressed_as = code;
|
2021-09-28 05:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return found_key;
|
|
|
|
});
|
|
|
|
|
|
|
|
bool all_pressed = allElementsPressed();
|
|
|
|
|
|
|
|
if (all_pressed)
|
2021-10-04 17:30:21 +02:00
|
|
|
{
|
2021-12-29 15:59:18 +01:00
|
|
|
grade = _evaluator.calculatePrecision(input.timestamp);
|
2021-10-04 17:30:21 +02:00
|
|
|
if (isHold())
|
|
|
|
_context->hold_manager->emplace(this);
|
|
|
|
}
|
2021-09-28 05:48:06 +02:00
|
|
|
|
|
|
|
if (all_pressed || !input_valid)
|
|
|
|
{
|
|
|
|
_state = State::DYING;
|
|
|
|
for (auto& element : _elements)
|
2021-12-29 15:59:18 +01:00
|
|
|
element.animations[_state]->launch(element.sprite, input.timestamp, getPerfectOffset());
|
2021-09-28 05:48:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "User input: " << static_cast<int>(grade) << "\n";
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicArrowNote::update(const kku::microsec& music_offset)
|
2021-09-28 05:48:06 +02:00
|
|
|
{
|
|
|
|
switch (_state)
|
|
|
|
{
|
|
|
|
default: return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::FLYING:
|
2021-12-29 15:59:18 +01:00
|
|
|
if (!_evaluator.isActive(music_offset) && music_offset > getPerfectOffset())
|
2021-12-08 19:00:47 +01:00
|
|
|
{
|
|
|
|
_state = State::DYING;
|
|
|
|
for (auto& element : _elements)
|
2021-12-29 15:59:18 +01:00
|
|
|
element.animations[_state]->launch(element.sprite, music_offset, getPerfectOffset());
|
2021-10-03 17:23:28 +02:00
|
|
|
}
|
2021-09-28 05:48:06 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case State::DYING:
|
|
|
|
if (_elements[0].animations[_state]->isDone())
|
|
|
|
_state = State::DEAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& element : _elements)
|
|
|
|
if (element.animations[_state])
|
|
|
|
element.animations[_state]->update(music_offset);
|
|
|
|
}
|
|
|
|
|
2021-12-28 19:04:50 +01:00
|
|
|
void ClassicArrowNote::display(const ClassicGraphicsManager * const manager) const
|
2021-12-23 18:33:24 +01:00
|
|
|
{
|
2021-12-28 19:04:50 +01:00
|
|
|
manager->display(_elements);
|
2021-12-23 18:33:24 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicArrowNote::setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range)
|
2021-12-23 18:33:24 +01:00
|
|
|
{
|
|
|
|
manager->setGraphics(_elements, std::move(range));
|
|
|
|
}
|
|
|
|
|
2021-09-28 05:48:06 +02:00
|
|
|
bool ClassicArrowNote::allElementsPressed() const
|
|
|
|
{
|
|
|
|
return std::all_of(_elements.begin(), _elements.end(),
|
|
|
|
[](const auto& element)
|
|
|
|
{
|
|
|
|
return element.pressed;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
bool ClassicArrowNote::isPressedAs(char key) const
|
2021-09-28 05:48:06 +02:00
|
|
|
{
|
|
|
|
return std::any_of(_elements.begin(), _elements.end(),
|
2021-12-08 19:00:47 +01:00
|
|
|
[key](const auto& element)
|
2021-09-28 05:48:06 +02:00
|
|
|
{
|
|
|
|
return key == element.pressed_as;
|
|
|
|
});
|
|
|
|
}
|
2021-10-04 17:30:21 +02:00
|
|
|
|
|
|
|
bool ClassicArrowNote::isHold() const
|
|
|
|
{
|
|
|
|
return _is_hold;
|
|
|
|
}
|