forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationHelper.cpp
More file actions
56 lines (50 loc) · 1.47 KB
/
NotificationHelper.cpp
File metadata and controls
56 lines (50 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "NotificationHelper.hpp"
#include "Components.hpp"
#include "EntitySystem.hpp"
#include "GUI.hpp"
void NotificationHelper::set_cooldown(EntitySystem& ents, std::size_t id, Ogre::Real val)
{
auto comp = ents.get_component<NotificationComponent>(id);
if(comp)
comp->cooldown = val;
}
Ogre::Real NotificationHelper::get_cooldown(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<NotificationComponent>(id);
if(comp)
return comp->cooldown;
else
return Ogre::Real{};
}
void NotificationHelper::reset(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<NotificationComponent>(id);
if(comp)
comp->curr_time = comp->cooldown;
}
bool NotificationHelper::notify(EntitySystem& ents, std::size_t id, const std::string& msg)
{
auto comp = ents.get_component<NotificationComponent>(id);
if(comp && comp->curr_time >= comp->cooldown)
{
GUI::instance().get_log().print("\\[" + std::to_string(id) + "\\] " + msg);
comp->curr_time = 0.f;
return true;
}
else
return false;
}
Ogre::Real NotificationHelper::get_curr_time(EntitySystem& ents, std::size_t id)
{
auto comp = ents.get_component<NotificationComponent>(id);
if(comp)
return comp->curr_time;
else
return Ogre::Real{};
}
void NotificationHelper::advance_curr_time(EntitySystem& ents, std::size_t id, Ogre::Real val)
{
auto comp = ents.get_component<NotificationComponent>(id);
if(comp) // Negative values intentionally allow for cooldown prolonging.
comp->curr_time += val;
}