diff options
Diffstat (limited to 'src/crepe/api')
-rw-r--r-- | src/crepe/api/Animator.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/BehaviorScript.hpp | 3 | ||||
-rw-r--r-- | src/crepe/api/Camera.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Script.h | 78 | ||||
-rw-r--r-- | src/crepe/api/Script.hpp | 23 | ||||
-rw-r--r-- | src/crepe/api/Sprite.cpp | 2 | ||||
-rw-r--r-- | src/crepe/api/Transform.cpp | 2 |
7 files changed, 64 insertions, 48 deletions
diff --git a/src/crepe/api/Animator.cpp b/src/crepe/api/Animator.cpp index 4ce4bf0..203cef3 100644 --- a/src/crepe/api/Animator.cpp +++ b/src/crepe/api/Animator.cpp @@ -1,5 +1,5 @@ -#include "util/Log.h" +#include "util/dbg.h" #include "Animator.h" #include "Component.h" diff --git a/src/crepe/api/BehaviorScript.hpp b/src/crepe/api/BehaviorScript.hpp index b9bb1e2..353d5e2 100644 --- a/src/crepe/api/BehaviorScript.hpp +++ b/src/crepe/api/BehaviorScript.hpp @@ -2,8 +2,6 @@ #include <type_traits> -#include "../util/Log.h" - #include "BehaviorScript.h" #include "Script.h" @@ -11,7 +9,6 @@ namespace crepe { template <class T, typename... Args> BehaviorScript & BehaviorScript::set_script(Args &&... args) { - dbg_trace(); static_assert(std::is_base_of<Script, T>::value); this->script = std::unique_ptr<Script>(new T(std::forward<Args>(args)...)); diff --git a/src/crepe/api/Camera.cpp b/src/crepe/api/Camera.cpp index 179dc18..19a3296 100644 --- a/src/crepe/api/Camera.cpp +++ b/src/crepe/api/Camera.cpp @@ -1,4 +1,4 @@ -#include "util/Log.h" +#include "util/dbg.h" #include "Camera.h" #include "Component.h" diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index c797db0..18a029b 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -8,6 +8,7 @@ #include "../system/CollisionSystem.h" #include "../types.h" #include "../util/OptionalRef.h" +#include "../util/Log.h" namespace crepe { @@ -58,83 +59,85 @@ protected: protected: /** - * \name Utility functions + * \name Component query functions + * \see ComponentManager * \{ */ - /** * \brief Get single component of type \c T on this game object - * * \tparam T Type of component - * * \returns Reference to component - * * \throws std::runtime_error if this game object does not have a component with type \c T */ template <typename T> T & get_component() const; - // TODO: make get_component calls for component types that can have more than 1 instance - // cause compile-time errors - /** * \brief Get all components of type \c T on this game object - * * \tparam T Type of component - * * \returns List of component references */ template <typename T> RefVector<T> get_components() const; - - /** - * \copydoc ComponentManager::get_components_by_id - * \see ComponentManager::get_components_by_id - */ + //! \copydoc ComponentManager::get_components_by_id template <typename T> RefVector<T> get_components_by_id(game_object_id_t id) const; - /** - * \copydoc ComponentManager::get_components_by_name - * \see ComponentManager::get_components_by_name - */ + //! \copydoc ComponentManager::get_components_by_name template <typename T> RefVector<T> get_components_by_name(const std::string & name) const; - /** - * \copydoc ComponentManager::get_components_by_tag - * \see ComponentManager::get_components_by_tag - */ + //! \copydoc ComponentManager::get_components_by_tag template <typename T> RefVector<T> get_components_by_tag(const std::string & tag) const; + //! \} /** - * \brief Log a message using Log::logf - * - * \tparam Args Log::logf parameters - * \param args Log::logf parameters + * \name Logging functions + * \see Log + * \{ */ - template <typename... Args> - void logf(Args &&... args); + //! \copydoc Log::logf + template <class... Args> + void logf(const Log::Level & level, std::format_string<Args...> fmt, Args &&... args); + //! \copydoc Log::logf + template <class... Args> + void logf(std::format_string<Args...> fmt, Args &&... args); + // \} /** - * \brief Subscribe to an event with an explicit channel - * \see EventManager::subscribe + * \name Event manager functions + * \see EventManager + * \{ */ + //! \copydoc EventManager::subscribe template <typename EventType> void subscribe(const EventHandler<EventType> & callback, event_channel_t channel); - /** - * \brief Subscribe to an event on EventManager::CHANNEL_ALL - * \see EventManager::subscribe - */ + //! \copydoc EventManager::subscribe template <typename EventType> void subscribe(const EventHandler<EventType> & callback); + //! \copydoc EventManager::trigger_event + template <typename EventType> + void trigger_event(const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL); + //! \copydoc EventManager::queue_event + template <typename EventType> + void queue_event(const EventType & event = {}, event_channel_t channel = EventManager::CHANNEL_ALL); + //! \} /** - * \brief Set the next scene using SceneManager - * \see SceneManager::set_next_scene + * \name Scene-related functions + * \see SceneManager + * \{ */ + //! \copydoc SceneManager::set_next_scene void set_next_scene(const std::string & name); + //! \} + /** + * \name Save data management functions + * \see SaveManager + * \{ + */ //! Retrieve SaveManager reference SaveManager & get_save_manager() const; + //! \} //! Replay management functions struct replay { // NOLINT @@ -152,7 +155,6 @@ protected: replay(OptionalRef<Mediator> & mediator) : mediator(mediator) {} friend class Script; } replay{mediator}; - //! \} private: diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index 547fb8b..2553fd1 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -24,9 +24,14 @@ RefVector<T> Script::get_components() const { return this->get_components_by_id<T>(this->game_object_id); } -template <typename... Args> -void Script::logf(Args &&... args) { - Log::logf(std::forward<Args>(args)...); +template <class... Args> +void Script::logf(const Log::Level & level, std::format_string<Args...> fmt, Args &&... args) { + Log::logf(level, fmt, std::forward<Args>(args)...); +} + +template <class... Args> +void Script::logf(std::format_string<Args...> fmt, Args &&... args) { + Log::logf(fmt, std::forward<Args>(args)...); } template <typename EventType> @@ -55,6 +60,18 @@ void Script::subscribe(const EventHandler<EventType> & callback) { this->subscribe_internal(callback, EventManager::CHANNEL_ALL); } +template <typename EventType> +void Script::trigger_event(const EventType & event, event_channel_t channel) { + EventManager & mgr = this->mediator->event_manager; + mgr.trigger_event(event, channel); +} + +template <typename EventType> +void Script::queue_event(const EventType & event, event_channel_t channel) { + EventManager & mgr = this->mediator->event_manager; + mgr.queue_event(event, channel); +} + template <typename T> RefVector<T> Script::get_components_by_id(game_object_id_t id) const { Mediator & mediator = this->mediator; diff --git a/src/crepe/api/Sprite.cpp b/src/crepe/api/Sprite.cpp index ba684ba..0107c7b 100644 --- a/src/crepe/api/Sprite.cpp +++ b/src/crepe/api/Sprite.cpp @@ -1,6 +1,6 @@ #include <cmath> -#include "../util/Log.h" +#include "../util/dbg.h" #include "api/Asset.h" #include "Component.h" diff --git a/src/crepe/api/Transform.cpp b/src/crepe/api/Transform.cpp index 5fc886b..32b44e1 100644 --- a/src/crepe/api/Transform.cpp +++ b/src/crepe/api/Transform.cpp @@ -1,4 +1,4 @@ -#include "../util/Log.h" +#include "../util/dbg.h" #include "Transform.h" |