2021-10-05 14:48:28 -04:00
|
|
|
#include "classiceditor.h"
|
|
|
|
|
2021-11-24 13:21:30 -05:00
|
|
|
ClassicEditor::ClassicEditor(std::shared_ptr<ClassicGraphicsManager>&& manager) :
|
|
|
|
_graphics_manager(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-11-24 13:21:30 -05:00
|
|
|
_context.graphics_manager = _graphics_manager;
|
2021-12-06 14:18:04 -05:00
|
|
|
|
|
|
|
int basic_offset = 500000 * 6;
|
|
|
|
|
|
|
|
std::set<MockClassicNote*, NotePtrCompt> _set = {};
|
|
|
|
|
2021-12-08 13:00:47 -05:00
|
|
|
NoteInitializer init;
|
|
|
|
init.context = &_context;
|
|
|
|
init.intervals = {};
|
|
|
|
init.perfect_offset = basic_offset + (500000 * 20);
|
|
|
|
|
|
|
|
ElementInitializer elem_init;
|
|
|
|
elem_init.type = _selected_type;
|
|
|
|
elem_init.coordinates = Coordinates{ 700 - (5 * 120), 550 };
|
|
|
|
elem_init.falling_curve_interpolation = {};
|
|
|
|
|
|
|
|
MockArrowNoteInitializer mock_init;
|
|
|
|
mock_init.elements = {elem_init};
|
|
|
|
mock_init.initializer = init;
|
|
|
|
_set.insert(new MockClassicNote(std::move(mock_init)));
|
2021-12-06 14:18:04 -05:00
|
|
|
|
|
|
|
_timeline.setNotes(_set, 1648648);
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
2021-12-09 02:55:53 -05:00
|
|
|
microsec ClassicEditor::adjustOffset(microsec offset) const noexcept
|
|
|
|
{
|
|
|
|
microsec left = -1;
|
|
|
|
microsec right = -1;
|
|
|
|
|
|
|
|
std::set<microsec>::iterator i;
|
|
|
|
|
|
|
|
for (i = _ticks.begin(); i != _ticks.end(); ++i)
|
|
|
|
{
|
|
|
|
if (*i >= offset)
|
|
|
|
{
|
|
|
|
right = *i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (; i != _ticks.end(); --i)
|
|
|
|
{
|
|
|
|
if (*i <= offset)
|
|
|
|
{
|
|
|
|
left = *i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (right == -1)
|
|
|
|
offset = left;
|
|
|
|
else if (left == -1)
|
|
|
|
offset = right;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const microsec right_distance = right - offset;
|
|
|
|
const microsec left_distance = offset - left;
|
|
|
|
|
|
|
|
offset = (right_distance > left_distance)
|
|
|
|
? left_distance
|
|
|
|
: right_distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
2021-11-02 13:47:42 -04:00
|
|
|
void ClassicEditor::input(PlayerInput&& inputdata)
|
|
|
|
{
|
2021-12-03 14:21:27 -05:00
|
|
|
_current_time = inputdata.timestamp;
|
2021-11-24 13:21:30 -05:00
|
|
|
const auto& event = inputdata.event;
|
|
|
|
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sf::Event::MouseButtonPressed:
|
|
|
|
{
|
2021-12-03 14:21:27 -05:00
|
|
|
const auto note = _timeline.getNoteBy(_current_time);
|
2021-12-09 02:55:53 -05:00
|
|
|
if (_timeline.isExpired(note) && !_ticks.empty())
|
2021-11-24 13:21:30 -05:00
|
|
|
{
|
|
|
|
NoteInitializer init;
|
|
|
|
init.context = &_context;
|
|
|
|
init.intervals = {};
|
2021-12-09 02:55:53 -05:00
|
|
|
init.perfect_offset = adjustOffset(_current_time);
|
2021-11-24 13:21:30 -05:00
|
|
|
|
|
|
|
ElementInitializer elem_init;
|
|
|
|
elem_init.type = _selected_type;
|
|
|
|
elem_init.coordinates = Coordinates{ event.mouseButton.x, event.mouseButton.y };
|
|
|
|
elem_init.falling_curve_interpolation = {};
|
2021-11-02 13:47:42 -04:00
|
|
|
|
2021-11-24 13:21:30 -05:00
|
|
|
MockArrowNoteInitializer mock_init;
|
|
|
|
mock_init.elements = {elem_init};
|
|
|
|
mock_init.initializer = init;
|
|
|
|
|
|
|
|
_timeline.insertNote(new MockClassicNote(std::move(mock_init)));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
2021-12-03 14:21:27 -05:00
|
|
|
void ClassicEditor::update(UpdateData&& updatedata)
|
2021-11-02 13:47:42 -04:00
|
|
|
{
|
2021-12-03 14:21:27 -05:00
|
|
|
_timeline.update(updatedata.timestamp);
|
2021-11-24 13:21:30 -05:00
|
|
|
_timeline.fetchVisibleNotes();
|
2021-11-02 13:47:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicEditor::draw() const
|
2021-10-05 14:48:28 -04:00
|
|
|
{
|
2021-12-03 14:21:27 -05:00
|
|
|
const auto& graphics_manager = _graphics_manager;
|
|
|
|
auto notes = _timeline.getVisibleNotes();
|
|
|
|
|
|
|
|
std::for_each(notes.first, notes.second,
|
|
|
|
[graphics_manager](const auto& note)
|
|
|
|
{
|
|
|
|
note->draw();
|
|
|
|
});
|
2021-11-24 13:21:30 -05:00
|
|
|
}
|
2021-10-05 14:48:28 -04:00
|
|
|
|
2021-12-08 13:00:47 -05:00
|
|
|
void ClassicEditor::recalculate(const microsec& timestamp)
|
|
|
|
{
|
|
|
|
_timeline.recalculate(timestamp);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|