diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-11 22:07:17 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2025-01-11 22:07:17 +0100 |
commit | cc8add56f9b8f0a32e7ab35a63454fed81eaacba (patch) | |
tree | e765a71b4a9b8798d99873fdcaf9487bc8f2954e /src/doc/feature/script_ecs.dox | |
parent | b6609ecd6636e65db76eb11617923222921d52d2 (diff) | |
parent | f06be6004ec8b47e3b4b1ba4fda068b365923683 (diff) |
Merge branch 'loek/doxygen'
Diffstat (limited to 'src/doc/feature/script_ecs.dox')
-rw-r--r-- | src/doc/feature/script_ecs.dox | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/doc/feature/script_ecs.dox b/src/doc/feature/script_ecs.dox new file mode 100644 index 0000000..8bd3376 --- /dev/null +++ b/src/doc/feature/script_ecs.dox @@ -0,0 +1,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>(); + logf("My name is {}", own_metadata.name); + } + + void list_enemies() { + RefVector<Metadata> enemies = get_components_by_tag<Metadata>("enemy"); + logf("There are {} enemies:", enemies.size()); + for (const Metadata & enemy : enemies) { + logf("- {}", enemy.name); + } + } +}; +``` + +*/ +} |