Input: Throw error if action doesn't exist
Thow errors if requesting an unexisting InputMap action. Makes `Input.is_action_*` methods consistents with `Event.is_action_*` which already throw errors. fixes #33303
This commit is contained in:
parent
f3864ec89f
commit
2aee71d52d
1 changed files with 16 additions and 0 deletions
|
@ -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 {
|
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);
|
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 {
|
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);
|
const Map<StringName, Action>::Element *E = action_state.find(p_action);
|
||||||
if (!E) {
|
if (!E) {
|
||||||
return false;
|
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 {
|
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);
|
const Map<StringName, Action>::Element *E = action_state.find(p_action);
|
||||||
if (!E) {
|
if (!E) {
|
||||||
return false;
|
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 {
|
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);
|
const Map<StringName, Action>::Element *E = action_state.find(p_action);
|
||||||
if (!E) {
|
if (!E) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
|
Loading…
Reference in a new issue