diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-02-24 15:08:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-24 15:08:41 +0100 |
commit | 829b6ef27b08ce0eea45f691de4e5bb2a1335a8f (patch) | |
tree | f609e222475dbda4e5b8c2385217cbd67303d64b /core | |
parent | f3864ec89f337ad1454a7112ba47896f2524ba9b (diff) | |
parent | 2aee71d52dc687c8f8be1807436875eb83f7d4fb (diff) |
Merge pull request #40937 from 27thLiz/inputmap-error
Input: Throw error if action doesn't exist
Diffstat (limited to 'core')
-rw-r--r-- | core/input/input.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/input/input.cpp b/core/input/input.cpp index 94a18b5b4f..f928ae7654 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -241,10 +241,18 @@ bool Input::is_joy_button_pressed(int p_device, int p_button) const { } bool Input::is_action_pressed(const StringName &p_action, bool p_exact) const { +#ifdef DEBUG_ENABLED + bool has_action = InputMap::get_singleton()->has_action(p_action); + ERR_FAIL_COND_V_MSG(!has_action, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); +#endif return action_state.has(p_action) && action_state[p_action].pressed && (p_exact ? action_state[p_action].exact : true); } bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) const { +#ifdef DEBUG_ENABLED + bool has_action = InputMap::get_singleton()->has_action(p_action); + ERR_FAIL_COND_V_MSG(!has_action, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); +#endif const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) { return false; @@ -262,6 +270,10 @@ bool Input::is_action_just_pressed(const StringName &p_action, bool p_exact) con } bool Input::is_action_just_released(const StringName &p_action, bool p_exact) const { +#ifdef DEBUG_ENABLED + bool has_action = InputMap::get_singleton()->has_action(p_action); + ERR_FAIL_COND_V_MSG(!has_action, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); +#endif const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) { return false; @@ -279,6 +291,10 @@ bool Input::is_action_just_released(const StringName &p_action, bool p_exact) co } float Input::get_action_strength(const StringName &p_action, bool p_exact) const { +#ifdef DEBUG_ENABLED + bool has_action = InputMap::get_singleton()->has_action(p_action); + ERR_FAIL_COND_V_MSG(!has_action, false, "Request for nonexistent InputMap action '" + String(p_action) + "'."); +#endif const Map<StringName, Action>::Element *E = action_state.find(p_action); if (!E) { return 0.0f; |