forked from NaiJi/project-kyoku
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
#include "classiceditor.h"
|
|
|
|
ClassicEditor::ClassicEditor(std::shared_ptr<ClassicGraphicsManager>&& manager) :
|
|
_graphics_manager(manager),
|
|
_selected_type(Type::UP),
|
|
_current_time(0)
|
|
{
|
|
_context.graphics_manager = _graphics_manager;
|
|
_timeline.setNotes({}, 1648648);
|
|
}
|
|
|
|
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))
|
|
{
|
|
NoteInitializer init;
|
|
init.context = &_context;
|
|
init.intervals = {};
|
|
init.perfect_offset = _current_time;
|
|
|
|
ElementInitializer elem_init;
|
|
elem_init.type = _selected_type;
|
|
elem_init.coordinates = Coordinates{ event.mouseButton.x, event.mouseButton.y };
|
|
elem_init.falling_curve_interpolation = {};
|
|
|
|
MockArrowNoteInitializer mock_init;
|
|
mock_init.elements = {elem_init};
|
|
mock_init.initializer = init;
|
|
|
|
_timeline.insertNote(new MockClassicNote(std::move(mock_init)));
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
void ClassicEditor::update(UpdateData&& updatedata)
|
|
{
|
|
_timeline.update(updatedata.timestamp);
|
|
_timeline.fetchVisibleNotes();
|
|
}
|
|
|
|
void ClassicEditor::draw() const
|
|
{
|
|
const auto& graphics_manager = _graphics_manager;
|
|
auto notes = _timeline.getVisibleNotes();
|
|
|
|
std::for_each(notes.first, notes.second,
|
|
[graphics_manager](const auto& note)
|
|
{
|
|
note->draw();
|
|
});
|
|
}
|
|
|
|
void ClassicEditor::selectNoteType(Type type) noexcept
|
|
{
|
|
_selected_type = type;
|
|
}
|