timer system for ui

This commit is contained in:
arthur.jamet
2021-06-16 13:26:48 +02:00
parent c1551f20de
commit a477ef1252
6 changed files with 66 additions and 12 deletions
+1 -10
View File
@@ -15,7 +15,7 @@ namespace BBM
: System(wal)
{}
void TimerSystem::onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime)
void TimerSystem::onUpdate(WAL::ViewEntity<TimerComponent> &entity, std::chrono::nanoseconds dtime)
{
auto &timer = entity.get<TimerComponent>();
timer.ringIn -= dtime;
@@ -23,14 +23,5 @@ namespace BBM
timer.setDisable(true);
timer.callback(entity, this->_wal);
}
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get());
if (text) {
unsigned long second = std::chrono::duration_cast<std::chrono::seconds>(timer.ringIn).count();
unsigned long minutes = second / 60;
second = second % 60;
text->setText(std::to_string(minutes) + ":" + std::to_string(second));
}
}
}
+2 -2
View File
@@ -11,11 +11,11 @@
namespace BBM
{
class TimerSystem : public WAL::System<TimerComponent, Drawable2DComponent>
class TimerSystem : public WAL::System<TimerComponent>
{
public:
//! @inherit
void onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime) override;
void onUpdate(WAL::ViewEntity<TimerComponent> &entity, std::chrono::nanoseconds dtime) override;
//! @brief A default constructor
TimerSystem(WAL::Wal &);
+30
View File
@@ -0,0 +1,30 @@
//
// Created by Zoe Roux on 5/31/21.
//
#include "TimerUISystem.hpp"
#include "Component/Timer/TimerComponent.hpp"
#include "Drawables/2D/Text.hpp"
using namespace std::chrono_literals;
namespace RAY2D = RAY::Drawables::Drawables2D;
namespace BBM
{
TimerUISystem::TimerUISystem(WAL::Wal &wal)
: System(wal)
{}
void TimerUISystem::onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime)
{
auto &timer = entity.get<TimerComponent>();
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.get<Drawable2DComponent>().drawable.get());
if (text) {
unsigned long second = std::chrono::duration_cast<std::chrono::seconds>(timer.ringIn).count();
unsigned long minutes = second / 60;
second = second % 60;
text->setText(std::to_string(minutes) + ":" + std::to_string(second));
}
}
}
+29
View File
@@ -0,0 +1,29 @@
//
// Created by Zoe Roux on 5/31/21.
//
#pragma once
#include <System/System.hpp>
#include <Wal.hpp>
#include <Component/Timer/TimerComponent.hpp>
#include "Component/Renderer/Drawable2DComponent.hpp"
namespace BBM
{
class TimerUISystem : public WAL::System<TimerComponent, Drawable2DComponent>
{
public:
//! @inherit
void onUpdate(WAL::ViewEntity<TimerComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime) override;
//! @brief A default constructor
TimerUISystem(WAL::Wal &);
//! @brief A timer system is copy constructable.
TimerUISystem(const TimerUISystem &) = default;
//! @brief A default destructor
~TimerUISystem() override = default;
//! @breief A timer system is assignable.
TimerUISystem &operator=(const TimerUISystem &) = default;
};
}