#pragma once #include "../ComponentManager.h" #include "BehaviorScript.h" #include "Script.h" namespace crepe { template T & Script::get_component() const { using namespace std; vector> all_components = this->get_components(); if (all_components.size() < 1) throw runtime_error( format("Script: no component found with type = {}", typeid(T).name())); return all_components.back().get(); } template std::vector> Script::get_components() const { ComponentManager & mgr = *this->component_manager_ref; return mgr.get_components_by_id(*this->game_object_id_ref); } template void Script::logf(Args &&... args) { Log::logf(std::forward(args)...); } template void Script::subscribe_internal(const EventHandler & callback, event_channel_t channel) { EventManager & mgr = *this->event_manager_ref; subscription_t listener = mgr.subscribe([this, callback](const EventType & data) -> bool { bool & active = *this->active_ref; if (!active) return false; return callback(data); }, channel); this->listeners.push_back(listener); } template void Script::subscribe(const EventHandler & callback, event_channel_t channel) { this->subscribe_internal(callback, channel); } template void Script::subscribe(const EventHandler & callback) { this->subscribe_internal(callback, EventManager::CHANNEL_ALL); } } // namespace crepe