mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-03 10:26:29 +00:00
timer system for ui
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 &);
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user