Fixed Controller Rebinding to support Axis

This commit is contained in:
Snoweuph 2023-04-11 22:28:22 +02:00
parent 6fa3602b65
commit d8ec01161e
4 changed files with 19 additions and 5 deletions

View file

@ -21,6 +21,11 @@ func load_data():
"move_down": KEY_S, "move_down": KEY_S,
"move_right": KEY_D, "move_right": KEY_D,
"attack": "m" + str(MOUSE_BUTTON_LEFT), "attack": "m" + str(MOUSE_BUTTON_LEFT),
"move_up_controller": "j" + str(JOY_AXIS_LEFT_Y) + "/-1.00",
"move_left_controller": "j" + str(JOY_AXIS_LEFT_X) + "/-1.00",
"move_down_controller": "j" + str(JOY_AXIS_LEFT_Y) + "/1.00",
"move_right_controller": "j" + str(JOY_AXIS_LEFT_X) + "/1.00",
"attack_controller": "b" + str(JOY_BUTTON_A),
} }
save_data() save_data()
else: else:

View file

@ -9,7 +9,12 @@ extends Node
"move_down", "move_down",
"move_left", "move_left",
"move_right", "move_right",
"attack" "attack",
"move_up_controller",
"move_down_controller",
"move_left_controller",
"move_right_controller",
"attack_controller"
] ]
const resolutions_dictionary : Dictionary = { const resolutions_dictionary : Dictionary = {
@ -87,9 +92,11 @@ func set_controls_from_save_file() -> void:
control_event = InputEventJoypadButton.new() control_event = InputEventJoypadButton.new()
control_event.button_index = binding control_event.button_index = binding
"j": "j":
binding = int(binding.right(binding.length()-1)) binding = binding.right(binding.length()-1)
binding = binding.split("/")
control_event = InputEventJoypadMotion.new() control_event = InputEventJoypadMotion.new()
control_event.axis = binding control_event.axis = int(binding[0])
control_event.axis_value = float(binding[1])
_: _:
control_event = InputEventKey.new() control_event = InputEventKey.new()
control_event.set_keycode(binding) control_event.set_keycode(binding)

View file

@ -9,8 +9,10 @@ func _ready():
func display_key (): func display_key ():
self.text = "%s" % InputMap.action_get_events(input_action_name)[0].as_text() self.text = "%s" % InputMap.action_get_events(input_action_name)[0].as_text()
if self.text.begins_with("Joypad Motion on Axis"): if self.text.begins_with("Joypad Motion on Axis"):
print(self.text)
var split_text = self.text.split(" ") var split_text = self.text.split(" ")
self.text = split_text[3] + " " + split_text[4] self.text = "+" if float(split_text[13]) > 0 else "-"
self.text += split_text[3] + " " + split_text[4] + " "
if self.text.begins_with("Joypad Button"): if self.text.begins_with("Joypad Button"):
var split_text = self.text.split(" ") var split_text = self.text.split(" ")
self.text = split_text[1] + " " + split_text[2] self.text = split_text[1] + " " + split_text[2]

View file

@ -59,7 +59,7 @@ func remap_key(event):
"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":
Save.game_data["%s" % [remap_action]] = "j" + str(event.axis) 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":