Adjust editor process to new editor context

selection
NaiJi ✨ 2 years ago
parent c24ecc0acc
commit 90292750fb

@ -21,13 +21,10 @@ bool Application::init()
[&](){ pushState(GUIState::Tag::ABOUT); },
};
EditorState::Callbacks editor_callbacks = {[&](){ popState(); }};
About::Callbacks about_callbacks = {[&](){ popState(); }};
const auto main_menu = std::make_shared<MainMenu>(_core_factory, std::move(callbacks));
const auto game_state = std::make_shared<GameState>(_core_factory, classic::getGame(_core_factory), GameState::Callbacks());
const auto editor = std::make_shared<EditorState>(_core_factory, classic::getEditor(_core_factory), std::move(editor_callbacks));
const auto about = std::make_shared<About>(_core_factory, std::move(about_callbacks));
const auto game_state = std::make_shared<GameState>(_core_factory, classic::getGame(_core_factory), GameState::Callbacks{[&](){ popState(); }});
const auto editor = std::make_shared<EditorState>(_core_factory, classic::getEditor(_core_factory), EditorState::Callbacks{[&](){ popState(); }});
const auto about = std::make_shared<About>(_core_factory, About::Callbacks{[&](){ popState(); }});
_states[GUIState::Tag::MAIN_MENU] = main_menu;
_states[GUIState::Tag::GAME] = game_state;

@ -20,8 +20,11 @@ void GameState::input(const kku::SystemEvent& event)
break;
case kku::SystemEvent::Type::KeyRelease:
if (std::get<kku::SystemEvent::Key>(event.data).view == kku::SystemEvent::Key::Code::Space)
const auto view = std::get<kku::SystemEvent::Key>(event.data).view;
if (view == kku::SystemEvent::Key::Code::Space)
_music->isPlaying() ? _music->pause() : _music->play();
if (view == kku::SystemEvent::Key::Code::Escape)
_onLeaveGameCallback();
}
_game->input(kku::GameEvent{_music->fetchOffset(), event});
@ -48,5 +51,5 @@ void GameState::enter()
void GameState::leave()
{
_onLeaveGameCallback();
_music->stop();
}

@ -8,6 +8,7 @@
#include "game/gamecontext.h"
#include "game/holdmanager.h"
#include "editor/classiceditor.h"
#include "editor/editorcontext.h"
#include "editor/selectionmanager.h"
@ -33,7 +34,11 @@ std::unique_ptr<kku::Editor> classic::getEditor(const std::shared_ptr<kku::CoreF
const auto factory = std::make_shared<ClassicGraphicsFactory>(core_factory);
const auto timeline = std::make_shared<kku::Timeline<ClassicNote>>();
const auto graphics_manager = std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset);
const auto selection_manager = std::make_shared<SelectionManager<ClassicNote>>();
std::vector<std::shared_ptr<ClassicGraphicsManager>> graphics_managers;
graphics_managers.emplace_back(std::make_shared<ClassicSceneGraphicsManager>(timeline, factory, visibility_offset));
const auto context = std::make_shared<EditorContext>(selection_manager, std::move(graphics_managers));
return nullptr;//std::make_unique<ClassicEditor>(timeline, graphics_manager);
return std::make_unique<ClassicEditor>(timeline, context);
}

