You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.1 KiB
C++

#include "editorcontext.h"
#include "game/classicarrownote.h"
#include "graphics/animations/classicanimationscenario.h"
#include "graphics/classicgraphicsmanager.h"
#include "graphics/classicnotegraphics.h"
EditorContext::EditorContext(
const std::shared_ptr<SelectionManager> &selection_manager,
std::vector<std::shared_ptr<ClassicGraphicsManager>> &&graphics_managers)
: _selection_manager(selection_manager),
_graphics_managers(std::move(graphics_managers))
{
}
void EditorContext::input(ClassicArrowNote *note, kku::GameEvent &&input) const
{
switch (input.event.type)
{
default:
break;
case kku::SystemEvent::Type::MousePress:
{
const auto clicked_position =
std::get<kku::SystemEvent::Mouse>(input.event.data).position;
for (auto &element : note->getElements())
{
if (element.sprite->getRectangle()->contains(clicked_position))
{
if (_selection_manager->isSelected(note->getId(), element.id))
_selection_manager->remove(note->getId(), element.id);
else
_selection_manager->fetch(note->getId(), element.id);
}
}
break;
}
}
}
void EditorContext::update(ClassicArrowNote *note,
const kku::microsec &music_offset) const
{
auto &elements = note->getElements();
switch (note->getState())
{
default:
return;
break;
case ClassicArrowNote::State::INITIAL:
note->setState(ClassicArrowNote::State::FLYING);
for (auto &manager : _graphics_managers)
manager->update(music_offset, note);
break;
case ClassicArrowNote::State::FLYING:
if (!note->isActive(music_offset) &&
music_offset > note->getPerfectOffset())
{
note->setState(ClassicArrowNote::State::DYING);
for (auto &element : elements)
element.animations[note->getState()]->launch(
element.sprite, music_offset, note->getPerfectOffset());
}
break;
case ClassicArrowNote::State::DYING:
if (elements[0].animations[note->getState()]->isDone())
{
note->setState(ClassicArrowNote::State::DEAD);
for (auto &manager : _graphics_managers)
manager->update(music_offset, note);
}
break;
}
for (auto &element : elements)
if (element.animations[note->getState()])
element.animations[note->getState()]->update(music_offset);
}
std::shared_ptr<SelectionManager> EditorContext::getSelectionManager() const
{
return _selection_manager;
}
void EditorContext::inputUI(kku::GameEvent &&input)
{
for (auto &manager : _graphics_managers)
manager->input(std::move(input));
}
void EditorContext::updateGraphics(const kku::microsec &music_offset)
{
for (auto &manager : _graphics_managers)
manager->update(music_offset);
}
void EditorContext::displayGraphics() const
{
for (const auto &manager : _graphics_managers)
manager->display();
}