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
+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));
}
}
}