From 527415677f308fbf997fb42a7fac677bfe151189 Mon Sep 17 00:00:00 2001 From: Sara Date: Tue, 28 May 2024 16:58:22 +0200 Subject: [PATCH] feat: added shorthand listen_to functions to PlayerInput --- player_input.cpp | 8 ++++++++ player_input.hpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/player_input.cpp b/player_input.cpp index 1dc2bbf..fb9ba9c 100644 --- a/player_input.cpp +++ b/player_input.cpp @@ -107,6 +107,14 @@ void PlayerInput::listen_to(Listener const& listener) { this->listeners.push_back(listener); } +void PlayerInput::listen_to(gd::String action, gd::Callable callable) { + this->listeners.push_back(Listener(action, callable)); +} + +void PlayerInput::listen_to(gd::String negative, gd::String positive, gd::Callable callable) { + this->listeners.push_back(Listener(negative, positive, callable)); +} + void PlayerInput::stop_listening(Node *node) { for(size_t i = 0; i < this->listeners.size(); ++i) { Listener l = this->listeners.get(i); diff --git a/player_input.hpp b/player_input.hpp index 50378ab..84ccb6c 100644 --- a/player_input.hpp +++ b/player_input.hpp @@ -73,6 +73,9 @@ public: virtual void _process(double deltaTime) override; void listen_to(Listener const &listener); + void listen_to(gd::String action, gd::Callable callable); + void listen_to(gd::String negative, gd::String positive, gd::Callable callable); + void stop_listening(Node *node); void stop_listening(Listener const &listener); void clear_listeners();