From 3d50dfb0c8b93f04ae6c3e49c3851c9bc3179755 Mon Sep 17 00:00:00 2001 From: Nathan Hoad Date: Wed, 20 Mar 2024 23:17:32 +1000 Subject: [PATCH] Emit did_change signal when setting from empty (#35) --- Input Helper.csproj | 2 +- Input Helper.csproj.old | 7 +++++++ addons/input_helper/input_helper.gd | 9 ++++----- project.godot | 6 +++++- tests/test_remapping.gd | 30 +++++++++++++++++++++++++++-- 5 files changed, 45 insertions(+), 9 deletions(-) create mode 100644 Input Helper.csproj.old diff --git a/Input Helper.csproj b/Input Helper.csproj index e4e05ed..76cf192 100644 --- a/Input Helper.csproj +++ b/Input Helper.csproj @@ -1,4 +1,4 @@ - + net6.0 true diff --git a/Input Helper.csproj.old b/Input Helper.csproj.old new file mode 100644 index 0000000..e4e05ed --- /dev/null +++ b/Input Helper.csproj.old @@ -0,0 +1,7 @@ + + + net6.0 + true + InputHelper + + \ No newline at end of file diff --git a/addons/input_helper/input_helper.gd b/addons/input_helper/input_helper.gd index 5c1037f..55dfa99 100644 --- a/addons/input_helper/input_helper.gd +++ b/addons/input_helper/input_helper.gd @@ -363,7 +363,7 @@ func _update_input_for_action(action: String, input: InputEvent, swap_if_taken: # Find the key based event for the target action var action_events: Array[InputEvent] = InputMap.action_get_events(action) - var did_change: bool = false + var is_replacing: bool = false for i in range(0, action_events.size()): var event: InputEvent = action_events[i] if check_is_valid.call(event): @@ -376,11 +376,11 @@ func _update_input_for_action(action: String, input: InputEvent, swap_if_taken: # Replace the event action_events[i] = input - did_change = true + is_replacing = true break # If we were trying to replace something but didn't find it then just add it to the end - if not did_change: + if not is_replacing: action_events.append(input) # Apply the changes @@ -389,8 +389,7 @@ func _update_input_for_action(action: String, input: InputEvent, swap_if_taken: if event != null: InputMap.action_add_event(action, event) - if did_change: - did_change_signal.emit(action, input) + did_change_signal.emit(action, input) return OK diff --git a/project.godot b/project.godot index 6c79d9e..3059971 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="Input Helper" run/main_scene="res://tests/tests.tscn" -config/features=PackedStringArray("4.2", "Forward Plus") +config/features=PackedStringArray("4.2", "C#", "Forward Plus") config/icon="res://icon.svg" [autoload] @@ -48,3 +48,7 @@ ui_accept={ , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"button_index":1,"pressure":0.0,"pressed":true,"script":null) ] } +ui_test_empty={ +"deadzone": 0.5, +"events": [] +} diff --git a/tests/test_remapping.gd b/tests/test_remapping.gd index 8c34f79..50bf128 100644 --- a/tests/test_remapping.gd +++ b/tests/test_remapping.gd @@ -1,9 +1,9 @@ extends AbstractTest -const SERIALIZED_INPUT_SNAPSHOT = '{"ui_accept":{"joypad":[],"keyboard":["Enter"],"mouse":[1]},"ui_cancel":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_copy":{"joypad":[],"keyboard":["C|ctrl","Insert|ctrl"],"mouse":[]},"ui_cut":{"joypad":[],"keyboard":["X|ctrl","Delete|shift"],"mouse":[]},"ui_down":{"joypad":[12,"1|1"],"keyboard":["Down"],"mouse":[]},"ui_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_filedialog_refresh":{"joypad":[],"keyboard":["F5"],"mouse":[]},"ui_filedialog_show_hidden":{"joypad":[],"keyboard":["H"],"mouse":[]},"ui_filedialog_up_one_level":{"joypad":[],"keyboard":["Backspace"],"mouse":[]},"ui_focus_next":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_focus_prev":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_graph_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_graph_duplicate":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_home":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_left":{"joypad":[13,"0|-1"],"keyboard":["Left"],"mouse":[]},"ui_menu":{"joypad":[],"keyboard":["Menu"],"mouse":[]},"ui_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_paste":{"joypad":[],"keyboard":["V|ctrl","Insert|shift"],"mouse":[]},"ui_redo":{"joypad":[],"keyboard":["Z|shift,ctrl","Y|ctrl"],"mouse":[]},"ui_right":{"joypad":[14,"0|1"],"keyboard":["Right"],"mouse":[]},"ui_select":{"joypad":[3],"keyboard":["Space"],"mouse":[]},"ui_swap_input_direction":{"joypad":[],"keyboard":["QuoteLeft|ctrl"],"mouse":[]},"ui_text_add_selection_for_next_occurrence":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_text_backspace":{"joypad":[],"keyboard":["Backspace","Backspace|shift"],"mouse":[]},"ui_text_backspace_all_to_left":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_backspace_all_to_left.macos":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word.macos":{"joypad":[],"keyboard":["Backspace|alt"],"mouse":[]},"ui_text_caret_add_above":{"joypad":[],"keyboard":["Up|shift,ctrl"],"mouse":[]},"ui_text_caret_add_above.macos":{"joypad":[],"keyboard":["O|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below":{"joypad":[],"keyboard":["Down|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below.macos":{"joypad":[],"keyboard":["L|shift,ctrl"],"mouse":[]},"ui_text_caret_document_end":{"joypad":[],"keyboard":["End|ctrl"],"mouse":[]},"ui_text_caret_document_end.macos":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_caret_document_start":{"joypad":[],"keyboard":["Home|ctrl"],"mouse":[]},"ui_text_caret_document_start.macos":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_caret_down":{"joypad":[],"keyboard":["Down"],"mouse":[]},"ui_text_caret_left":{"joypad":[],"keyboard":["Left"],"mouse":[]},"ui_text_caret_line_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_text_caret_line_end.macos":{"joypad":[],"keyboard":["E|ctrl","Right|ctrl"],"mouse":[]},"ui_text_caret_line_start":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_text_caret_line_start.macos":{"joypad":[],"keyboard":["A|ctrl","Left|ctrl"],"mouse":[]},"ui_text_caret_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_text_caret_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_text_caret_right":{"joypad":[],"keyboard":["Right"],"mouse":[]},"ui_text_caret_up":{"joypad":[],"keyboard":["Up"],"mouse":[]},"ui_text_caret_word_left":{"joypad":[],"keyboard":["Left|ctrl"],"mouse":[]},"ui_text_caret_word_left.macos":{"joypad":[],"keyboard":["Left|alt"],"mouse":[]},"ui_text_caret_word_right":{"joypad":[],"keyboard":["Right|ctrl"],"mouse":[]},"ui_text_caret_word_right.macos":{"joypad":[],"keyboard":["Right|alt"],"mouse":[]},"ui_text_clear_carets_and_selection":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_text_completion_accept":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_completion_query":{"joypad":[],"keyboard":["Space|ctrl"],"mouse":[]},"ui_text_completion_replace":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_dedent":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_text_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_text_delete_all_to_right":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_delete_all_to_right.macos":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word.macos":{"joypad":[],"keyboard":["Delete|alt"],"mouse":[]},"ui_text_indent":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_newline":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_newline_above":{"joypad":[],"keyboard":["Enter|shift,ctrl","Kp Enter|shift,ctrl"],"mouse":[]},"ui_text_newline_blank":{"joypad":[],"keyboard":["Enter|ctrl","Kp Enter|ctrl"],"mouse":[]},"ui_text_scroll_down":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_scroll_down.macos":{"joypad":[],"keyboard":["Down|alt,ctrl"],"mouse":[]},"ui_text_scroll_up":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_scroll_up.macos":{"joypad":[],"keyboard":["Up|alt,ctrl"],"mouse":[]},"ui_text_select_all":{"joypad":[],"keyboard":["A|ctrl"],"mouse":[]},"ui_text_select_word_under_caret":{"joypad":[],"keyboard":["G|alt"],"mouse":[]},"ui_text_select_word_under_caret.macos":{"joypad":[],"keyboard":["G|ctrl,meta"],"mouse":[]},"ui_text_submit":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_toggle_insert_mode":{"joypad":[],"keyboard":["Insert"],"mouse":[]},"ui_undo":{"joypad":[],"keyboard":["Z|ctrl"],"mouse":[]},"ui_up":{"joypad":[11,"1|-1"],"keyboard":["Up"],"mouse":[]}}' +const SERIALIZED_INPUT_SNAPSHOT = '{"ui_accept":{"joypad":[1],"keyboard":["Enter"],"mouse":[1]},"ui_cancel":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_copy":{"joypad":[],"keyboard":["C|ctrl","Insert|ctrl"],"mouse":[]},"ui_cut":{"joypad":[],"keyboard":["X|ctrl","Delete|shift"],"mouse":[]},"ui_down":{"joypad":[12,"1|1"],"keyboard":["Down"],"mouse":[]},"ui_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_filedialog_refresh":{"joypad":[],"keyboard":["F5"],"mouse":[]},"ui_filedialog_show_hidden":{"joypad":[],"keyboard":["H"],"mouse":[]},"ui_filedialog_up_one_level":{"joypad":[],"keyboard":["Backspace"],"mouse":[]},"ui_focus_next":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_focus_prev":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_graph_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_graph_duplicate":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_home":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_left":{"joypad":[13,"0|-1"],"keyboard":["Left"],"mouse":[]},"ui_menu":{"joypad":[],"keyboard":["Menu"],"mouse":[]},"ui_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_paste":{"joypad":[],"keyboard":["V|ctrl","Insert|shift"],"mouse":[]},"ui_redo":{"joypad":[],"keyboard":["Z|shift,ctrl","Y|ctrl"],"mouse":[]},"ui_right":{"joypad":[14,"0|1"],"keyboard":["Right"],"mouse":[]},"ui_select":{"joypad":[3],"keyboard":["Space"],"mouse":[]},"ui_swap_input_direction":{"joypad":[],"keyboard":["QuoteLeft|ctrl"],"mouse":[]},"ui_test_empty":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_add_selection_for_next_occurrence":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_text_backspace":{"joypad":[],"keyboard":["Backspace","Backspace|shift"],"mouse":[]},"ui_text_backspace_all_to_left":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_backspace_all_to_left.macos":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word.macos":{"joypad":[],"keyboard":["Backspace|alt"],"mouse":[]},"ui_text_caret_add_above":{"joypad":[],"keyboard":["Up|shift,ctrl"],"mouse":[]},"ui_text_caret_add_above.macos":{"joypad":[],"keyboard":["O|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below":{"joypad":[],"keyboard":["Down|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below.macos":{"joypad":[],"keyboard":["L|shift,ctrl"],"mouse":[]},"ui_text_caret_document_end":{"joypad":[],"keyboard":["End|ctrl"],"mouse":[]},"ui_text_caret_document_end.macos":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_caret_document_start":{"joypad":[],"keyboard":["Home|ctrl"],"mouse":[]},"ui_text_caret_document_start.macos":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_caret_down":{"joypad":[],"keyboard":["Down"],"mouse":[]},"ui_text_caret_left":{"joypad":[],"keyboard":["Left"],"mouse":[]},"ui_text_caret_line_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_text_caret_line_end.macos":{"joypad":[],"keyboard":["E|ctrl","Right|ctrl"],"mouse":[]},"ui_text_caret_line_start":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_text_caret_line_start.macos":{"joypad":[],"keyboard":["A|ctrl","Left|ctrl"],"mouse":[]},"ui_text_caret_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_text_caret_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_text_caret_right":{"joypad":[],"keyboard":["Right"],"mouse":[]},"ui_text_caret_up":{"joypad":[],"keyboard":["Up"],"mouse":[]},"ui_text_caret_word_left":{"joypad":[],"keyboard":["Left|ctrl"],"mouse":[]},"ui_text_caret_word_left.macos":{"joypad":[],"keyboard":["Left|alt"],"mouse":[]},"ui_text_caret_word_right":{"joypad":[],"keyboard":["Right|ctrl"],"mouse":[]},"ui_text_caret_word_right.macos":{"joypad":[],"keyboard":["Right|alt"],"mouse":[]},"ui_text_clear_carets_and_selection":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_text_completion_accept":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_completion_query":{"joypad":[],"keyboard":["Space|ctrl"],"mouse":[]},"ui_text_completion_replace":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_dedent":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_text_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_text_delete_all_to_right":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_delete_all_to_right.macos":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word.macos":{"joypad":[],"keyboard":["Delete|alt"],"mouse":[]},"ui_text_indent":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_newline":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_newline_above":{"joypad":[],"keyboard":["Enter|shift,ctrl","Kp Enter|shift,ctrl"],"mouse":[]},"ui_text_newline_blank":{"joypad":[],"keyboard":["Enter|ctrl","Kp Enter|ctrl"],"mouse":[]},"ui_text_scroll_down":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_scroll_down.macos":{"joypad":[],"keyboard":["Down|alt,ctrl"],"mouse":[]},"ui_text_scroll_up":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_scroll_up.macos":{"joypad":[],"keyboard":["Up|alt,ctrl"],"mouse":[]},"ui_text_select_all":{"joypad":[],"keyboard":["A|ctrl"],"mouse":[]},"ui_text_select_word_under_caret":{"joypad":[],"keyboard":["G|alt"],"mouse":[]},"ui_text_select_word_under_caret.macos":{"joypad":[],"keyboard":["G|ctrl,meta"],"mouse":[]},"ui_text_submit":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_toggle_insert_mode":{"joypad":[],"keyboard":["Insert"],"mouse":[]},"ui_undo":{"joypad":[],"keyboard":["Z|ctrl"],"mouse":[]},"ui_up":{"joypad":[11,"1|-1"],"keyboard":["Up"],"mouse":[]}}' const SERIALIZED_ACCEPT_SNAPSHOT = '{"ui_accept":{"joypad":[],"keyboard":["Enter","Space"],"mouse":[1]}}' -const DESERIALIZED_INPUT_SNAPSHOT = '{"ui_accept":{"joypad":[],"keyboard":["Enter","Space"],"mouse":[1]},"ui_cancel":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_copy":{"joypad":[],"keyboard":["C|ctrl","Insert|ctrl"],"mouse":[]},"ui_cut":{"joypad":[],"keyboard":["X|ctrl","Delete|shift"],"mouse":[]},"ui_down":{"joypad":[12,"1|1"],"keyboard":["Down"],"mouse":[]},"ui_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_filedialog_refresh":{"joypad":[],"keyboard":["F5"],"mouse":[]},"ui_filedialog_show_hidden":{"joypad":[],"keyboard":["H"],"mouse":[]},"ui_filedialog_up_one_level":{"joypad":[],"keyboard":["Backspace"],"mouse":[]},"ui_focus_next":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_focus_prev":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_graph_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_graph_duplicate":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_home":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_left":{"joypad":[13,"0|-1"],"keyboard":["Left"],"mouse":[]},"ui_menu":{"joypad":[],"keyboard":["Menu"],"mouse":[]},"ui_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_paste":{"joypad":[],"keyboard":["V|ctrl","Insert|shift"],"mouse":[]},"ui_redo":{"joypad":[],"keyboard":["Z|shift,ctrl","Y|ctrl"],"mouse":[]},"ui_right":{"joypad":[14,"0|1"],"keyboard":["Right"],"mouse":[]},"ui_select":{"joypad":[3],"keyboard":["Space"],"mouse":[]},"ui_swap_input_direction":{"joypad":[],"keyboard":["QuoteLeft|ctrl"],"mouse":[]},"ui_text_add_selection_for_next_occurrence":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_text_backspace":{"joypad":[],"keyboard":["Backspace","Backspace|shift"],"mouse":[]},"ui_text_backspace_all_to_left":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_backspace_all_to_left.macos":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word.macos":{"joypad":[],"keyboard":["Backspace|alt"],"mouse":[]},"ui_text_caret_add_above":{"joypad":[],"keyboard":["Up|shift,ctrl"],"mouse":[]},"ui_text_caret_add_above.macos":{"joypad":[],"keyboard":["O|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below":{"joypad":[],"keyboard":["Down|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below.macos":{"joypad":[],"keyboard":["L|shift,ctrl"],"mouse":[]},"ui_text_caret_document_end":{"joypad":[],"keyboard":["End|ctrl"],"mouse":[]},"ui_text_caret_document_end.macos":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_caret_document_start":{"joypad":[],"keyboard":["Home|ctrl"],"mouse":[]},"ui_text_caret_document_start.macos":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_caret_down":{"joypad":[],"keyboard":["Down"],"mouse":[]},"ui_text_caret_left":{"joypad":[],"keyboard":["Left"],"mouse":[]},"ui_text_caret_line_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_text_caret_line_end.macos":{"joypad":[],"keyboard":["E|ctrl","Right|ctrl"],"mouse":[]},"ui_text_caret_line_start":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_text_caret_line_start.macos":{"joypad":[],"keyboard":["A|ctrl","Left|ctrl"],"mouse":[]},"ui_text_caret_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_text_caret_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_text_caret_right":{"joypad":[],"keyboard":["Right"],"mouse":[]},"ui_text_caret_up":{"joypad":[],"keyboard":["Up"],"mouse":[]},"ui_text_caret_word_left":{"joypad":[],"keyboard":["Left|ctrl"],"mouse":[]},"ui_text_caret_word_left.macos":{"joypad":[],"keyboard":["Left|alt"],"mouse":[]},"ui_text_caret_word_right":{"joypad":[],"keyboard":["Right|ctrl"],"mouse":[]},"ui_text_caret_word_right.macos":{"joypad":[],"keyboard":["Right|alt"],"mouse":[]},"ui_text_clear_carets_and_selection":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_text_completion_accept":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_completion_query":{"joypad":[],"keyboard":["Space|ctrl"],"mouse":[]},"ui_text_completion_replace":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_dedent":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_text_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_text_delete_all_to_right":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_delete_all_to_right.macos":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word.macos":{"joypad":[],"keyboard":["Delete|alt"],"mouse":[]},"ui_text_indent":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_newline":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_newline_above":{"joypad":[],"keyboard":["Enter|shift,ctrl","Kp Enter|shift,ctrl"],"mouse":[]},"ui_text_newline_blank":{"joypad":[],"keyboard":["Enter|ctrl","Kp Enter|ctrl"],"mouse":[]},"ui_text_scroll_down":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_scroll_down.macos":{"joypad":[],"keyboard":["Down|alt,ctrl"],"mouse":[]},"ui_text_scroll_up":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_scroll_up.macos":{"joypad":[],"keyboard":["Up|alt,ctrl"],"mouse":[]},"ui_text_select_all":{"joypad":[],"keyboard":["A|ctrl"],"mouse":[]},"ui_text_select_word_under_caret":{"joypad":[],"keyboard":["G|alt"],"mouse":[]},"ui_text_select_word_under_caret.macos":{"joypad":[],"keyboard":["G|ctrl,meta"],"mouse":[]},"ui_text_submit":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_toggle_insert_mode":{"joypad":[],"keyboard":["Insert"],"mouse":[]},"ui_undo":{"joypad":[],"keyboard":["Z|ctrl"],"mouse":[]},"ui_up":{"joypad":[11,"1|-1"],"keyboard":["Up"],"mouse":[]}}' +const DESERIALIZED_INPUT_SNAPSHOT = '{"ui_accept":{"joypad":[],"keyboard":["Enter","Space"],"mouse":[1]},"ui_cancel":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_copy":{"joypad":[],"keyboard":["C|ctrl","Insert|ctrl"],"mouse":[]},"ui_cut":{"joypad":[],"keyboard":["X|ctrl","Delete|shift"],"mouse":[]},"ui_down":{"joypad":[12,"1|1"],"keyboard":["Down"],"mouse":[]},"ui_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_filedialog_refresh":{"joypad":[],"keyboard":["F5"],"mouse":[]},"ui_filedialog_show_hidden":{"joypad":[],"keyboard":["H"],"mouse":[]},"ui_filedialog_up_one_level":{"joypad":[],"keyboard":["Backspace"],"mouse":[]},"ui_focus_next":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_focus_prev":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_graph_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_graph_duplicate":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_home":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_left":{"joypad":[13,"0|-1"],"keyboard":["Left"],"mouse":[]},"ui_menu":{"joypad":[],"keyboard":["Menu"],"mouse":[]},"ui_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_paste":{"joypad":[],"keyboard":["V|ctrl","Insert|shift"],"mouse":[]},"ui_redo":{"joypad":[],"keyboard":["Z|shift,ctrl","Y|ctrl"],"mouse":[]},"ui_right":{"joypad":[14,"0|1"],"keyboard":["Right"],"mouse":[]},"ui_select":{"joypad":[3],"keyboard":["Space"],"mouse":[]},"ui_swap_input_direction":{"joypad":[],"keyboard":["QuoteLeft|ctrl"],"mouse":[]},"ui_test_empty":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_add_selection_for_next_occurrence":{"joypad":[],"keyboard":["D|ctrl"],"mouse":[]},"ui_text_backspace":{"joypad":[],"keyboard":["Backspace","Backspace|shift"],"mouse":[]},"ui_text_backspace_all_to_left":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_backspace_all_to_left.macos":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word":{"joypad":[],"keyboard":["Backspace|ctrl"],"mouse":[]},"ui_text_backspace_word.macos":{"joypad":[],"keyboard":["Backspace|alt"],"mouse":[]},"ui_text_caret_add_above":{"joypad":[],"keyboard":["Up|shift,ctrl"],"mouse":[]},"ui_text_caret_add_above.macos":{"joypad":[],"keyboard":["O|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below":{"joypad":[],"keyboard":["Down|shift,ctrl"],"mouse":[]},"ui_text_caret_add_below.macos":{"joypad":[],"keyboard":["L|shift,ctrl"],"mouse":[]},"ui_text_caret_document_end":{"joypad":[],"keyboard":["End|ctrl"],"mouse":[]},"ui_text_caret_document_end.macos":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_caret_document_start":{"joypad":[],"keyboard":["Home|ctrl"],"mouse":[]},"ui_text_caret_document_start.macos":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_caret_down":{"joypad":[],"keyboard":["Down"],"mouse":[]},"ui_text_caret_left":{"joypad":[],"keyboard":["Left"],"mouse":[]},"ui_text_caret_line_end":{"joypad":[],"keyboard":["End"],"mouse":[]},"ui_text_caret_line_end.macos":{"joypad":[],"keyboard":["E|ctrl","Right|ctrl"],"mouse":[]},"ui_text_caret_line_start":{"joypad":[],"keyboard":["Home"],"mouse":[]},"ui_text_caret_line_start.macos":{"joypad":[],"keyboard":["A|ctrl","Left|ctrl"],"mouse":[]},"ui_text_caret_page_down":{"joypad":[],"keyboard":["PageDown"],"mouse":[]},"ui_text_caret_page_up":{"joypad":[],"keyboard":["PageUp"],"mouse":[]},"ui_text_caret_right":{"joypad":[],"keyboard":["Right"],"mouse":[]},"ui_text_caret_up":{"joypad":[],"keyboard":["Up"],"mouse":[]},"ui_text_caret_word_left":{"joypad":[],"keyboard":["Left|ctrl"],"mouse":[]},"ui_text_caret_word_left.macos":{"joypad":[],"keyboard":["Left|alt"],"mouse":[]},"ui_text_caret_word_right":{"joypad":[],"keyboard":["Right|ctrl"],"mouse":[]},"ui_text_caret_word_right.macos":{"joypad":[],"keyboard":["Right|alt"],"mouse":[]},"ui_text_clear_carets_and_selection":{"joypad":[],"keyboard":["Escape"],"mouse":[]},"ui_text_completion_accept":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_completion_query":{"joypad":[],"keyboard":["Space|ctrl"],"mouse":[]},"ui_text_completion_replace":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_dedent":{"joypad":[],"keyboard":["Tab|shift"],"mouse":[]},"ui_text_delete":{"joypad":[],"keyboard":["Delete"],"mouse":[]},"ui_text_delete_all_to_right":{"joypad":[],"keyboard":[],"mouse":[]},"ui_text_delete_all_to_right.macos":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word":{"joypad":[],"keyboard":["Delete|ctrl"],"mouse":[]},"ui_text_delete_word.macos":{"joypad":[],"keyboard":["Delete|alt"],"mouse":[]},"ui_text_indent":{"joypad":[],"keyboard":["Tab"],"mouse":[]},"ui_text_newline":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_newline_above":{"joypad":[],"keyboard":["Enter|shift,ctrl","Kp Enter|shift,ctrl"],"mouse":[]},"ui_text_newline_blank":{"joypad":[],"keyboard":["Enter|ctrl","Kp Enter|ctrl"],"mouse":[]},"ui_text_scroll_down":{"joypad":[],"keyboard":["Down|ctrl"],"mouse":[]},"ui_text_scroll_down.macos":{"joypad":[],"keyboard":["Down|alt,ctrl"],"mouse":[]},"ui_text_scroll_up":{"joypad":[],"keyboard":["Up|ctrl"],"mouse":[]},"ui_text_scroll_up.macos":{"joypad":[],"keyboard":["Up|alt,ctrl"],"mouse":[]},"ui_text_select_all":{"joypad":[],"keyboard":["A|ctrl"],"mouse":[]},"ui_text_select_word_under_caret":{"joypad":[],"keyboard":["G|alt"],"mouse":[]},"ui_text_select_word_under_caret.macos":{"joypad":[],"keyboard":["G|ctrl,meta"],"mouse":[]},"ui_text_submit":{"joypad":[],"keyboard":["Enter","Kp Enter"],"mouse":[]},"ui_text_toggle_insert_mode":{"joypad":[],"keyboard":["Insert"],"mouse":[]},"ui_undo":{"joypad":[],"keyboard":["Z|ctrl"],"mouse":[]},"ui_up":{"joypad":[11,"1|-1"],"keyboard":["Up"],"mouse":[]}}' func before_each() -> void: @@ -105,3 +105,29 @@ func test_can_manage_joypad_input() -> void: InputHelper.replace_joypad_input_for_action(&"ui_accept", next_input, old_input) var replaced_input = InputHelper.get_joypad_inputs_for_action(&"ui_accept")[0] assert(replaced_input.button_index == JOY_BUTTON_A, "Should be the A button.") + + +func test_will_emit_changed_signal() -> void: + var empty_input = InputHelper.get_joypad_input_for_action(&"ui_test_empty") + assert(empty_input == null, "Should be no button for ui_test_empty.") + + # We have to use a dictionary because integers pass by value + var signal_calls: Dictionary = { count = 0 } + var on_joypad_input_changed: Callable + on_joypad_input_changed = func(action, input): + signal_calls.count += 1 + InputHelper.joypad_input_changed.connect(on_joypad_input_changed) + + # Set it from nothing + var next_input = InputEventJoypadButton.new() + next_input.button_index = JOY_BUTTON_RIGHT_SHOULDER + InputHelper.set_joypad_input_for_action(&"ui_test_empty", next_input) + assert(signal_calls.count == 1, "Should have emitted signal.") + + # Replace it + var next_next_input = InputEventJoypadButton.new() + next_next_input.button_index = JOY_BUTTON_B + InputHelper.set_joypad_input_for_action(&"ui_test_empty", next_next_input, false) + assert(signal_calls.count == 2, "Should have emitted signal.") + + InputHelper.joypad_input_changed.disconnect(on_joypad_input_changed)