-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathComponentModule.cpp
More file actions
53 lines (51 loc) · 1.47 KB
/
Copy pathComponentModule.cpp
File metadata and controls
53 lines (51 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
#include "ComponentModule.h"
namespace sh::game
{
auto ComponentModule::GetComponents() -> std::unordered_map<std::string, std::unique_ptr<IComponentType>>&
{
return components;
}
auto ComponentModule::GetComponents() const -> const std::unordered_map<std::string, std::unique_ptr<IComponentType>>&
{
return components;
}
auto ComponentModule::GetComponent(std::string_view name) const -> IComponentType*
{
auto it = components.find(std::string{ name });
if (it == components.end())
return nullptr;
return it->second.get();
}
SH_GAME_API void ComponentModule::RegisterWaitingComponents()
{
for (auto& componentInfo : waitingComponents)
components.insert_or_assign(componentInfo.name, std::move(componentInfo.componentType));
waitingComponents.clear();
}
SH_GAME_API auto ComponentModule::GetWaitingComponents() const -> const std::vector<ComponentInfo>&
{
return waitingComponents;
}
SH_GAME_API void ComponentModule::DestroyComponent(const std::string& name)
{
auto it = components.find(name);
if (it != components.end())
components.erase(it);
}
SH_GAME_API void ComponentModule::DestroyComponent(const std::string& name, const std::string& group)
{
std::string fullName{};
if (group.size() == 0)
fullName = name;
else
{
fullName.reserve(group.size() + name.size() + 1);
fullName = group;
fullName += '/';
fullName += name;
}
auto it = components.find(fullName);
if (it != components.end())
components.erase(it);
}
}