2021-10-05 14:48:28 -04:00
|
|
|
#include "classiceditor.h"
|
|
|
|
|
2022-02-09 18:30:49 -05:00
|
|
|
#include "editor/selectionmanager.h"
|
2022-10-17 22:59:51 -04:00
|
|
|
#include "graphics/classicgraphicsmanager.h"
|
2021-12-28 13:04:50 -05:00
|
|
|
|
|
|
|
// Replace with interface by dependency injection
|
|
|
|
#include "graphics/animations/classicdyinganimationscenario.h"
|
2022-10-17 22:59:51 -04:00
|
|
|
#include "graphics/animations/classicflyinganimationscenario.h"
|
2021-12-28 13:04:50 -05:00
|
|
|
//
|
|
|
|
|
2022-02-23 17:45:43 -05:00
|
|
|
#include "callbacks/callbacksimple.h"
|
2022-10-17 22:59:51 -04:00
|
|
|
#include "editorcontext.h"
|
|
|
|
#include "game/classicarrownote.h"
|
2022-02-23 17:45:43 -05:00
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
ClassicEditor::ClassicEditor(
|
|
|
|
const std::shared_ptr<kku::Timeline<ClassicNote>> &timeline,
|
|
|
|
const std::shared_ptr<EditorContext> &context)
|
|
|
|
: _timeline(timeline), _context(context), _selected_type(Type::UP),
|
|
|
|
_current_time(0), _scroll_step(500000), _note_id(0)
|
2021-11-02 13:47:42 -04:00
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
kku::microsec starting_beat_offset = 402162;
|
2022-02-05 20:33:09 -05:00
|
|
|
int amount_of_beats = 209;
|
|
|
|
kku::microsec interval = 1412162;
|
|
|
|
kku::microsec tempo_interval = interval / 4;
|
|
|
|
kku::microsec note_input_offset = 412162 / 2;
|
2022-10-17 22:59:51 -04:00
|
|
|
// microsec note_input_offset_fast = 412162 / 6;
|
2022-02-05 20:33:09 -05:00
|
|
|
kku::microsec bpm_iterator = starting_beat_offset;
|
|
|
|
kku::microsec bpm_end = starting_beat_offset + (interval * amount_of_beats);
|
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
std::vector<kku::microsec> input_intervals = {
|
|
|
|
note_input_offset / 3, note_input_offset / 3 * 2, note_input_offset};
|
|
|
|
std::set<ClassicNote *, kku::NotePtrComparator> notes;
|
2022-02-05 20:33:09 -05:00
|
|
|
input_intervals.shrink_to_fit();
|
|
|
|
|
|
|
|
bpm_iterator += tempo_interval;
|
|
|
|
|
|
|
|
float x = 90.;
|
|
|
|
|
|
|
|
int counter = 3;
|
|
|
|
while (bpm_iterator < bpm_end)
|
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
ArrowElement element;
|
2022-02-05 20:33:09 -05:00
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
element.position = kku::Point(x, 390.f);
|
|
|
|
element.falling_curve_interpolation = {};
|
2022-02-05 20:33:09 -05:00
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::W,
|
|
|
|
kku::SystemEvent::Key::Code::Up};
|
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
element.type = Type::UP;
|
|
|
|
|
|
|
|
bool hold = false;
|
2022-02-05 20:33:09 -05:00
|
|
|
|
2022-05-28 01:52:59 -04:00
|
|
|
if (_note_id == 0)
|
|
|
|
{
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::S,
|
|
|
|
kku::SystemEvent::Key::Code::Down};
|
|
|
|
|
|
|
|
element.type = Type::DOWN;
|
|
|
|
}
|
|
|
|
|
2022-02-05 20:33:09 -05:00
|
|
|
if (counter == 0)
|
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
hold = true;
|
2022-02-05 20:33:09 -05:00
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::D,
|
|
|
|
kku::SystemEvent::Key::Code::Right};
|
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
element.type = Type::RIGHT;
|
|
|
|
|
|
|
|
counter = 13;
|
2022-02-05 20:33:09 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
--counter;
|
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
ClassicArrowNote::Init init{_note_id++, context, bpm_iterator,
|
|
|
|
input_intervals, {element}, hold};
|
2022-02-05 20:33:09 -05:00
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
notes.insert(new ClassicArrowNote(std::move(init)));
|
2022-02-05 20:33:09 -05:00
|
|
|
|
|
|
|
bpm_iterator += tempo_interval;
|
|
|
|
x += 70;
|
|
|
|
|
|
|
|
if (x >= 1200)
|
|
|
|
x = 90.;
|
|
|
|
}
|
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
_timeline->setNotes(notes);
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
kku::microsec ClassicEditor::adjustOffset(kku::microsec offset) const noexcept
|
2021-12-09 02:55:53 -05:00
|
|
|
{
|
2022-10-17 22:59:51 -04:00
|
|
|
const auto §ion = getBPMSectionAt(offset);
|
2021-12-29 09:59:18 -05:00
|
|
|
const kku::microsec actual_offset = offset - section.offset_start;
|
2021-12-09 02:55:53 -05:00
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
return actual_offset + (actual_offset % (section.interval + 1));
|
2021-12-09 02:55:53 -05:00
|
|
|
}
|
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
void ClassicEditor::input(kku::GameEvent &&input)
|
2021-11-02 13:47:42 -04:00
|
|
|
{
|
2021-12-29 09:59:18 -05:00
|
|
|
_current_time = input.timestamp;
|
2022-10-17 22:59:51 -04:00
|
|
|
const auto &event = input.event;
|
2021-11-24 13:21:30 -05:00
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
switch (input.event.type)
|
2021-11-24 13:21:30 -05:00
|
|
|
{
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
2022-02-09 18:30:49 -05: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)
|
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
_context->getSelectionManager()->enableMultiselection(true);
|
2022-02-09 18:30:49 -05:00
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
_context->getSelectionManager()->enableMultiselection(false);
|
2022-02-09 18:30:49 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
case kku::SystemEvent::Type::MousePress:
|
2021-11-24 13:21:30 -05:00
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
const auto note = _timeline->getNoteBy(_current_time);
|
2022-10-17 22:59:51 -04:00
|
|
|
if (_timeline->isExpired(note) && !_bpm_sections.empty() &&
|
|
|
|
_current_time >= (*_bpm_sections.begin()).offset_start)
|
2021-11-24 13:21:30 -05:00
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
ArrowElement element;
|
2021-11-24 13:21:30 -05:00
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
element.position =
|
|
|
|
std::get<kku::SystemEvent::Mouse>(event.data).position;
|
2022-05-22 00:17:15 -04:00
|
|
|
element.falling_curve_interpolation = {};
|
2022-01-11 15:15:24 -05:00
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::W,
|
|
|
|
kku::SystemEvent::Key::Code::Up};
|
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
element.type = Type::UP;
|
2021-11-02 13:47:42 -04:00
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
ClassicArrowNote::Init init{_note_id++, _context, _current_time,
|
|
|
|
{}, {element}, false};
|
2021-11-24 13:21:30 -05:00
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
_timeline->insertNote(new ClassicArrowNote(std::move(init)));
|
2021-11-24 13:21:30 -05:00
|
|
|
}
|
2022-02-09 18:30:49 -05:00
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
if (!_context->getSelectionManager()->isMultiselectionEnabled())
|
|
|
|
_context->getSelectionManager()->discard();
|
2022-02-09 18:30:49 -05:00
|
|
|
|
2022-05-22 00:17:15 -04:00
|
|
|
//_graphics_manager->input(std::move(input));
|
2022-02-09 18:30:49 -05:00
|
|
|
|
2021-11-24 13:21:30 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-05-28 01:52:59 -04:00
|
|
|
|
|
|
|
_context->inputUI(std::move(input));
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
void ClassicEditor::update(kku::UpdateData &&updatedata)
|
2021-11-02 13:47:42 -04:00
|
|
|
{
|
2021-12-28 13:04:50 -05:00
|
|
|
_timeline->update(updatedata.timestamp);
|
2022-05-22 00:17:15 -04:00
|
|
|
_context->updateGraphics(updatedata.timestamp);
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
2021-12-28 13:04:50 -05:00
|
|
|
void ClassicEditor::display() const
|
2021-10-05 14:48:28 -04:00
|
|
|
{
|
2022-05-22 00:17:15 -04:00
|
|
|
_context->displayGraphics();
|
2021-11-24 13:21:30 -05:00
|
|
|
}
|
2021-10-05 14:48:28 -04:00
|
|
|
|
2022-10-17 22:59:51 -04:00
|
|
|
void ClassicEditor::recalculate(const kku::microsec ×tamp)
|
2021-12-08 13:00:47 -05:00
|
|
|
{
|
2021-12-28 13:04:50 -05:00
|
|
|
_timeline->recalculate(timestamp);
|
2021-12-08 13:00:47 -05:00
|
|
|
}
|
|
|
|
|
2021-11-24 13:21:30 -05:00
|
|
|
void ClassicEditor::selectNoteType(Type type) noexcept
|
|
|
|
{
|
|
|
|
_selected_type = type;
|
2021-10-05 14:48:28 -04:00
|
|
|
}
|