55 lines
1.3 KiB
C++
55 lines
1.3 KiB
C++
#include "Sequencer.h"
|
|
#include "Figments/MainLoop.h"
|
|
|
|
Sequencer::Sequencer(std::vector<Sequencer::Scene> &&scenes) :
|
|
Task("SceneSequencer"),
|
|
m_scenes(std::move(scenes))
|
|
{
|
|
}
|
|
|
|
void
|
|
Sequencer::loop() {}
|
|
|
|
const char*
|
|
Sequencer::currentSceneName()
|
|
{
|
|
return m_scenes[m_idx].name;
|
|
}
|
|
|
|
const std::vector<Sequencer::Scene>
|
|
Sequencer::scenes() const
|
|
{
|
|
return m_scenes;
|
|
}
|
|
|
|
void
|
|
Sequencer::handleEvent(const InputEvent& evt)
|
|
{
|
|
if (evt.intent == InputEvent::SetPattern || evt.intent == InputEvent::NextPattern || evt.intent == InputEvent::PreviousPattern) {
|
|
Log.info("Switching pattern!");
|
|
for(const char* pattern : m_scenes[m_idx].patterns) {
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StopThing, pattern});
|
|
}
|
|
|
|
if (evt.intent == InputEvent::NextPattern) {
|
|
m_idx++;
|
|
} else if (evt.intent == InputEvent::PreviousPattern) {
|
|
m_idx--;
|
|
} else {
|
|
m_idx = evt.asInt();
|
|
}
|
|
|
|
if (m_idx < 0) {
|
|
m_idx = m_scenes.size() - 1;
|
|
}
|
|
|
|
if (m_idx >= m_scenes.size()) {
|
|
m_idx = 0;
|
|
}
|
|
|
|
for(const char* pattern : m_scenes[m_idx].patterns) {
|
|
MainLoop::instance()->dispatch(InputEvent{InputEvent::StartThing, pattern});
|
|
}
|
|
}
|
|
}
|