* Returns an nonexistent action error message with a suggestion of the closest * matching action name (if possible). */
| 69 | * matching action name (if possible). |
| 70 | */ |
| 71 | String 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 |
| 95 | void InputMap::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const { |
no test coverage detected