@ -8,19 +8,19 @@
#include "graphics/animations/classicdyinganimationscenario.h"
//
#include "game/classicarrownote.h"
#include "editorcontext.h"
#include "callbacks/callbacksimple.h"
ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager,
const std::shared_ptr<SelectionManager<ClassicNote>>& selection_manager) :
const std::shared_ptr<EditorContext>& context) :
_timeline(timeline),
_graphics_manager(graphics_manager),
_selection_manager(selection_manager),
_context(context),
_selected_type(Type::UP),
_current_time(0),
_scroll_step(500000)
{
/*kku::microsec starting_beat_offset = 402162;
kku::microsec starting_beat_offset = 402162;
int amount_of_beats = 209;
kku::microsec interval = 1412162;
kku::microsec tempo_interval = interval / 4;
@ -41,35 +41,42 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
while (bpm_iterator < bpm_end)
{
ArrowNoteInitializer init;
ArrowElementInitializer element;
init.initializer.intervals = input_intervals;
init.initializer.perfect_offset = bpm_iterator;
init.hold = false;
ArrowElement element;
element.element.position = kku::Point(x, 390.f);
element.element.falling_curve_interpolation = {};
element.position = kku::Point(x, 390.f);
element.falling_curve_interpolation = {};
element.keys = {kku::SystemEvent::Key::Code::W,
kku::SystemEvent::Key::Code::Up};
element.element.type = Type::UP;
element.type = Type::UP;
bool hold = false;
if (counter == 0)
{
init.hold = true;
hold = true;
element.keys = {kku::SystemEvent::Key::Code::D,
kku::SystemEvent::Key::Code::Right};
element.element.type = Type::RIGHT;
element.type = Type::RIGHT;
counter = 13;
}
--counter;
init.elements = {element};
ClassicArrowNote::Init init
{
context,
bpm_iterator,
input_intervals,
{element},
hold
};
notes.insert(new ClassicMockNote(std::move(init), _selection_manager));
notes.insert(new ClassicArrowNote(std::move(init)));
bpm_iterator += tempo_interval;
x += 70;
@ -78,7 +85,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>&
x = 90.;
}
_timeline->setNotes(notes);*/
_timeline->setNotes(notes);
}
kku::microsec ClassicEditor::adjustOffset(kku::microsec offset) const noexcept
@ -86,13 +93,13 @@ kku::microsec ClassicEditor::adjustOffset(kku::microsec offset) const noexcept
const auto& section = getBPMSectionAt(offset);
const kku::microsec actual_offset = offset - section.offset_start;
return actual_offset + (actual_offset % section.interval);
return actual_offset + (actual_offset % (section.interval + 1));
}
void ClassicEditor::input(kku::GameEvent&& input)
{
_current_time = input.timestamp;
//const auto& event = input.event;
const auto& event = input.event;
switch (input.event.type)
{
@ -105,7 +112,7 @@ void ClassicEditor::input(kku::GameEvent&& input)
const auto key_data = std::get<kku::SystemEvent::Key>(input.event.data);
if (key_data.view == kku::SystemEvent::Key::Code::LControl)
{
_selection_manager->enableMultiselection(true);
_context->getSelectionManager()->enableMultiselection(true);
}
break;
}
@ -115,39 +122,42 @@ void ClassicEditor::input(kku::GameEvent&& input)
const auto key_data = std::get<kku::SystemEvent::Key>(input.event.data);
if (key_data.view == kku::SystemEvent::Key::Code::LControl)
{
_selection_manager->enableMultiselection(false);
_context->getSelectionManager()->enableMultiselection(false);
}
break;
}
case kku::SystemEvent::Type::MousePress:
{
/*const auto note = _timeline->getNoteBy(_current_time);
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 = input.timestamp;
init.hold = false;
ArrowElement element;
element.element.position = std::get<kku::SystemEvent::Mouse>(event.data).position;
element.element.falling_curve_interpolation = {};
element.position = std::get<kku::SystemEvent::Mouse>(event.data).position;
element.falling_curve_interpolation = {};
element.keys = {kku::SystemEvent::Key::Code::W,
kku::SystemEvent::Key::Code::Up};
element.element.type = Type::UP;
element.type = Type::UP;
init.elements = { element };
ClassicArrowNote::Init init
{
_context,
_current_time,
{},
{element},
false
};
_timeline->insertNote(new ClassicMockNote(std::move(init), _selection_manager));
_timeline->insertNote(new ClassicArrowNote(std::move(init)));
}
if (!_selection_manager->isMultiselectionEnabled())
_selection_manager->discard();
if (!_context->getSelectionManager()->isMultiselectionEnabled())
_context->getSelectionManager()->discard();
_graphics_manager->input(std::move(input));*/
//_graphics_manager->input(std::move(input));
break;
}
@ -158,11 +168,12 @@ void ClassicEditor::input(kku::GameEvent&& input)
void ClassicEditor::update(kku::UpdateData&& updatedata)
{
_timeline->update(updatedata.timestamp);
_context->updateGraphics(updatedata.timestamp);
}
void ClassicEditor::display() const
{
_graphics_manager->display();
_context->displayGraphics();
}
void ClassicEditor::recalculate(const kku::microsec& timestamp)

