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

185 lines
5.1 KiB
C++
Raw Normal View History

2021-10-05 14:48:28 -04:00
#include "classiceditor.h"
2022-02-09 18:30:49 -05:00
#include "editor/selectionmanager.h"
#include "graphics/classicgraphicsmanager.h"
// Replace with interface by dependency injection
#include "graphics/animations/classicdyinganimationscenario.h"
#include "graphics/animations/classicflyinganimationscenario.h"
//
2022-02-23 17:45:43 -05:00
#include "callbacks/callbacksimple.h"
#include "editorcontext.h"
#include "game/classicarrownote.h"
2022-02-23 17:45:43 -05: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
{
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;
// 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);
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)
{
ArrowElement element;
2022-02-05 20:33:09 -05: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};
element.type = Type::UP;
bool hold = false;
2022-02-05 20:33:09 -05: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)
{
hold = true;
2022-02-05 20:33:09 -05:00
element.keys = {kku::SystemEvent::Key::Code::D,
kku::SystemEvent::Key::Code::Right};
element.type = Type::RIGHT;
counter = 13;
2022-02-05 20:33:09 -05:00
}
--counter;
ClassicArrowNote::Init init{_note_id++, context, bpm_iterator,
input_intervals, {element}, hold};
2022-02-05 20:33:09 -05: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.;
}
_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
{
const auto &section = getBPMSectionAt(offset);
2021-12-29 09:59:18 -05:00
const kku::microsec actual_offset = offset - section.offset_start;
return actual_offset + (actual_offset % (section.interval + 1));
}
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-12-29 09:59:18 -05:00
switch (input.event.type)
{
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)
{
_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)
{
_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:
{
const auto note = _timeline->getNoteBy(_current_time);
if (_timeline->isExpired(note) && !_bpm_sections.empty() &&
_current_time >= (*_bpm_sections.begin()).offset_start)
{
ArrowElement element;
element.position =
std::get<kku::SystemEvent::Mouse>(event.data).position;
element.falling_curve_interpolation = {};
2022-01-11 15:15:24 -05:00
element.keys = {kku::SystemEvent::Key::Code::W,
kku::SystemEvent::Key::Code::Up};
element.type = Type::UP;
2021-11-02 13:47:42 -04:00
ClassicArrowNote::Init init{_note_id++, _context, _current_time,
{}, {element}, false};
_timeline->insertNote(new ClassicArrowNote(std::move(init)));
}
2022-02-09 18:30:49 -05:00
if (!_context->getSelectionManager()->isMultiselectionEnabled())
_context->getSelectionManager()->discard();
2022-02-09 18:30:49 -05:00
//_graphics_manager->input(std::move(input));
2022-02-09 18:30:49 -05:00
break;
}
}
_context->inputUI(std::move(input));
2021-11-02 13:47:42 -04:00
}
void ClassicEditor::update(kku::UpdateData &&updatedata)
2021-11-02 13:47:42 -04:00
{
_timeline->update(updatedata.timestamp);
_context->updateGraphics(updatedata.timestamp);
2021-11-02 13:47:42 -04:00
}
void ClassicEditor::display() const
2021-10-05 14:48:28 -04:00
{
_context->displayGraphics();
}
2021-10-05 14:48:28 -04:00
void ClassicEditor::recalculate(const kku::microsec &timestamp)
{
_timeline->recalculate(timestamp);
}
void ClassicEditor::selectNoteType(Type type) noexcept
{
_selected_type = type;
2021-10-05 14:48:28 -04:00
}