diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-11-19 20:49:09 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-11-19 20:49:09 +0100 |
commit | 0f9f379a4dec7ad9d1dce30af5e2259931692c5f (patch) | |
tree | d84a76559d99fd6a3541d0087538564d79e39470 /src/crepe/api/Script.hpp | |
parent | 38a2476bcfa41b6d83a9a72d35f5acb684dc87fd (diff) | |
parent | 0476a8e9dbe7afb422862f7b1c15aaed7f3c416e (diff) |
merge with master
Diffstat (limited to 'src/crepe/api/Script.hpp')
-rw-r--r-- | src/crepe/api/Script.hpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index d96c0e8..a064a90 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -8,18 +8,21 @@ namespace crepe { template <typename T> -T & Script::get_component() { - std::vector<std::reference_wrapper<T>> all_components - = this->get_components<T>(); - if (all_components.size() < 1) throw nullptr; // TODO +T & Script::get_component() const { + using namespace std; + vector<reference_wrapper<T>> all_components = this->get_components<T>(); + if (all_components.size() < 1) + throw runtime_error( + format("Script: no component found with type = {}", typeid(T).name())); return all_components.back().get(); } template <typename T> -std::vector<std::reference_wrapper<T>> Script::get_components() { - ComponentManager & mgr = ComponentManager::get_instance(); - return mgr.get_components_by_id<T>(this->parent->game_object_id); +std::vector<std::reference_wrapper<T>> Script::get_components() const { + auto & mgr = *this->component_manager_ref; + + return mgr.get_components_by_id<T>(this->game_object_id); } } // namespace crepe |