Implement logic for HoldManager

This commit is contained in:
NaiJi ✨ 2021-10-04 18:30:21 +03:00
parent 24aadf8174
commit 8579dc5507
9 changed files with 72 additions and 42 deletions

View File

@ -1,5 +1,6 @@
#include "classicarrownote.h"
#include "classicgraphicsmanager.h"
#include "holdmanager.h"
// Replace with interface by dependency injection
#include "classicflyinganimationscenario.h"
@ -64,7 +65,11 @@ void ClassicArrowNote::input(PlayerInput&& inputdata)
bool all_pressed = allElementsPressed();
if (all_pressed)
{
grade = _evaluator.calculatePrecision(inputdata.timestamp);
if (isHold())
_context->hold_manager->emplace(this);
}
if (all_pressed || !input_valid)
{
@ -138,3 +143,8 @@ bool ClassicArrowNote::isPressedAs(sf::Keyboard::Key key) const
return key == element.pressed_as;
});
}
bool ClassicArrowNote::isHold() const
{
return _is_hold;
}

View File

@ -16,6 +16,7 @@ public:
bool allElementsPressed() const;
bool isPressedAs(sf::Keyboard::Key key) const;
inline bool isHold() const;
private:

View File

@ -1,14 +1,17 @@
#include "classicgame.h"
#include "classicnote.h"
#include "classicmapcreator.h"
#include "holdmanager.h"
#include "context.h"
#include "tools/music.h"
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music) :
_graphics_manager(std::move(manager)),
_hold_manager(std::make_shared<HoldManager>(_graphics_manager)),
_music(std::move(music)),
_is_paused(false)
{
_slap_buffer.loadFromFile("very-final-slap.wav");
_slap_buffer.loadFromFile("Tick.ogg");
_slap.setBuffer(_slap_buffer);
_slap.setVolume(50);
@ -56,7 +59,9 @@ ClassicGame::~ClassicGame()
void ClassicGame::run()
{
ClassicMapCreator creator(_graphics_manager);
const auto context = std::make_shared<Context>(Context{_graphics_manager, _hold_manager});
ClassicMapCreator creator(context);
auto beatmap = creator.createBeatmap("aa");
_music->openFromFile("METEOR.flac");
_music->setVolume(10);
@ -99,29 +104,13 @@ void ClassicGame::input(PlayerInput&& inputdata)
auto note = (*note_it);
note->input(std::move(inputdata));
_slap.play();
/*if (note->isHold() && note->allElementsPressed()) // also check for Type
{
_notes_on_hold.emplace_back(note);
std::cout << "HOLD initited by " << inputdata.event.key.code << '\n';
}*/
}
}
break;
case sf::Event::KeyReleased:
{
/*bool key_match = std::any_of(_notes_on_hold.begin(), _notes_on_hold.end(),
[key=inputdata.event.key.code](const auto& note)
{
return note->isPressedAs(key);
});
if (key_match)
{
_notes_on_hold.clear();
std::cout << "HOLD released by " << inputdata.event.key.code << '\n';
}*/
_hold_manager->checkRelease(inputdata.event.key.code);
}
break;

View File

@ -1,5 +1,4 @@
#ifndef CLASSICGAME_H
#define CLASSICGAME_H
#pragma once
#include <map>
#include <memory>
@ -15,6 +14,7 @@
class Music;
class ClassicGraphicsManager;
class HoldManager;
class ClassicGame final : public Game
{
@ -34,6 +34,7 @@ private:
std::map<Type, Action> _buttons_to_released_actions;
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
std::shared_ptr<HoldManager> _hold_manager;
Timeline<ClassicNote> _timeline;
sf::SoundBuffer _slap_buffer;
@ -43,5 +44,3 @@ private:
bool _is_paused;
};
#endif // CLASSICGAME_H

View File

@ -6,8 +6,8 @@
#include "classicdyinganimationscenario.h"
//
ClassicMapCreator::ClassicMapCreator(const std::shared_ptr<ClassicGraphicsManager>& manager) :
_graphics_manager(manager)
ClassicMapCreator::ClassicMapCreator(const std::shared_ptr<Context> &context) :
_context(context)
{}
Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
@ -33,8 +33,6 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
int counter = 3;
const auto context = std::make_shared<Context>(Context{_graphics_manager});
while (bpm_iterator < bpm_end)
{
ArrowNoteInitializer init;
@ -42,7 +40,7 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
init.initializer.intervals = input_intervals;
init.initializer.perfect_offset = bpm_iterator;
init.hold = false;
init.initializer.context = context;
init.initializer.context = _context;
element.element.coordinates = {x, 390.};
element.element.falling_curve_interpolation = {};

View File

@ -1,12 +1,11 @@
#ifndef CLASSICMAPCREATOR_H
#define CLASSICMAPCREATOR_H
#pragma once
#include <set>
#include "tools/mathutils.h"
#include "core/note.h"
#include "classicnote.h"
#include "classicgraphicsmanager.h"
struct Context;
struct Beatmap
{
@ -17,12 +16,10 @@ struct Beatmap
class ClassicMapCreator
{
public:
explicit ClassicMapCreator(const std::shared_ptr<ClassicGraphicsManager>& manager);
explicit ClassicMapCreator(const std::shared_ptr<Context>& context);
Beatmap createBeatmap(const std::string& filepath) const;
private:
const std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
const std::shared_ptr<Context> _context;
};
#endif // CLASSICMAPCREATOR_H

View File

@ -3,8 +3,10 @@
#include <memory>
class ClassicGraphicsManager;
class HoldManager;
struct Context
{
std::shared_ptr<ClassicGraphicsManager> graphics_manager;
std::shared_ptr<HoldManager> hold_manager;
};

View File

@ -1,6 +1,36 @@
#include "holdmanager.h"
#include "classicarrownote.h"
#include <iostream>
/* THIS IS SIDEQUEST!!!! Right now I am working on the Editor >:C
*
* */
HoldManager::HoldManager(const std::shared_ptr<ClassicGraphicsManager>& graphics_manager) :
_graphics_manager(graphics_manager)
{}
void HoldManager::emplace(ClassicArrowNote* note)
{
_notes_on_hold.emplace_back(note);
}
void HoldManager::checkRelease(sf::Keyboard::Key released_key)
{
bool key_match = std::any_of(_notes_on_hold.begin(), _notes_on_hold.end(),
[released_key](const auto& note)
{
return note->isPressedAs(released_key);
});
if (key_match)
_notes_on_hold.clear();
}
void HoldManager::drawHoldBar()
{
if (_notes_on_hold.empty())
return;
/* taking proxy sprites for notes on hold
* and drawing on centered bar */
// _graphics_manager-> . . .
}

View File

@ -2,17 +2,21 @@
#include "core/inputtype.h"
#include <vector>
#include <memory>
class ClassicArrowNote;
class ClassicGraphicsManager;
class HoldManager // Not important now
class HoldManager
{
public:
explicit HoldManager() = default;
explicit HoldManager(const std::shared_ptr<ClassicGraphicsManager>& graphics_manager);
void emplace(ClassicArrowNote* note);
void checkRelease(sf::Keyboard::Key released_key);
void drawHoldBar();
private:
std::vector<ClassicArrowNote*> _notes_on_hold;
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
};