Improve Remap Controller Axis Detection

This commit is contained in:
Snoweuph 2023-04-11 22:39:39 +02:00
parent d8ec01161e
commit 47ddb86bbb

View file

@ -50,20 +50,20 @@ func start_remap(button : Button, action : String):
pass pass
func remap_key(event): func remap_key(event):
set_process_unhandled_key_input(false)
for key in InputMap.action_get_events(remap_action):
InputMap.action_erase_event(remap_action, key)
InputMap.action_add_event(remap_action, event)
match str(event.get_class()): match str(event.get_class()):
"InputEventJoypadButton": "InputEventJoypadButton":
Save.game_data["%s" % [remap_action]] = "b" + str(event.button_index) Save.game_data["%s" % [remap_action]] = "b" + str(event.button_index)
"InputEventJoypadMotion": "InputEventJoypadMotion":
if abs(event.axis_value) < 0.5: return
Save.game_data["%s" % [remap_action]] = "j" + str(event.axis) + str("/1.00" if event.axis_value > 0 else "/-1.00") Save.game_data["%s" % [remap_action]] = "j" + str(event.axis) + str("/1.00" if event.axis_value > 0 else "/-1.00")
"InputEventMouseButton": "InputEventMouseButton":
Save.game_data["%s" % [remap_action]] = "m" + str(event.button_index) Save.game_data["%s" % [remap_action]] = "m" + str(event.button_index)
"InputEventKey": "InputEventKey":
Save.game_data["%s" % [remap_action]] = event.keycode Save.game_data["%s" % [remap_action]] = event.keycode
set_process_unhandled_key_input(false)
for key in InputMap.action_get_events(remap_action):
InputMap.action_erase_event(remap_action, key)
InputMap.action_add_event(remap_action, event)
remap_button.display_key() remap_button.display_key()
remap_button.grab_focus() remap_button.grab_focus()
remap_button.disabled = false remap_button.disabled = false