diff --git a/player_input.cpp b/player_input.cpp index f9cbc79..3712632 100644 --- a/player_input.cpp +++ b/player_input.cpp @@ -1,4 +1,5 @@ #include "player_input.hpp" +#include "godot_cpp/variant/utility_functions.hpp" #include "godot_macros.h" #include #include @@ -25,29 +26,34 @@ PlayerInput::Listener::Listener(gd::String action, gd::Callable callable) std::optional PlayerInput::Listener::evaluate_action(gd::String const &action) { gd::Input *input = gd::Input::get_singleton(); + gd::UtilityFunctions::print("evaluating ", action); if(action.begins_with("_mouse_")) { + gd::UtilityFunctions::print("evaluating ", action, " as mouse motion"); gd::Vector2 vector = PlayerInput::get_last_mouse_motion(); - if(action.ends_with("_up")) + if(action == "_mouse_up") return vector.y > 0.f ? vector.y : 0.f; - else if(action.ends_with("_down")) + else if(action == "_mouse_down") return vector.y < 0.f ? -vector.y : 0.f; - else if(action.ends_with("_right")) + else if(action == "_mouse_right") return vector.x > 0.f ? vector.x : 0.f; - else if(action.ends_with("_left")) + else if(action == "_mouse_left") return vector.x < 0.f ? -vector.x : 0.f; } if(action.is_empty()) { return 0.f; } else { + gd::UtilityFunctions::print("evaluating ", action, " as regular"); return float(input->is_action_pressed(action)); } } bool PlayerInput::Listener::has_changed(gd::Ref const &event) { - bool const mouse_changed{this->isMouseEvent && event->is_class("InputEventMouseMotion")}; + // do not evaluate mouse events as anything but + if(this->isMouseEvent) + return event->is_class("InputEventMouseMotion"); bool const negative_changed{!this->actionNegative.is_empty() && event->is_action(this->actionNegative)}; bool const positive_changed{!this->actionPositive.is_empty() && event->is_action(this->actionPositive)}; - return mouse_changed || negative_changed || positive_changed; + return negative_changed || positive_changed; } float PlayerInput::Listener::evaluate(gd::Ref const &event) { @@ -129,5 +135,9 @@ void PlayerInput::stop_listening(Listener const& listener) { void PlayerInput::clear_listeners() { this->listeners.clear(); } + +void PlayerInput::set_device(int id) { + this->device = id; +} } diff --git a/player_input.hpp b/player_input.hpp index 84ccb6c..90de3d4 100644 --- a/player_input.hpp +++ b/player_input.hpp @@ -52,18 +52,6 @@ public: bool operator==(PlayerInput::Listener const& b) const; }; -private: - // the last mouse motion, updated by the primary instance - static gd::Vector2 lastMouseMotion; - // does a primary instance exist - static bool primaryExists; - // is this the primary instance - // the primary instance is responsible for updating static - // variables like lastMouseMotion - bool isPrimary{false}; - - // current listeners for this instance - gd::Vector listeners{}; public: static gd::Vector2 get_last_mouse_motion(); @@ -79,6 +67,21 @@ public: void stop_listening(Node *node); void stop_listening(Listener const &listener); void clear_listeners(); + + void set_device(int id); +private: + // the last mouse motion, updated by the primary instance + static gd::Vector2 lastMouseMotion; + // does a primary instance exist + static bool primaryExists; + // is this the primary instance + // the primary instance is responsible for updating static + // variables like lastMouseMotion + bool isPrimary{false}; + int device{-1}; + + // current listeners for this instance + gd::Vector listeners{}; }; }