From ce43781cb37adc5fd25555864b1001b9ab23de94 Mon Sep 17 00:00:00 2001 From: Mai Lavelle Date: Mon, 16 Aug 2021 00:53:01 -0400 Subject: Fix input methods returning zero strength when pressed status not requested Fixes behavior of these methods: `InputMap::event_get_action_status` `InputEvent*::action_match` Previously when `p_pressed` was `nullptr`, `p_strength` would be set to `0.0f` regardless of event strength. This affected `InputEventAction` events processed by `Input.parse_input_event` for example. Regression found in afa89c9eea5c99 --- core/input/input_event.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'core/input/input_event.cpp') diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 16bb92d94b..325cdf2127 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -431,10 +431,11 @@ bool InputEventKey::action_match(const Ref &p_event, bool *p_pressed match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code); } if (match) { + bool pressed = key->is_pressed(); if (p_pressed != nullptr) { - *p_pressed = key->is_pressed(); + *p_pressed = pressed; } - float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + float strength = pressed ? 1.0f : 0.0f; if (p_strength != nullptr) { *p_strength = strength; } @@ -587,10 +588,11 @@ bool InputEventMouseButton::action_match(const Ref &p_event, bool *p bool match = mb->button_index == button_index; if (match) { + bool pressed = mb->is_pressed(); if (p_pressed != nullptr) { - *p_pressed = mb->is_pressed(); + *p_pressed = pressed; } - float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + float strength = pressed ? 1.0f : 0.0f; if (p_strength != nullptr) { *p_strength = strength; } @@ -998,10 +1000,11 @@ bool InputEventJoypadButton::action_match(const Ref &p_event, bool * bool match = button_index == jb->button_index; if (match) { + bool pressed = jb->is_pressed(); if (p_pressed != nullptr) { - *p_pressed = jb->is_pressed(); + *p_pressed = pressed; } - float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + float strength = pressed ? 1.0f : 0.0f; if (p_strength != nullptr) { *p_strength = strength; } @@ -1291,10 +1294,11 @@ bool InputEventAction::action_match(const Ref &p_event, bool *p_pres bool match = action == act->action; if (match) { + bool pressed = act->pressed; if (p_pressed != nullptr) { - *p_pressed = act->pressed; + *p_pressed = pressed; } - float strength = (p_pressed != nullptr && *p_pressed) ? 1.0f : 0.0f; + float strength = pressed ? 1.0f : 0.0f; if (p_strength != nullptr) { *p_strength = strength; } -- cgit v1.2.3