aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-20 12:48:46 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-20 12:48:46 +0100
commit43c6971591aaff8ada4adc1b1b4146b19d43f8e9 (patch)
tree8f405ec11d3e7275ea29d1aaf045fd7e70a4dcfb /src/crepe/api
parent5537096ea31e778e1604c87f2032168cfc2da22b (diff)
parent49e7d902ec2b6f509ab79994e7e2626f4bbbccf2 (diff)
merge master
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Script.cpp15
-rw-r--r--src/crepe/api/Script.h38
2 files changed, 52 insertions, 1 deletions
diff --git a/src/crepe/api/Script.cpp b/src/crepe/api/Script.cpp
index b147252..06b535f 100644
--- a/src/crepe/api/Script.cpp
+++ b/src/crepe/api/Script.cpp
@@ -20,6 +20,21 @@ void Script::subscribe(const EventHandler<CollisionEvent> & callback) {
this->subscribe_internal(callback, this->game_object_id);
}
+template <>
+void Script::subscribe(const EventHandler<ButtonExitEvent> & callback) {
+ this->subscribe_internal(callback, this->game_object_id);
+}
+
+template <>
+void Script::subscribe(const EventHandler<ButtonPressEvent> & callback) {
+ this->subscribe_internal(callback, this->game_object_id);
+}
+
+template <>
+void Script::subscribe(const EventHandler<ButtonEnterEvent> & callback) {
+ this->subscribe_internal(callback, this->game_object_id);
+}
+
void Script::set_next_scene(const string & name) {
SceneManager & mgr = this->mediator->scene_manager;
mgr.set_next_scene(name);
diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h
index 5f68928..bbee920 100644
--- a/src/crepe/api/Script.h
+++ b/src/crepe/api/Script.h
@@ -8,6 +8,7 @@
#include "../manager/Mediator.h"
#include "../manager/ReplayManager.h"
#include "../system/CollisionSystem.h"
+#include "../system/InputSystem.h"
#include "../types.h"
#include "../util/Log.h"
#include "../util/OptionalRef.h"
@@ -270,7 +271,42 @@ void Script::subscribe(const EventHandler<CollisionEvent> & callback);
template <>
void Script::subscribe(const EventHandler<CollisionEvent> & callback, event_channel_t)
= delete;
-
+/**
+ * \brief Subscribe to ButtonPressEvent for the current GameObject
+ *
+ * This is a template specialization for Script::subscribe which automatically sets the event
+ * channel so the callback handler is only called for ButtonPressEvent events that apply to the
+ * current GameObject the parent BehaviorScript is attached to.
+ */
+template <>
+void Script::subscribe(const EventHandler<ButtonPressEvent> & callback);
+template <>
+void Script::subscribe(const EventHandler<ButtonPressEvent> & callback, event_channel_t)
+ = delete;
+/**
+ * \brief Subscribe to ButtonExitEvent for the current GameObject
+ *
+ * This is a template specialization for Script::subscribe which automatically sets the event
+ * channel so the callback handler is only called for ButtonExitEvent events that apply to the
+ * current GameObject the parent BehaviorScript is attached to.
+ */
+template <>
+void Script::subscribe(const EventHandler<ButtonExitEvent> & callback);
+template <>
+void Script::subscribe(const EventHandler<ButtonExitEvent> & callback, event_channel_t)
+ = delete;
+/**
+ * \brief Subscribe to ButtonEnterEvent for the current GameObject
+ *
+ * This is a template specialization for Script::subscribe which automatically sets the event
+ * channel so the callback handler is only called for ButtonEnterEvent events that apply to the
+ * current GameObject the parent BehaviorScript is attached to.
+ */
+template <>
+void Script::subscribe(const EventHandler<ButtonEnterEvent> & callback);
+template <>
+void Script::subscribe(const EventHandler<ButtonEnterEvent> & callback, event_channel_t)
+ = delete;
} // namespace crepe
#include "Script.hpp"