From ca1a2e11242879a437999318b809ebd9c8b75ea2 Mon Sep 17 00:00:00 2001 From: Nick H <62965063+SirQuartz@users.noreply.github.com> Date: Fri, 2 Jul 2021 00:02:28 -0400 Subject: [PATCH] Add `get_dead_zone()` method to `InputMap` This commit adds a new method to the `InputMap`, allowing the user to get the value of an action's dead zone as a float. (cherry picked from commit c6f28ed62b5b24033439e6c5d8517883d93c5f53) --- core/input_map.cpp | 7 +++++++ core/input_map.h | 1 + doc/classes/InputMap.xml | 9 +++++++++ 3 files changed, 17 insertions(+) diff --git a/core/input_map.cpp b/core/input_map.cpp index 9d8230b5379..6c82b8dc87c 100644 --- a/core/input_map.cpp +++ b/core/input_map.cpp @@ -45,6 +45,7 @@ void InputMap::_bind_methods() { ClassDB::bind_method(D_METHOD("erase_action", "action"), &InputMap::erase_action); ClassDB::bind_method(D_METHOD("action_set_deadzone", "action", "deadzone"), &InputMap::action_set_deadzone); + ClassDB::bind_method(D_METHOD("action_get_deadzone", "action"), &InputMap::action_get_deadzone); ClassDB::bind_method(D_METHOD("action_add_event", "action", "event"), &InputMap::action_add_event); ClassDB::bind_method(D_METHOD("action_has_event", "action", "event"), &InputMap::action_has_event); ClassDB::bind_method(D_METHOD("action_erase_event", "action", "event"), &InputMap::action_erase_event); @@ -148,6 +149,12 @@ bool InputMap::has_action(const StringName &p_action) const { return input_map.has(p_action); } +float InputMap::action_get_deadzone(const StringName &p_action) { + ERR_FAIL_COND_V_MSG(!input_map.has(p_action), 0.0f, _suggest_actions(p_action)); + + return input_map[p_action].deadzone; +} + void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone) { ERR_FAIL_COND_MSG(!input_map.has(p_action), _suggest_actions(p_action)); diff --git a/core/input_map.h b/core/input_map.h index 53cad7c5729..1d4460750bc 100644 --- a/core/input_map.h +++ b/core/input_map.h @@ -71,6 +71,7 @@ public: void add_action(const StringName &p_action, float p_deadzone = 0.5); void erase_action(const StringName &p_action); + float action_get_deadzone(const StringName &p_action); void action_set_deadzone(const StringName &p_action, float p_deadzone); void action_add_event(const StringName &p_action, const Ref &p_event); bool action_has_event(const StringName &p_action, const Ref &p_event); diff --git a/doc/classes/InputMap.xml b/doc/classes/InputMap.xml index b92b3b35878..55cc699db4a 100644 --- a/doc/classes/InputMap.xml +++ b/doc/classes/InputMap.xml @@ -41,6 +41,15 @@ Removes all events from an action. + + + + + + + Returns a deadzone value for the action. + +