Implement logic for HoldManager
This commit is contained in:
parent
24aadf8174
commit
8579dc5507
|
@ -1,5 +1,6 @@
|
||||||
#include "classicarrownote.h"
|
#include "classicarrownote.h"
|
||||||
#include "classicgraphicsmanager.h"
|
#include "classicgraphicsmanager.h"
|
||||||
|
#include "holdmanager.h"
|
||||||
|
|
||||||
// Replace with interface by dependency injection
|
// Replace with interface by dependency injection
|
||||||
#include "classicflyinganimationscenario.h"
|
#include "classicflyinganimationscenario.h"
|
||||||
|
@ -64,7 +65,11 @@ void ClassicArrowNote::input(PlayerInput&& inputdata)
|
||||||
bool all_pressed = allElementsPressed();
|
bool all_pressed = allElementsPressed();
|
||||||
|
|
||||||
if (all_pressed)
|
if (all_pressed)
|
||||||
|
{
|
||||||
grade = _evaluator.calculatePrecision(inputdata.timestamp);
|
grade = _evaluator.calculatePrecision(inputdata.timestamp);
|
||||||
|
if (isHold())
|
||||||
|
_context->hold_manager->emplace(this);
|
||||||
|
}
|
||||||
|
|
||||||
if (all_pressed || !input_valid)
|
if (all_pressed || !input_valid)
|
||||||
{
|
{
|
||||||
|
@ -138,3 +143,8 @@ bool ClassicArrowNote::isPressedAs(sf::Keyboard::Key key) const
|
||||||
return key == element.pressed_as;
|
return key == element.pressed_as;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ClassicArrowNote::isHold() const
|
||||||
|
{
|
||||||
|
return _is_hold;
|
||||||
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public:
|
||||||
|
|
||||||
bool allElementsPressed() const;
|
bool allElementsPressed() const;
|
||||||
bool isPressedAs(sf::Keyboard::Key key) const;
|
bool isPressedAs(sf::Keyboard::Key key) const;
|
||||||
|
inline bool isHold() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
#include "classicgame.h"
|
#include "classicgame.h"
|
||||||
#include "classicnote.h"
|
#include "classicnote.h"
|
||||||
#include "classicmapcreator.h"
|
#include "classicmapcreator.h"
|
||||||
|
#include "holdmanager.h"
|
||||||
|
#include "context.h"
|
||||||
#include "tools/music.h"
|
#include "tools/music.h"
|
||||||
|
|
||||||
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music) :
|
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music) :
|
||||||
_graphics_manager(std::move(manager)),
|
_graphics_manager(std::move(manager)),
|
||||||
|
_hold_manager(std::make_shared<HoldManager>(_graphics_manager)),
|
||||||
_music(std::move(music)),
|
_music(std::move(music)),
|
||||||
_is_paused(false)
|
_is_paused(false)
|
||||||
{
|
{
|
||||||
_slap_buffer.loadFromFile("very-final-slap.wav");
|
_slap_buffer.loadFromFile("Tick.ogg");
|
||||||
_slap.setBuffer(_slap_buffer);
|
_slap.setBuffer(_slap_buffer);
|
||||||
_slap.setVolume(50);
|
_slap.setVolume(50);
|
||||||
|
|
||||||
|
@ -56,7 +59,9 @@ ClassicGame::~ClassicGame()
|
||||||
|
|
||||||
void ClassicGame::run()
|
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");
|
auto beatmap = creator.createBeatmap("aa");
|
||||||
_music->openFromFile("METEOR.flac");
|
_music->openFromFile("METEOR.flac");
|
||||||
_music->setVolume(10);
|
_music->setVolume(10);
|
||||||
|
@ -99,29 +104,13 @@ void ClassicGame::input(PlayerInput&& inputdata)
|
||||||
auto note = (*note_it);
|
auto note = (*note_it);
|
||||||
note->input(std::move(inputdata));
|
note->input(std::move(inputdata));
|
||||||
_slap.play();
|
_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;
|
break;
|
||||||
|
|
||||||
case sf::Event::KeyReleased:
|
case sf::Event::KeyReleased:
|
||||||
{
|
{
|
||||||
/*bool key_match = std::any_of(_notes_on_hold.begin(), _notes_on_hold.end(),
|
_hold_manager->checkRelease(inputdata.event.key.code);
|
||||||
[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';
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#ifndef CLASSICGAME_H
|
#pragma once
|
||||||
#define CLASSICGAME_H
|
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -15,6 +14,7 @@
|
||||||
|
|
||||||
class Music;
|
class Music;
|
||||||
class ClassicGraphicsManager;
|
class ClassicGraphicsManager;
|
||||||
|
class HoldManager;
|
||||||
|
|
||||||
class ClassicGame final : public Game
|
class ClassicGame final : public Game
|
||||||
{
|
{
|
||||||
|
@ -34,6 +34,7 @@ private:
|
||||||
std::map<Type, Action> _buttons_to_released_actions;
|
std::map<Type, Action> _buttons_to_released_actions;
|
||||||
|
|
||||||
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
||||||
|
std::shared_ptr<HoldManager> _hold_manager;
|
||||||
Timeline<ClassicNote> _timeline;
|
Timeline<ClassicNote> _timeline;
|
||||||
|
|
||||||
sf::SoundBuffer _slap_buffer;
|
sf::SoundBuffer _slap_buffer;
|
||||||
|
@ -43,5 +44,3 @@ private:
|
||||||
|
|
||||||
bool _is_paused;
|
bool _is_paused;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLASSICGAME_H
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
#include "classicdyinganimationscenario.h"
|
#include "classicdyinganimationscenario.h"
|
||||||
//
|
//
|
||||||
|
|
||||||
ClassicMapCreator::ClassicMapCreator(const std::shared_ptr<ClassicGraphicsManager>& manager) :
|
ClassicMapCreator::ClassicMapCreator(const std::shared_ptr<Context> &context) :
|
||||||
_graphics_manager(manager)
|
_context(context)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
|
Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
|
||||||
|
@ -33,8 +33,6 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
|
||||||
|
|
||||||
int counter = 3;
|
int counter = 3;
|
||||||
|
|
||||||
const auto context = std::make_shared<Context>(Context{_graphics_manager});
|
|
||||||
|
|
||||||
while (bpm_iterator < bpm_end)
|
while (bpm_iterator < bpm_end)
|
||||||
{
|
{
|
||||||
ArrowNoteInitializer init;
|
ArrowNoteInitializer init;
|
||||||
|
@ -42,7 +40,7 @@ Beatmap ClassicMapCreator::createBeatmap(const std::string& filepath) const
|
||||||
init.initializer.intervals = input_intervals;
|
init.initializer.intervals = input_intervals;
|
||||||
init.initializer.perfect_offset = bpm_iterator;
|
init.initializer.perfect_offset = bpm_iterator;
|
||||||
init.hold = false;
|
init.hold = false;
|
||||||
init.initializer.context = context;
|
init.initializer.context = _context;
|
||||||
|
|
||||||
element.element.coordinates = {x, 390.};
|
element.element.coordinates = {x, 390.};
|
||||||
element.element.falling_curve_interpolation = {};
|
element.element.falling_curve_interpolation = {};
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
#ifndef CLASSICMAPCREATOR_H
|
#pragma once
|
||||||
#define CLASSICMAPCREATOR_H
|
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
#include "tools/mathutils.h"
|
#include "tools/mathutils.h"
|
||||||
#include "core/note.h"
|
#include "classicnote.h"
|
||||||
|
|
||||||
#include "classicgraphicsmanager.h"
|
struct Context;
|
||||||
|
|
||||||
struct Beatmap
|
struct Beatmap
|
||||||
{
|
{
|
||||||
|
@ -17,12 +16,10 @@ struct Beatmap
|
||||||
class ClassicMapCreator
|
class ClassicMapCreator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit ClassicMapCreator(const std::shared_ptr<ClassicGraphicsManager>& manager);
|
explicit ClassicMapCreator(const std::shared_ptr<Context>& context);
|
||||||
|
|
||||||
Beatmap createBeatmap(const std::string& filepath) const;
|
Beatmap createBeatmap(const std::string& filepath) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
const std::shared_ptr<Context> _context;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CLASSICMAPCREATOR_H
|
|
||||||
|
|
|
@ -3,8 +3,10 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
class ClassicGraphicsManager;
|
class ClassicGraphicsManager;
|
||||||
|
class HoldManager;
|
||||||
|
|
||||||
struct Context
|
struct Context
|
||||||
{
|
{
|
||||||
std::shared_ptr<ClassicGraphicsManager> graphics_manager;
|
std::shared_ptr<ClassicGraphicsManager> graphics_manager;
|
||||||
|
std::shared_ptr<HoldManager> hold_manager;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,36 @@
|
||||||
#include "holdmanager.h"
|
#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-> . . .
|
||||||
|
}
|
||||||
|
|
|
@ -2,17 +2,21 @@
|
||||||
|
|
||||||
#include "core/inputtype.h"
|
#include "core/inputtype.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
class ClassicArrowNote;
|
class ClassicArrowNote;
|
||||||
|
class ClassicGraphicsManager;
|
||||||
|
|
||||||
class HoldManager // Not important now
|
class HoldManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit HoldManager() = default;
|
explicit HoldManager(const std::shared_ptr<ClassicGraphicsManager>& graphics_manager);
|
||||||
|
|
||||||
void emplace(ClassicArrowNote* note);
|
void emplace(ClassicArrowNote* note);
|
||||||
void checkRelease(sf::Keyboard::Key released_key);
|
void checkRelease(sf::Keyboard::Key released_key);
|
||||||
|
|
||||||
|
void drawHoldBar();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ClassicArrowNote*> _notes_on_hold;
|
std::vector<ClassicArrowNote*> _notes_on_hold;
|
||||||
|
std::shared_ptr<ClassicGraphicsManager> _graphics_manager;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue