forked from NaiJi/project-kyoku
Add debug helper and clean init code
parent
bf8e6be88f
commit
e37fb7b539
@ -0,0 +1,84 @@
|
||||
#include "debughelper.h"
|
||||
|
||||
DebugHelper::DebugHelper(bool init) :
|
||||
_toggled(init)
|
||||
{
|
||||
_bpm_pulse.setSize({460, 360});
|
||||
_bpm_pulse.setOrigin(0.f, 0.f);
|
||||
_bpm_pulse.setFillColor(sf::Color(255, 0, 0, 0));
|
||||
_tap_pulse.setSize({460, 360});
|
||||
_tap_pulse.move(460.f, 0.f);
|
||||
_tap_pulse.setFillColor(sf::Color(0, 255, 0, 0));
|
||||
_death_pulse.setSize({460, 360});
|
||||
_death_pulse.move(460.f, 360.f);
|
||||
_death_pulse.setFillColor(sf::Color(0, 100, 255, 0));
|
||||
|
||||
_font.loadFromFile("VeraMono.ttf");
|
||||
|
||||
_time_print.setFont(_font);
|
||||
_time_print.setPosition(60, 60);
|
||||
_time_print.setFillColor(sf::Color(255, 255, 255));
|
||||
_time_print.setCharacterSize(25);
|
||||
}
|
||||
|
||||
void DebugHelper::toggle()
|
||||
{
|
||||
_toggled = !_toggled;
|
||||
}
|
||||
|
||||
static bool isVisible(const sf::Shape* shape)
|
||||
{
|
||||
return shape->getFillColor().a > 0;
|
||||
}
|
||||
|
||||
void DebugHelper::update(const sf::Int64 µseconds)
|
||||
{
|
||||
_time_print.setString(std::to_string(microseconds));
|
||||
|
||||
if (isVisible(&_bpm_pulse))
|
||||
{
|
||||
const auto new_alpha = _bpm_pulse.getFillColor().a - 25;
|
||||
_bpm_pulse.setFillColor(sf::Color(255, 0, 0, (new_alpha < 0) ? 0 : new_alpha));
|
||||
}
|
||||
|
||||
if (isVisible(&_tap_pulse))
|
||||
{
|
||||
const auto new_alpha = _tap_pulse.getFillColor().a - 25;
|
||||
_tap_pulse.setFillColor(sf::Color(0, 255, 0, (new_alpha < 0) ? 0 : new_alpha));
|
||||
}
|
||||
|
||||
if (isVisible(&_death_pulse))
|
||||
{
|
||||
const auto new_alpha = _death_pulse.getFillColor().a - 25;
|
||||
_death_pulse.setFillColor(sf::Color(0, 100, 255, (new_alpha < 0) ? 0 : new_alpha));
|
||||
}
|
||||
}
|
||||
|
||||
void DebugHelper::drawOn(sf::RenderWindow &game_window) const
|
||||
{
|
||||
if (_toggled)
|
||||
{
|
||||
game_window.draw(_bpm_pulse);
|
||||
game_window.draw(_tap_pulse);
|
||||
game_window.draw(_death_pulse);
|
||||
game_window.draw(_time_print);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugHelper::onUserTap()
|
||||
{
|
||||
const sf::Uint8 alpha = 255;
|
||||
_tap_pulse.setFillColor(sf::Color(255, 0, 0, alpha));
|
||||
}
|
||||
|
||||
void DebugHelper::onBeat()
|
||||
{
|
||||
const sf::Uint8 alpha = 255;
|
||||
_bpm_pulse.setFillColor(sf::Color(0, 255, 0, alpha));
|
||||
}
|
||||
|
||||
void DebugHelper::onDeath()
|
||||
{
|
||||
const sf::Uint8 alpha = 255;
|
||||
_death_pulse.setFillColor(sf::Color(0, 100, 255, alpha));
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
#ifndef DEBUGHELPER_H
|
||||
#define DEBUGHELPER_H
|
||||
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
class DebugHelper
|
||||
{
|
||||
public:
|
||||
DebugHelper(bool init = true);
|
||||
|
||||
void toggle();
|
||||
void update(const sf::Int64& microseconds);
|
||||
void drawOn(sf::RenderWindow &game_window) const;
|
||||
void onUserTap();
|
||||
void onBeat();
|
||||
void onDeath();
|
||||
|
||||
private:
|
||||
bool _toggled;
|
||||
sf::RectangleShape _bpm_pulse;
|
||||
sf::RectangleShape _tap_pulse;
|
||||
sf::RectangleShape _death_pulse;
|
||||
sf::Font _font;
|
||||
sf::Text _time_print;
|
||||
};
|
||||
|
||||
#endif // DEBUGHELPER_H
|
Loading…
Reference in New Issue