project-kyoku/src/modes/classicmode/game/classicgame.cpp

71 lines
1.8 KiB
C++
Raw Normal View History

2021-12-29 15:59:18 +01:00
#include "classicgame.h"
2022-02-10 00:30:49 +01:00
#include "classicmode/classicnote.h"
2021-12-29 15:59:18 +01:00
#include "classicmapcreator.h"
#include "graphics/classicscenegraphicsmanager.h"
#include "holdmanager.h"
ClassicGame::ClassicGame(const std::shared_ptr<kku::Timeline<ClassicNote>>& timeline,
const std::shared_ptr<ClassicGraphicsManager>& graphics_manager) :
_timeline(timeline),
_graphics_manager(graphics_manager),
_hold_manager(std::make_unique<HoldManager>())
{}
ClassicGame::~ClassicGame()
{}
void ClassicGame::run()
{
2022-02-10 00:30:49 +01:00
auto beatmap = classic::createBeatmap("aa", _hold_manager);
2021-12-29 15:59:18 +01:00
_timeline->setNotes(beatmap.notes);
}
void ClassicGame::input(kku::GameEvent&& input)
{
switch (input.event.type)
{
default:
return;
break;
case kku::SystemEvent::Type::KeyPress:
{
auto note_it = _timeline->getActiveNote(input.timestamp);
if (!_timeline->isExpired(note_it))
{
auto note = (*note_it);
note->input(std::move(input));
}
}
break;
case kku::SystemEvent::Type::KeyRelease:
{
_hold_manager->checkRelease(std::get<kku::SystemEvent::Key>(input.event.data).view);
}
break;
}
}
void ClassicGame::update(kku::UpdateData&& updatedata)
{
// UNCOMMENT TO TEST AUTOPLAY
2022-01-11 21:15:24 +01:00
/*auto note_it = _timeline->getActiveNote(updatedata.timestamp);
2021-12-29 15:59:18 +01:00
if (!_timeline->isExpired(note_it) && updatedata.timestamp >= (*note_it)->getPerfectOffset())
{
auto note = (*note_it);
note->input(kku::GameEvent{updatedata.timestamp, kku::SystemEvent{kku::SystemEvent::Type::None, kku::SystemEvent::Key{}}});
2022-01-11 21:15:24 +01:00
}*/
2021-12-29 15:59:18 +01:00
_timeline->update(updatedata.timestamp);
_graphics_manager->update(updatedata.timestamp);
}
void ClassicGame::display() const
{
_graphics_manager->display();
}