From 195f7770c42aa1ed1052725dde26699d2ecc689f Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Fri, 25 Oct 2024 20:46:32 +0200 Subject: implement get_component for scripts --- src/crepe/api/Script.hpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/crepe/api/Script.hpp (limited to 'src/crepe/api/Script.hpp') diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp new file mode 100644 index 0000000..8ddd344 --- /dev/null +++ b/src/crepe/api/Script.hpp @@ -0,0 +1,26 @@ +#pragma once + +#include "../ComponentManager.h" + +#include "Script.h" +#include "BehaviorScript.h" + +namespace crepe::api { + +template +T & Script::get_component() { + std::vector> all_components = this->get_components(); + if (all_components.size() < 1) + throw nullptr; // TODO + + return all_components.back().get(); +} + +template +std::vector> Script::get_components() { + ComponentManager & mgr = ComponentManager::get_instance(); + return mgr.get_components_by_id(this->parent->game_object_id); +} + +} + -- cgit v1.2.3