summaryrefslogtreecommitdiff
path: root/core/input/input_map.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/input/input_map.cpp')
-rw-r--r--core/input/input_map.cpp30
1 files changed, 20 insertions, 10 deletions
diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp
index d341b5ba4c..3cb4b43a26 100644
--- a/core/input/input_map.cpp
+++ b/core/input/input_map.cpp
@@ -70,8 +70,9 @@ void InputMap::erase_action(const StringName &p_action) {
Array InputMap::_get_actions() {
Array ret;
List<StringName> actions = get_actions();
- if (actions.empty())
+ if (actions.empty()) {
return ret;
+ }
for (const List<StringName>::Element *E = actions.front(); E; E = E->next()) {
ret.push_back(E->get());
@@ -124,8 +125,9 @@ void InputMap::action_set_deadzone(const StringName &p_action, float p_deadzone)
void InputMap::action_add_event(const StringName &p_action, const Ref<InputEvent> &p_event) {
ERR_FAIL_COND_MSG(p_event.is_null(), "It's not a reference to a valid InputEvent object.");
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
- if (_find_event(input_map[p_action], p_event))
+ if (_find_event(input_map[p_action], p_event)) {
return; //already gots
+ }
input_map[p_action].inputs.push_back(p_event);
}
@@ -139,8 +141,9 @@ void InputMap::action_erase_event(const StringName &p_action, const Ref<InputEve
ERR_FAIL_COND_MSG(!input_map.has(p_action), "Request for nonexistent InputMap action '" + String(p_action) + "'.");
List<Ref<InputEvent>>::Element *E = _find_event(input_map[p_action], p_event);
- if (E)
+ if (E) {
input_map[p_action].inputs.erase(E);
+ }
}
void InputMap::action_erase_events(const StringName &p_action) {
@@ -163,8 +166,9 @@ Array InputMap::_get_action_list(const StringName &p_action) {
const List<Ref<InputEvent>> *InputMap::get_action_list(const StringName &p_action) {
const Map<StringName, Action>::Element *E = input_map.find(p_action);
- if (!E)
+ if (!E) {
return nullptr;
+ }
return &E->get().inputs;
}
@@ -179,10 +183,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
Ref<InputEventAction> input_event_action = p_event;
if (input_event_action.is_valid()) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = input_event_action->is_pressed();
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = (p_pressed != nullptr && *p_pressed) ? input_event_action->get_strength() : 0.0f;
+ }
return input_event_action->get_action() == p_action;
}
@@ -190,10 +196,12 @@ bool InputMap::event_get_action_status(const Ref<InputEvent> &p_event, const Str
float strength;
List<Ref<InputEvent>>::Element *event = _find_event(E->get(), p_event, &pressed, &strength);
if (event != nullptr) {
- if (p_pressed != nullptr)
+ if (p_pressed != nullptr) {
*p_pressed = pressed;
- if (p_strength != nullptr)
+ }
+ if (p_strength != nullptr) {
*p_strength = strength;
+ }
return true;
} else {
return false;
@@ -213,8 +221,9 @@ void InputMap::load_from_globals() {
for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) {
const PropertyInfo &pi = E->get();
- if (!pi.name.begins_with("input/"))
+ if (!pi.name.begins_with("input/")) {
continue;
+ }
String name = pi.name.substr(pi.name.find("/") + 1, pi.name.length());
@@ -225,8 +234,9 @@ void InputMap::load_from_globals() {
add_action(name, deadzone);
for (int i = 0; i < events.size(); i++) {
Ref<InputEvent> event = events[i];
- if (event.is_null())
+ if (event.is_null()) {
continue;
+ }
action_add_event(name, event);
}
}