-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameObject.cpp
50 lines (38 loc) · 915 Bytes
/
GameObject.cpp
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
#include "GameObject.hpp"
unsigned int GameObject::current_id(0);
GameObject::GameObject () :
_ID(current_id++)
{}
GameObject::~GameObject ()
{}
unsigned int GameObject::getId () const
{
return _ID;
}
bool GameObject::addComponent (Component *c)
{
if (_components.find(c->getName()) != _components.cend())
return false;
_components[c->getName()] = c;
return true;
}
bool GameObject::deleteComponent (const std::string & name)
{
auto it(_components.find(name));
if (it == _components.cend())
return false;
_components.erase(it);
return true;
}
Component* GameObject::getComponent (const std::string & name)
{
auto it(_components.find(name));
return it == _components.cend() ? nullptr : it->second;
}
std::list<std::string> GameObject::getComponentList () const
{
std::list<std::string> res;
for (auto e : _components)
res.push_back(e.first);
return res;
}