2021-10-05 20:48:28 +02:00
|
|
|
#include "classiceditor.h"
|
|
|
|
|
2022-02-10 00:30:49 +01:00
|
|
|
#include "classicmocknote.h"
|
2022-02-06 02:33:09 +01:00
|
|
|
#include "graphics/classicgraphicsmanager.h"
|
2022-02-10 00:30:49 +01:00
|
|
|
#include "editor/selectionmanager.h"
|
2021-12-28 19:04:50 +01:00
|
|
|
|
|
|
|
// Replace with interface by dependency injection
|
|
|
|
#include "graphics/animations/classicflyinganimationscenario.h"
|
|
|
|
#include "graphics/animations/classicdyinganimationscenario.h"
|
|
|
|
//
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
2022-02-10 00:30:49 +01:00
|
|
|
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager,
|
|
|
|
const std::shared_ptr<SelectionManager>& selection_manager) :
|
2021-12-28 19:04:50 +01:00
|
|
|
_timeline(timeline),
|
|
|
|
_graphics_manager(graphics_manager),
|
2022-02-10 00:30:49 +01:00
|
|
|
_selection_manager(selection_manager),
|
2021-12-03 20:21:27 +01:00
|
|
|
_selected_type(Type::UP),
|
2021-12-06 20:18:04 +01:00
|
|
|
_current_time(0),
|
|
|
|
_scroll_step(500000)
|
2021-11-02 18:47:42 +01:00
|
|
|
{
|
2022-02-06 02:33:09 +01:00
|
|
|
kku::microsec starting_beat_offset = 402162;
|
|
|
|
int amount_of_beats = 209;
|
|
|
|
kku::microsec interval = 1412162;
|
|
|
|
kku::microsec tempo_interval = interval / 4;
|
|
|
|
kku::microsec note_input_offset = 412162 / 2;
|
|
|
|
//microsec note_input_offset_fast = 412162 / 6;
|
|
|
|
kku::microsec bpm_iterator = starting_beat_offset;
|
|
|
|
kku::microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
|
|
|
|
|
|
|
std::vector<kku::microsec> input_intervals = {note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset};
|
|
|
|
std::set<ClassicNote*, kku::NotePtrComparator> notes;
|
|
|
|
input_intervals.shrink_to_fit();
|
|
|
|
|
|
|
|
bpm_iterator += tempo_interval;
|
|
|
|
|
|
|
|
float x = 90.;
|
|
|
|
|
|
|
|
int counter = 3;
|
|
|
|
|
|
|
|
while (bpm_iterator < bpm_end)
|
|
|
|
{
|
|
|
|
ArrowNoteInitializer init;
|
|
|
|
ArrowElementInitializer element;
|
|
|
|
init.initializer.intervals = input_intervals;
|
|
|
|
init.initializer.perfect_offset = bpm_iterator;
|
|
|
|
init.hold = false;
|
|
|
|
|
|
|
|
element.element.position = kku::Point(x, 390.f);
|
|
|
|
element.element.falling_curve_interpolation = {};
|
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::W,
|
|
|
|
kku::SystemEvent::Key::Code::Up};
|
|
|
|
|
|
|
|
element.element.type = Type::UP;
|
|
|
|
|
|
|
|
if (counter == 0)
|
|
|
|
{
|
|
|
|
init.hold = true;
|
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::D,
|
|
|
|
kku::SystemEvent::Key::Code::Right};
|
|
|
|
|
|
|
|
element.element.type = Type::RIGHT;
|
|
|
|
}
|
|
|
|
|
|
|
|
--counter;
|
|
|
|
|
|
|
|
init.elements = {element};
|
|
|
|
|
2022-02-10 00:30:49 +01:00
|
|
|
notes.insert(new ClassicMockNote(std::move(init), _selection_manager));
|
2022-02-06 02:33:09 +01:00
|
|
|
|
|
|
|
bpm_iterator += tempo_interval;
|
|
|
|
x += 70;
|
|
|
|
|
|
|
|
if (x >= 1200)
|
|
|
|
x = 90.;
|
|
|
|
}
|
|
|
|
|
|
|
|
_timeline->setNotes(notes);
|
2021-11-02 18:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
kku::microsec ClassicEditor::adjustOffset(kku::microsec offset) const noexcept
|
2021-12-09 08:55:53 +01:00
|
|
|
{
|
2021-12-13 17:52:26 +01:00
|
|
|
const auto& section = getBPMSectionAt(offset);
|
2021-12-29 15:59:18 +01:00
|
|
|
const kku::microsec actual_offset = offset - section.offset_start;
|
2021-12-09 08:55:53 +01:00
|
|
|
|
2021-12-13 17:52:26 +01:00
|
|
|
return actual_offset + (actual_offset % section.interval);
|
2021-12-09 08:55:53 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicEditor::input(kku::GameEvent&& input)
|
2021-11-02 18:47:42 +01:00
|
|
|
{
|
2021-12-29 15:59:18 +01:00
|
|
|
_current_time = input.timestamp;
|
|
|
|
const auto& event = input.event;
|
2021-11-24 19:21:30 +01:00
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
switch (input.event.type)
|
2021-11-24 19:21:30 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2022-02-10 00:30:49 +01:00
|
|
|
case kku::SystemEvent::Type::KeyPress:
|
|
|
|
{
|
|
|
|
const auto key_data = std::get<kku::SystemEvent::Key>(input.event.data);
|
|
|
|
if (key_data.view == kku::SystemEvent::Key::Code::LControl)
|
|
|
|
{
|
|
|
|
_selection_manager->enableMultiselection(true);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case kku::SystemEvent::Type::KeyRelease:
|
|
|
|
{
|
|
|
|
const auto key_data = std::get<kku::SystemEvent::Key>(input.event.data);
|
|
|
|
if (key_data.view == kku::SystemEvent::Key::Code::LControl)
|
|
|
|
{
|
|
|
|
_selection_manager->enableMultiselection(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
case kku::SystemEvent::Type::MousePress:
|
2021-11-24 19:21:30 +01:00
|
|
|
{
|
2021-12-28 19:04:50 +01:00
|
|
|
const auto note = _timeline->getNoteBy(_current_time);
|
|
|
|
if (_timeline->isExpired(note) && !_bpm_sections.empty() && _current_time >= (*_bpm_sections.begin()).offset_start)
|
2021-11-24 19:21:30 +01:00
|
|
|
{
|
2021-12-28 19:04:50 +01:00
|
|
|
ArrowNoteInitializer init;
|
|
|
|
ArrowElementInitializer element;
|
|
|
|
init.initializer.intervals = {};
|
2021-12-29 15:59:18 +01:00
|
|
|
init.initializer.perfect_offset = input.timestamp;
|
2021-12-28 19:04:50 +01:00
|
|
|
init.hold = false;
|
2021-11-24 19:21:30 +01:00
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
element.element.position = std::get<kku::SystemEvent::Mouse>(event.data).position;
|
2021-12-28 19:04:50 +01:00
|
|
|
element.element.falling_curve_interpolation = {};
|
2022-01-11 21:15:24 +01:00
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::W,
|
|
|
|
kku::SystemEvent::Key::Code::Up};
|
|
|
|
|
2021-12-28 19:04:50 +01:00
|
|
|
element.element.type = Type::UP;
|
2021-11-02 18:47:42 +01:00
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
init.elements = { element };
|
2021-11-24 19:21:30 +01:00
|
|
|
|
2022-02-10 00:30:49 +01:00
|
|
|
_timeline->insertNote(new ClassicMockNote(std::move(init), _selection_manager));
|
2021-11-24 19:21:30 +01:00
|
|
|
}
|
2022-02-10 00:30:49 +01:00
|
|
|
|
|
|
|
if (!_selection_manager->isMultiselectionEnabled())
|
|
|
|
_selection_manager->discard();
|
|
|
|
|
|
|
|
_graphics_manager->input(std::move(input));
|
|
|
|
|
2021-11-24 19:21:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-11-02 18:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicEditor::update(kku::UpdateData&& updatedata)
|
2021-11-02 18:47:42 +01:00
|
|
|
{
|
2021-12-28 19:04:50 +01:00
|
|
|
_timeline->update(updatedata.timestamp);
|
2022-02-06 02:33:09 +01:00
|
|
|
_graphics_manager->update(updatedata.timestamp);
|
2021-11-02 18:47:42 +01:00
|
|
|
}
|
|
|
|
|
2021-12-28 19:04:50 +01:00
|
|
|
void ClassicEditor::display() const
|
2021-10-05 20:48:28 +02:00
|
|
|
{
|
2022-02-06 02:33:09 +01:00
|
|
|
_graphics_manager->display();
|
2021-11-24 19:21:30 +01:00
|
|
|
}
|
2021-10-05 20:48:28 +02:00
|
|
|
|
2021-12-29 15:59:18 +01:00
|
|
|
void ClassicEditor::recalculate(const kku::microsec& timestamp)
|
2021-12-08 19:00:47 +01:00
|
|
|
{
|
2021-12-28 19:04:50 +01:00
|
|
|
_timeline->recalculate(timestamp);
|
2021-12-08 19:00:47 +01:00
|
|
|
}
|
|
|
|
|
2021-11-24 19:21:30 +01:00
|
|
|
void ClassicEditor::selectNoteType(Type type) noexcept
|
|
|
|
{
|
|
|
|
_selected_type = type;
|
2021-10-05 20:48:28 +02:00
|
|
|
}
|