forked from Dzejrou/tdt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEventHandlerHelper.cpp
More file actions
44 lines (38 loc) · 1.17 KB
/
EventHandlerHelper.cpp
File metadata and controls
44 lines (38 loc) · 1.17 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
#include "EventHandlerHelper.hpp"
#include "Components.hpp"
#include "EntitySystem.hpp"
void EventHandlerHelper::set_handler(EntitySystem& ents, std::size_t id, const std::string& val)
{
auto comp = ents.get_component<EventHandlerComponent>(id);
if(comp)
comp->handler = val;
}
const std::string & EventHandlerHelper::get_handler(EntitySystem& ents, std::size_t id)
{
static std::string NO_HANDLER{"ERROR"};
auto comp = ents.get_component<EventHandlerComponent>(id);
if(comp)
return comp->handler;
else
return NO_HANDLER;
}
bool EventHandlerHelper::can_handle(EntitySystem& ents, std::size_t id, EVENT_TYPE val)
{
auto comp = ents.get_component<EventHandlerComponent>(id);
if(comp)
return comp->possible_events.test((int)val);
else
return false;
}
void EventHandlerHelper::add_possible_event(EntitySystem& ents, std::size_t id, EVENT_TYPE val)
{
auto comp = ents.get_component<EventHandlerComponent>(id);
if(comp)
comp->possible_events.set((int)val);
}
void EventHandlerHelper::delete_possible_event(EntitySystem& ents, std::size_t id, EVENT_TYPE val)
{
auto comp = ents.get_component<EventHandlerComponent>(id);
if(comp)
comp->possible_events.set((int)val, false);
}