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

85 lines
2.3 KiB
C++
Raw Normal View History

2021-10-05 14:48:28 -04:00
#include "classiceditor.h"
#include "game/classicarrownote.h"
// Replace with interface by dependency injection
#include "graphics/animations/classicflyinganimationscenario.h"
#include "graphics/animations/classicdyinganimationscenario.h"
//
ClassicEditor::ClassicEditor(const std::shared_ptr<Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager) :
_timeline(timeline),
_graphics_manager(graphics_manager),
_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
{
_timeline->setNotes({});
2021-11-02 13:47:42 -04:00
}
microsec ClassicEditor::adjustOffset(microsec offset) const noexcept
{
2021-12-13 11:52:26 -05:00
const auto& section = getBPMSectionAt(offset);
const microsec actual_offset = offset - section.offset_start;
2021-12-13 11:52:26 -05:00
return actual_offset + (actual_offset % section.interval);
}
2021-11-02 13:47:42 -04:00
void ClassicEditor::input(PlayerInput&& inputdata)
{
_current_time = inputdata.timestamp;
const auto& event = inputdata.event;
switch (event.type)
{
default:
break;
case sf::Event::MouseButtonPressed:
{
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 = {};
init.initializer.perfect_offset = inputdata.timestamp;
init.hold = false;
init.initializer.context = nullptr;
element.element.coordinates = Coordinates(event.mouseButton.x, event.mouseButton.y);
element.element.falling_curve_interpolation = {};
element.keys = {sf::Keyboard::W, sf::Keyboard::Up};
element.element.type = Type::UP;
2021-11-02 13:47:42 -04:00
init.elements = {element};
_timeline->insertNote(new ClassicArrowNote(std::move(init)));
}
break;
}
}
2021-11-02 13:47:42 -04:00
}
void ClassicEditor::update(UpdateData&& updatedata)
2021-11-02 13:47:42 -04:00
{
_timeline->update(updatedata.timestamp);
2021-11-02 13:47:42 -04:00
}
void ClassicEditor::display() const
2021-10-05 14:48:28 -04:00
{
}
2021-10-05 14:48:28 -04:00
void ClassicEditor::recalculate(const microsec& timestamp)
{
_timeline->recalculate(timestamp);
}
void ClassicEditor::selectNoteType(Type type) noexcept
{
_selected_type = type;
2021-10-05 14:48:28 -04:00
}