MCPcopy Create free account
hub / github.com/Redot-Engine/redot-engine / suggest_actions

Method suggest_actions

core/input/input_map.cpp:71–92  ·  view source on GitHub ↗

* Returns an nonexistent action error message with a suggestion of the closest * matching action name (if possible). */

Source from the content-addressed store, hash-verified

69 * matching action name (if possible).
70 */
71String InputMap::suggest_actions(const StringName &p_action) const {
72 StringName closest_action;
73 float closest_similarity = 0.0;
74
75 // Find the most action with the most similar name.
76 for (const KeyValue<StringName, Action> &kv : input_map) {
77 const float similarity = String(kv.key).similarity(p_action);
78
79 if (similarity > closest_similarity) {
80 closest_action = kv.key;
81 closest_similarity = similarity;
82 }
83 }
84
85 String error_message = vformat("The InputMap action \"%s\" doesn't exist.", p_action);
86
87 if (closest_similarity >= 0.4) {
88 // Only include a suggestion in the error message if it's similar enough.
89 error_message += vformat(" Did you mean \"%s\"?", closest_action);
90 }
91 return error_message;
92}
93
94#ifdef TOOLS_ENABLED
95void InputMap::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {

Callers 9

is_action_pressedMethod · 0.80
get_action_strengthMethod · 0.80
action_pressMethod · 0.80
action_releaseMethod · 0.80

Calls 3

vformatFunction · 0.85
similarityMethod · 0.80
StringClass · 0.50

Tested by

no test coverage detected