2021-10-05 14:48:28 -04:00
|
|
|
#include "classiceditor.h"
|
|
|
|
|
2021-12-28 13:04:50 -05:00
|
|
|
#include "game/classicarrownote.h"
|
|
|
|
|
|
|
|
// Replace with interface by dependency injection
|
|
|
|
#include "graphics/animations/classicflyinganimationscenario.h"
|
|
|
|
#include "graphics/animations/classicdyinganimationscenario.h"
|
|
|
|
//
|
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
|
2021-12-28 13:04:50 -05:00
|
|
|
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager) :
|
|
|
|
_timeline(timeline),
|
|
|
|
_graphics_manager(graphics_manager),
|
2021-12-03 14:21:27 -05:00
|
|
|
_selected_type(Type::UP),
|
2021-12-06 14:18:04 -05:00
|
|
|
_current_time(0),
|
|
|
|
_scroll_step(500000)
|
2021-11-02 13:47:42 -04:00
|
|
|
{
|
2021-12-28 13:04:50 -05:00
|
|
|
_timeline->setNotes({});
|
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
|
|
|
{
|
2021-12-13 11:52:26 -05:00
|
|
|
const auto& section = 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
|
|
|
|
2021-12-13 11:52:26 -05:00
|
|
|
return actual_offset + (actual_offset % section.interval);
|
2021-12-09 02:55:53 -05:00
|
|
|
}
|
|
|
|
|
2021-12-29 09:59:18 -05: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;
|
|
|
|
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;
|
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
case kku::SystemEvent::Type::MousePress:
|
2021-11-24 13:21:30 -05:00
|
|
|
{
|
2021-12-28 13:04:50 -05: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 13:21:30 -05:00
|
|
|
{
|
2021-12-28 13:04:50 -05:00
|
|
|
ArrowNoteInitializer init;
|
|
|
|
ArrowElementInitializer element;
|
|
|
|
init.initializer.intervals = {};
|
2021-12-29 09:59:18 -05:00
|
|
|
init.initializer.perfect_offset = input.timestamp;
|
2021-12-28 13:04:50 -05:00
|
|
|
init.hold = false;
|
|
|
|
init.initializer.context = nullptr;
|
2021-11-24 13:21:30 -05:00
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
element.element.position = std::get<kku::SystemEvent::Mouse>(event.data).position;
|
2021-12-28 13:04:50 -05:00
|
|
|
element.element.falling_curve_interpolation = {};
|
2022-01-11 15:15:24 -05:00
|
|
|
|
|
|
|
element.keys = {kku::SystemEvent::Key::Code::W,
|
|
|
|
kku::SystemEvent::Key::Code::Up};
|
|
|
|
|
2021-12-28 13:04:50 -05:00
|
|
|
element.element.type = Type::UP;
|
2021-11-02 13:47:42 -04:00
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
init.elements = { element };
|
2021-11-24 13:21:30 -05:00
|
|
|
|
2021-12-28 13:04:50 -05:00
|
|
|
_timeline->insertNote(new ClassicArrowNote(std::move(init)));
|
2021-11-24 13:21:30 -05:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
2021-12-29 09:59:18 -05: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);
|
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
|
|
|
{
|
2021-11-24 13:21:30 -05:00
|
|
|
}
|
2021-10-05 14:48:28 -04:00
|
|
|
|
2021-12-29 09:59:18 -05:00
|
|
|
void ClassicEditor::recalculate(const kku::microsec& timestamp)
|
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
|
|
|
}
|