diff --git a/src/modes/classicmode/classicfactory.cpp b/src/modes/classicmode/classicfactory.cpp index 9749635..22a4169 100644 --- a/src/modes/classicmode/classicfactory.cpp +++ b/src/modes/classicmode/classicfactory.cpp @@ -27,9 +27,8 @@ std::unique_ptr classic::getEditor(const std::shared_ptr(core_factory); - const auto timeline = std::make_shared>(); - const auto selection_manager = std::make_shared>(); - const auto graphics_manager = std::make_shared>(timeline, factory, visibility_offset); + const auto timeline = std::make_shared>(); + const auto graphics_manager = std::make_shared>(timeline, factory, visibility_offset); - return std::make_unique(timeline, graphics_manager, selection_manager); + return std::make_unique(timeline, graphics_manager); } diff --git a/src/modes/classicmode/classicnote.cpp b/src/modes/classicmode/classicnote.cpp index bc6708a..aa6c843 100644 --- a/src/modes/classicmode/classicnote.cpp +++ b/src/modes/classicmode/classicnote.cpp @@ -1,7 +1,7 @@ #include "classicmode/classicnote.h" -ClassicNote::ClassicNote(NoteInitializer &&init) : - Note(init.perfect_offset), +ClassicNote::ClassicNote(const kku::microsec& perfect_offset) : + Note(perfect_offset), _state(State::NONE) {} diff --git a/src/modes/classicmode/editor/classiceditor.cpp b/src/modes/classicmode/editor/classiceditor.cpp index f665447..ad6c1ca 100644 --- a/src/modes/classicmode/editor/classiceditor.cpp +++ b/src/modes/classicmode/editor/classiceditor.cpp @@ -1,6 +1,5 @@ #include "classiceditor.h" -#include "classicmocknote.h" #include "graphics/classicgraphicsmanager.h" #include "editor/selectionmanager.h" @@ -11,9 +10,9 @@ #include "callbacks/callbacksimple.h" -ClassicEditor::ClassicEditor(const std::shared_ptr>& timeline, +ClassicEditor::ClassicEditor(const std::shared_ptr>& timeline, const std::shared_ptr& graphics_manager, - const std::shared_ptr>& selection_manager) : + const std::shared_ptr>& selection_manager) : _timeline(timeline), _graphics_manager(graphics_manager), _selection_manager(selection_manager), @@ -31,7 +30,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset}; - std::set notes; + std::set notes; input_intervals.shrink_to_fit(); bpm_iterator += tempo_interval; diff --git a/src/modes/classicmode/editor/classiceditor.h b/src/modes/classicmode/editor/classiceditor.h index e2aaa8d..7ba0a98 100644 --- a/src/modes/classicmode/editor/classiceditor.h +++ b/src/modes/classicmode/editor/classiceditor.h @@ -6,7 +6,7 @@ #include "core/timeline.h" #include "selectionmanager.h" -#include "classicmocknote.h" +#include "classicmode/classicnote.h" #include "classicmode/classicactions.h" class ClassicGraphicsManager; @@ -14,9 +14,9 @@ class ClassicGraphicsManager; class ClassicEditor : public kku::Editor { public: - explicit ClassicEditor(const std::shared_ptr>& timeline, + explicit ClassicEditor(const std::shared_ptr>& timeline, const std::shared_ptr& graphics_manager, - const std::shared_ptr>& selection_manager); + const std::shared_ptr>& selection_manager); virtual void input(kku::GameEvent&& input) override; virtual void update(kku::UpdateData&& updatedata) override; @@ -28,9 +28,9 @@ public: private: inline kku::microsec adjustOffset(kku::microsec offset) const noexcept; - const std::shared_ptr> _timeline; + const std::shared_ptr> _timeline; const std::shared_ptr _graphics_manager; - const std::shared_ptr> _selection_manager; + const std::shared_ptr> _selection_manager; Type _selected_type; kku::microsec _current_time; diff --git a/src/modes/classicmode/editor/classicmocknote.cpp b/src/modes/classicmode/editor/classicmocknote.cpp deleted file mode 100644 index 356e8a4..0000000 --- a/src/modes/classicmode/editor/classicmocknote.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "classicmocknote.h" -#include "graphics/classicscenegraphicsmanager.h" -#include "graphics/animations/classicanimationscenario.h" -#include "editor/selectionmanager.h" - -ClassicMockNote::ClassicMockNote(ArrowNoteInitializer&& init, const std::shared_ptr>& selection_manager) : - ClassicNote(std::move(init.initializer)), - _selection_manager(selection_manager) -{ - _elements.resize(init.elements.size()); - - for (std::size_t i = 0; i < _elements.size(); ++i) - { - _elements[i].position = init.elements[i].element.position; - _elements[i].type = init.elements[i].element.type; - } -} - -bool ClassicMockNote::isActive(const kku::microsec &offset) const -{ - (void)offset; - return _state != State::DEAD - && _state != State::NONE; -} - -void ClassicMockNote::input(kku::GameEvent&& input) -{ - switch (input.event.type) - { - - default: - break; - - case kku::SystemEvent::Type::MousePress: - { - bool selection_changed = false; - std::size_t amount_selected = 0; - - const auto position = std::get(input.event.data).position; - for (auto& element : _elements) - { - if (element.sprite->getRectangle()->contains(position)) - { - element.selected = !element.selected; - selection_changed = true; - if (element.selected) - ++amount_selected; - } - } - - if (selection_changed) - { - if (amount_selected > 0) - _selection_manager->fetch(this); - else - _selection_manager->remove(this); - } - - break; - } - - } -} - -void ClassicMockNote::update(const kku::microsec& music_offset) -{ - switch (_state) - { - default: return; - break; - - case State::FLYING: - if (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); -} - -std::vector& ClassicMockNote::getElements() -{ - return _elements; -} - -void ClassicMockNote::deselect() -{ - for (auto& element : _elements) - element.selected = false; -} diff --git a/src/modes/classicmode/editor/classicmocknote.h b/src/modes/classicmode/editor/classicmocknote.h deleted file mode 100644 index ee5ab3c..0000000 --- a/src/modes/classicmode/editor/classicmocknote.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "classicmode/classicnote.h" - -#include "mockelement.h" -#include "classicmode/arrownoteinitializer.h" -#include "selectionmanager.h" - -class ClassicMockNote : public ClassicNote -{ -public: - explicit ClassicMockNote(ArrowNoteInitializer&& init, const std::shared_ptr>& selection_manager); - virtual ~ClassicMockNote() = default; - - virtual bool isActive(const kku::microsec& offset) const override; - virtual void update(const kku::microsec &music_offset) override; - virtual void input(kku::GameEvent&& input) override; - - std::vector& getElements(); - void deselect(); - -private: - const std::shared_ptr> _selection_manager; - std::vector _elements; -}; - -using MockElements = std::vector; diff --git a/src/modes/classicmode/game/classicarrownote.cpp b/src/modes/classicmode/game/classicarrownote.cpp deleted file mode 100644 index 49d4c70..0000000 --- a/src/modes/classicmode/game/classicarrownote.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "classicarrownote.h" -#include "graphics/animations/classicanimationscenario.h" -#include "holdmanager.h" - -#include - -ClassicArrowNote::ClassicArrowNote(ArrowNoteInitializer&& init, const std::shared_ptr& hold_manager) : - ClassicNote(std::move(init.initializer)), - _evaluator(init.initializer.intervals, _perfect_offset), - _hold_manager(hold_manager), - _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; - } -} - -bool ClassicArrowNote::isActive(const kku::microsec& offset) const -{ - return _evaluator.isActive(offset) - && _state != State::DYING; -} - -void ClassicArrowNote::input(kku::GameEvent&& input) -{ - auto grade = Grade::BAD; - - bool input_valid = std::any_of(_elements.begin(), _elements.end(), - [input=input](auto& element) - { - if (element.pressed) - return false; - - const auto 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()) - _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); -} - -bool ClassicArrowNote::allElementsPressed() const -{ - return std::all_of(_elements.begin(), _elements.end(), - [](const auto& element) - { - return element.pressed; - }); -} - -bool ClassicArrowNote::isPressedAs(kku::SystemEvent::Key::Code 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; -} - -std::vector& ClassicArrowNote::getElements() -{ - return _elements; -} diff --git a/src/modes/classicmode/game/classicarrownote.h b/src/modes/classicmode/game/classicarrownote.h index b05ac3c..40ac86b 100644 --- a/src/modes/classicmode/game/classicarrownote.h +++ b/src/modes/classicmode/game/classicarrownote.h @@ -1,14 +1,24 @@ #pragma once -#include "arrowelement.h" +#include "core/precisionevaluator.h" #include "classicmode/classicnote.h" -#include "classicmode/arrownoteinitializer.h" +#include "graphics/animations/classicanimationscenario.h" -class HoldManager; +#include +template class ClassicArrowNote : public ClassicNote { public: + + struct Init + { + const kku::microsec perfect_offset = 0; + + const std::vector& intervals = {}; + const std::vector& elements = {}; + }; + enum class Grade { PERFECT, @@ -16,25 +26,114 @@ public: BAD }; - explicit ClassicArrowNote(ArrowNoteInitializer&& init, const std::shared_ptr& hold_manager); - virtual ~ClassicArrowNote() = default; + explicit ClassicArrowNote(Init&& init) : + ClassicNote(init.perfect_offset), + _evaluator(init.intervals, init.perfect_offset) + { + _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; + } + } + + virtual bool isActive(const kku::microsec& offset) const override + { + return _evaluator.isActive(offset) + && _state != State::DYING; + } + + virtual void update(const kku::microsec &music_offset) override + { + 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); + } - virtual bool isActive(const kku::microsec& offset) const override; - virtual void update(const kku::microsec &music_offset) override; - virtual void input(kku::GameEvent&& input) override; + virtual void input(kku::GameEvent&& input) override + { + auto grade = Grade::BAD; + + bool input_valid = std::any_of(_elements.begin(), _elements.end(), + [input=input](auto& element) + { + if (element.pressed) + return false; + + const auto 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()) + //_hold_manager->emplace(this); + } - bool allElementsPressed() const; - bool isPressedAs(kku::SystemEvent::Key::Code key) const; - inline bool isHold() const; + if (all_pressed || !input_valid) + { + _state = State::DYING; + for (auto& element : _elements) + element.animations[_state]->launch(element.sprite, input.timestamp, getPerfectOffset()); + } - std::vector& getElements(); + std::cout << "User input: " << static_cast(grade) << "\n"; + } + + bool allElementsPressed() const + { + return std::all_of(_elements.begin(), _elements.end(), + [](const auto& element) + { + return element.pressed; + }); + } + + bool isPressedAs(kku::SystemEvent::Key::Code key) const + { + return std::any_of(_elements.begin(), _elements.end(), + [key](const auto& element) + { + return key == element.pressed_as; + }); + } private: const kku::PrecisionEvaluator _evaluator; - const std::shared_ptr _hold_manager; - - std::vector _elements; - bool _is_hold; + std::vector _elements; }; - -using ArrowElements = std::vector; diff --git a/src/modes/classicmode/game/holdmanager.h b/src/modes/classicmode/game/holdmanager.h index ddc5d20..fb04acd 100644 --- a/src/modes/classicmode/game/holdmanager.h +++ b/src/modes/classicmode/game/holdmanager.h @@ -1,22 +1,23 @@ #pragma once +#include "classicarrownote.h" +#include "game/arrowelement.h" #include "core/gameevent.h" #include #include -class ClassicArrowNote; class ClassicGraphicsManager; class HoldManager { public: - void emplace(ClassicArrowNote* note); + void emplace(ClassicArrowNote* note); void checkRelease(kku::SystemEvent::Key::Code released_key); void drawHoldBar(); private: - std::vector _notes_on_hold; + std::vector*> _notes_on_hold; std::shared_ptr _graphics_manager; }; diff --git a/src/modes/classicmode/include/classicmode/arrowelementinitializer.h b/src/modes/classicmode/include/classicmode/arrowelementinitializer.h deleted file mode 100644 index 6c63706..0000000 --- a/src/modes/classicmode/include/classicmode/arrowelementinitializer.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once - -#include "classicmode/elementinitializer.h" - -struct ArrowElementInitializer -{ - ElementInitializer element; - std::array keys; -}; diff --git a/src/modes/classicmode/include/classicmode/arrownoteinitializer.h b/src/modes/classicmode/include/classicmode/arrownoteinitializer.h deleted file mode 100644 index e87cb1d..0000000 --- a/src/modes/classicmode/include/classicmode/arrownoteinitializer.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include "classicmode/noteinitializer.h" -#include "arrowelementinitializer.h" - -struct ArrowNoteInitializer -{ - NoteInitializer initializer; - bool hold = false; - - std::vector elements; -}; diff --git a/src/modes/classicmode/include/classicmode/classicnote.h b/src/modes/classicmode/include/classicmode/classicnote.h index c02aecd..073c3ec 100644 --- a/src/modes/classicmode/include/classicmode/classicnote.h +++ b/src/modes/classicmode/include/classicmode/classicnote.h @@ -1,10 +1,6 @@ #pragma once #include "core/note.h" -#include "core/precisionevaluator.h" -#include "classicmode/noteinitializer.h" - -class ClassicGraphicsManager; class ClassicNote : public kku::Note { @@ -19,7 +15,7 @@ public: DEAD }; - explicit ClassicNote(NoteInitializer&& init); + explicit ClassicNote(const kku::microsec& perfect_offset); virtual ~ClassicNote() override = default; virtual bool isActive(const kku::microsec& offset) const override = 0; diff --git a/src/modes/classicmode/include/classicmode/elementinitializer.h b/src/modes/classicmode/include/classicmode/elementinitializer.h deleted file mode 100644 index 6c719bb..0000000 --- a/src/modes/classicmode/include/classicmode/elementinitializer.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include "classicactions.h" -#include "core/gameevent.h" -#include "core/point.h" - -#include - -struct ElementInitializer -{ - Type type = Type::NONE; - - kku::Point position; - std::vector falling_curve_interpolation; -}; diff --git a/src/modes/classicmode/include/classicmode/noteinitializer.h b/src/modes/classicmode/include/classicmode/noteinitializer.h deleted file mode 100644 index f806061..0000000 --- a/src/modes/classicmode/include/classicmode/noteinitializer.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include -#include - -#include "core/time.h" - -struct NoteInitializer -{ - std::vector intervals; - kku::microsec perfect_offset = 0; -};