Skip to content

Commit 705a7cc

Browse files
committed
Fix default input device when no joypad is connected
In commit 0a547d0 I simplified the way that our input hint components choose a default device: rather than reimplementing Input Helper's device detection, we use a pair of properties from the helper. Unfortunately I picked the wrong ones: I used last_known_joypad_device and last_known_joypad_index. As the name suggests, the last_known_joypad_device will never be "keyboard". Its docstring claims it will be "" if no gamepad is connected; in fact it is currently "generic", which I submitted nathanhoad/godot_input_helper#87 to fix. As a result, if you have no gamepad connected, then gamepad hints will always be shown. Instead, use InputHelper.device and InputHelper.device_index, which are the type and index of the last device that the player used to control the game. Before any input events have been received, these default to joypad 0 if there is a joypad connected, and "keyboard" / -1 if not.
1 parent 09abd29 commit 705a7cc

File tree

3 files changed

+3
-12
lines changed

3 files changed

+3
-12
lines changed

scenes/game_elements/props/hint/input_key/gamepad_input.gd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,7 @@ func _physics_process(_delta: float) -> void:
8080

8181
func _ready() -> void:
8282
InputHelper.device_changed.connect(_on_input_device_changed)
83-
_on_input_device_changed(
84-
InputHelper.last_known_joypad_device,
85-
InputHelper.last_known_joypad_index,
86-
)
83+
_on_input_device_changed(InputHelper.device, InputHelper.device_index)
8784

8885

8986
func _on_input_device_changed(device: String, _device_index: int) -> void:

scenes/game_elements/props/hint/input_key/interact_input.gd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,7 @@ func _physics_process(_delta: float) -> void:
2828

2929
func _ready() -> void:
3030
InputHelper.device_changed.connect(_on_input_device_changed)
31-
_on_input_device_changed(
32-
InputHelper.last_known_joypad_device,
33-
InputHelper.last_known_joypad_index,
34-
)
31+
_on_input_device_changed(InputHelper.device, InputHelper.device_index)
3532

3633

3734
func _on_input_device_changed(device: String, _device_index: int) -> void:

scenes/game_elements/props/hint/input_key/keyboard_input.gd

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ func _physics_process(_delta: float) -> void:
2020

2121
func _ready() -> void:
2222
InputHelper.device_changed.connect(_on_input_device_changed)
23-
_on_input_device_changed(
24-
InputHelper.last_known_joypad_device,
25-
InputHelper.last_known_joypad_index,
26-
)
23+
_on_input_device_changed(InputHelper.device, InputHelper.device_index)
2724

2825

2926
func _on_input_device_changed(device: String, _device_index: int) -> void:

0 commit comments

Comments
 (0)