@ -9,14 +9,13 @@
#include "classicmode/classicnote.h"
#include "classicmode/classicactions.h"
class ClassicGraphicsManager;
class EditorContext;
class ClassicEditor : public kku::Editor
{
public:
explicit ClassicEditor(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager,
const std::shared_ptr<SelectionManager<ClassicNote>>& selection_manager);
const std::shared_ptr<EditorContext>& context);
virtual void input(kku::GameEvent&& input) override;
virtual void update(kku::UpdateData&& updatedata) override;
@ -29,8 +28,8 @@ private:
inline kku::microsec adjustOffset(kku::microsec offset) const noexcept;
const std::shared_ptr<kku::Timeline<ClassicNote>> _timeline;
const std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
const std::shared_ptr<SelectionManager<ClassicNote>> _selection_manager;
const std::shared_ptr<EditorContext> _context;
Type _selected_type;
kku::microsec _current_time;

@ -0,0 +1,103 @@
#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<ClassicNote>>& 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
{
(void)note;
switch (input.event.type)
{
default:
break;
/*case kku::SystemEvent::Type::MousePress:
{
bool selection_changed = false;
std::size_t amount_selected = 0;
const auto position = std::get<kku::SystemEvent::Mouse>(input.event.data).position;
for (auto& element : note->getElements())
{
if (element.sprite->getRectangle()->contains(position))
{
element.selected = !element.selected;
selection_changed = true;
if (element.selected)
++amount_selected;
}
}
if (selection_changed)
{
if (amount_selected > 0)
_selection_manager->fetch(note);
else
_selection_manager->remove(note);
}
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);
break;
}
for (auto& element : elements)
if (element.animations[note->getState()])
element.animations[note->getState()]->update(music_offset);
}
std::shared_ptr<SelectionManager<ClassicNote>> EditorContext::getSelectionManager() const
{
return _selection_manager;
}
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();
}

@ -0,0 +1,28 @@
#pragma once
#include <memory>
#include <vector>
#include "classicmode/classicnote.h"
#include "classicmode/context.h"
#include "editor/selectionmanager.h"
class ClassicGraphicsManager;
class EditorContext : public Context
{
public:
explicit EditorContext(const std::shared_ptr<SelectionManager<ClassicNote>>& selection_manager,
std::vector<std::shared_ptr<ClassicGraphicsManager>>&& graphics_managers);
virtual void input(ClassicArrowNote *note, kku::GameEvent&& input) const override;
virtual void update(ClassicArrowNote *note, const kku::microsec &music_offset) const override;
void updateGraphics(const kku::microsec& music_offset);
void displayGraphics() const;
std::shared_ptr<SelectionManager<ClassicNote>> getSelectionManager() const;
private:
const std::shared_ptr<SelectionManager<ClassicNote>> _selection_manager;
const std::vector<std::shared_ptr<ClassicGraphicsManager>> _graphics_managers;
};

@ -8,14 +8,11 @@ class SelectionManager
{
public:
SelectionManager() :
_multiselection_enabled(false),
deselection([](T* thing) { thing->deselect(); })
_multiselection_enabled(false)
{}
// Remove whole selection completely
void discard()
{
apply(deselection);
_selected_things.clear();
}
@ -44,6 +41,15 @@ public:
}
}
bool isSelected(const T * const thing) const
{
for (const auto& selected_thing : thing)
if (thing == selected_thing)
return true;
return false;
}
void enableMultiselection(bool enable = true)
{
_multiselection_enabled = enable;
@ -63,6 +69,4 @@ public:
private:
std::vector<T*> _selected_things;
bool _multiselection_enabled;
const std::function<void(T*)> deselection;
};

@ -11,9 +11,6 @@ ClassicGame::ClassicGame(const std::shared_ptr<kku::Timeline<ClassicNote>>& time
_context(context)
{}
ClassicGame::~ClassicGame()
{}
void ClassicGame::run()
{
auto beatmap = classic::createBeatmap("aa", _context);

@ -16,7 +16,6 @@ class ClassicGame final : public kku::Game
public:
explicit ClassicGame(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<GameContext>& context);
virtual ~ClassicGame() override;
virtual void run() override;

Loading…
Cancel
Save