#include "classicarrownote.h" #include "graphics/classicscenegraphicsmanager.h" #include "graphics/animations/classicanimationscenario.h" #include "holdmanager.h" 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) { _elements[i].keys = init.elements[i].keys; _elements[i].position = init.elements[i].element.position; _elements[i].type = init.elements[i].element.type; } } void ClassicArrowNote::putToGame() { _state = State::FLYING; } void ClassicArrowNote::input(kku::GameEvent&& input) { auto grade = ClassicNote::Grade::BAD; bool input_valid = std::any_of(_elements.begin(), _elements.end(), [input=input](auto& element) { if (element.pressed) return false; const char code = std::get(input.event.data).view; auto key_iterator = std::find(element.keys.begin(), element.keys.end(), code); bool found_key = key_iterator != element.keys.end(); if (found_key) { element.pressed = true; element.pressed_as = code; } return found_key; }); bool all_pressed = allElementsPressed(); if (all_pressed) { grade = _evaluator.calculatePrecision(input.timestamp); if (isHold()) _context->hold_manager->emplace(this); } if (all_pressed || !input_valid) { _state = State::DYING; for (auto& element : _elements) element.animations[_state]->launch(element.sprite, input.timestamp, getPerfectOffset()); } std::cout << "User input: " << static_cast(grade) << "\n"; } void ClassicArrowNote::update(const kku::microsec& music_offset) { switch (_state) { default: return; break; case State::FLYING: if (!_evaluator.isActive(music_offset) && music_offset > getPerfectOffset()) { _state = State::DYING; for (auto& element : _elements) element.animations[_state]->launch(element.sprite, music_offset, getPerfectOffset()); } 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); } void ClassicArrowNote::display(const ClassicGraphicsManager * const manager) const { manager->display(_elements); } void ClassicArrowNote::setGraphics(ClassicGraphicsManager * const manager, kku::TimeRange&& range) { manager->setGraphics(_elements, std::move(range)); } bool ClassicArrowNote::allElementsPressed() const { return std::all_of(_elements.begin(), _elements.end(), [](const auto& element) { return element.pressed; }); } bool ClassicArrowNote::isPressedAs(char key) const { return std::any_of(_elements.begin(), _elements.end(), [key](const auto& element) { return key == element.pressed_as; }); } bool ClassicArrowNote::isHold() const { return _is_hold; }