project-kyoku/src/modes/classicmode/editor/classiceditor.cpp

180 lines
5.1 KiB
C++
Raw Normal View History

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"
// Replace with interface by dependency injection
#include "graphics/animations/classicflyinganimationscenario.h"
#include "graphics/animations/classicdyinganimationscenario.h"
//
2022-02-23 23:45:43 +01:00
#include "callbacks/callbacksimple.h"
ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicMockNote>>& timeline,
2022-02-10 00:30:49 +01:00
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager,
const std::shared_ptr<SelectionManager>& selection_manager) :
_timeline(timeline),
_graphics_manager(graphics_manager),
2022-02-10 00:30:49 +01:00
_selection_manager(selection_manager),
_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};
2022-02-23 23:45:43 +01:00
std::set<ClassicMockNote*, kku::NotePtrComparator> notes;
2022-02-06 02:33:09 +01:00
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-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-13 17:52:26 +01:00
return actual_offset + (actual_offset % section.interval);
}
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-12-29 15:59:18 +01:00
switch (input.event.type)
{
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:
{
const auto note = _timeline->getNoteBy(_current_time);
if (_timeline->isExpired(note) && !_bpm_sections.empty() && _current_time >= (*_bpm_sections.begin()).offset_start)
{
ArrowNoteInitializer init;
ArrowElementInitializer element;
init.initializer.intervals = {};
2021-12-29 15:59:18 +01:00
init.initializer.perfect_offset = input.timestamp;
init.hold = false;
2021-12-29 15:59:18 +01:00
element.element.position = std::get<kku::SystemEvent::Mouse>(event.data).position;
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};
element.element.type = Type::UP;
2021-11-02 18:47:42 +01:00
2021-12-29 15:59:18 +01:00
init.elements = { element };
2022-02-10 00:30:49 +01:00
_timeline->insertNote(new ClassicMockNote(std::move(init), _selection_manager));
}
2022-02-10 00:30:49 +01:00
if (!_selection_manager->isMultiselectionEnabled())
_selection_manager->discard();
_graphics_manager->input(std::move(input));
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
{
_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
}
void ClassicEditor::display() const
2021-10-05 20:48:28 +02:00
{
2022-02-06 02:33:09 +01:00
_graphics_manager->display();
2022-02-17 20:20:30 +01:00
_selection_manager->display();
}
2021-10-05 20:48:28 +02:00
2021-12-29 15:59:18 +01:00
void ClassicEditor::recalculate(const kku::microsec& timestamp)
{
_timeline->recalculate(timestamp);
}
void ClassicEditor::selectNoteType(Type type) noexcept
{
_selected_type = type;
2021-10-05 20:48:28 +02:00
}