blob: bbe1abc872bf5dd111a0a3bfc4fb197a86993052 (
plain)
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
57
|
// vim:ft=doxygen
namespace crepe {
/**
\defgroup feature_script_ecs Using ECS inside Script
\ingroup feature
\brief Query the component manager inside a concrete Script
Script provides several methods to request references to components during
runtime. These methods may be used in cases where it is either not practical or
impossible to manually pass the references required to implement a certain
behavior.
\see Script
\see ComponentManager
\par Example
\note This example assumes you already have a concrete Script. If not, read
\"\ref feature_script\" first.
The component manager can be queried for components inside Script using the
following methods:
- For requesting components on the same GameObject as this Script instance:
- Script::get_component(): \copybrief Script::get_component
- Script::get_components(): \copybrief Script::get_components
- For requesting components in the current Scene:
- Script::get_components_by_id(): \copybrief Script::get_components_by_id
- Script::get_components_by_name(): \copybrief Script::get_components_by_name
- Script::get_components_by_tag(): \copybrief Script::get_components_by_tag
```cpp
#include <crepe/util/Log.h>
#include <crepe/api/Script.h>
#include <crepe/api/Metadata.h>
using namespace crepe;
class MyScript : public Script {
void show_self() {
Metadata & own_metadata = get_component<Metadata>();
Log::logf("My name is {}", own_metadata.name);
}
void list_enemies() {
RefVector<Metadata> enemies = get_components_by_tag<Metadata>("enemy");
Log::logf("There are {} enemies:", enemies.size());
for (const Metadata & enemy : enemies) {
Log::logf("- {}", enemy.name);
}
}
};
```
*/
}
|