harvest/game/tools/configure_input.gd
2026-10-04 12:07:36 -04:00

72 lines
3.3 KiB
GDScript

extends SceneTree
## Writes the game's InputMap actions into project.godot (the prototype's actions, set by
## prototype/tools/configure_project.gd, are left as they are). Idempotent: re-running replaces
## only these actions. Run with the editor closed:
## godot --headless --path . --script res://game/tools/configure_input.gd
##
## | Action | Keyboard / mouse | Gamepad | Used from |
## |--------------|------------------|----------------|-----------|
## | fear | Q | Left shoulder | Step 4 |
## | patch (hold) | F | Y | Step 4 |
## | interact | E | X | Step 5 |
## | build_mode | B | D-pad up | Step 6 |
## | rotate_left | Z | D-pad left | Step 6 |
## | rotate_right | C | D-pad right | Step 6 |
## | build_next | Tab | D-pad down | Step 6 |
## | build_1..4 | 1, 2, 3, 4 | - | Step 6 |
## | cancel | Right mouse | B | Step 6 |
## | pause | Escape | Start | Step 11 |
## | hide_tips | Backspace | Back | Step 11 |
## | toggle_mic | M | - | Co-op |
## | sprint (hold)| Shift | L3 (stick) | Sprint |
## | weapon_next | Tab | D-pad down | Weapons |
## | weapon_1..3 | 1, 2, 3 | - | Weapons |
## The weapon keys are build mode's (build_next, build_1..3): outside build mode they pick weapons.
func _initialize() -> void:
_action("fear", [_key(KEY_Q), _joy(JOY_BUTTON_LEFT_SHOULDER)])
_action("patch", [_key(KEY_F), _joy(JOY_BUTTON_Y)])
_action("interact", [_key(KEY_E), _joy(JOY_BUTTON_X)])
_action("build_mode", [_key(KEY_B), _joy(JOY_BUTTON_DPAD_UP)])
_action("rotate_left", [_key(KEY_Z), _joy(JOY_BUTTON_DPAD_LEFT)])
_action("rotate_right", [_key(KEY_C), _joy(JOY_BUTTON_DPAD_RIGHT)])
_action("build_next", [_key(KEY_TAB), _joy(JOY_BUTTON_DPAD_DOWN)])
var number_keys: Array[Key] = [KEY_1, KEY_2, KEY_3, KEY_4]
for i in 4:
_action("build_%d" % (i + 1), [_key(number_keys[i])])
_action("cancel", [_mouse(MOUSE_BUTTON_RIGHT), _joy(JOY_BUTTON_B)])
_action("pause", [_key(KEY_ESCAPE), _joy(JOY_BUTTON_START)])
_action("hide_tips", [_key(KEY_BACKSPACE), _joy(JOY_BUTTON_BACK)])
_action("toggle_mic", [_key(KEY_M)])
_action("sprint", [_key(KEY_SHIFT), _joy(JOY_BUTTON_LEFT_STICK)])
_action("weapon_next", [_key(KEY_TAB), _joy(JOY_BUTTON_DPAD_DOWN)])
for i in 3:
_action("weapon_%d" % (i + 1), [_key(number_keys[i])])
var err := ProjectSettings.save()
print("configure_input: save -> %s" % error_string(err))
quit(0 if err == OK else 1)
func _action(action_name: String, events: Array[InputEvent]) -> void:
for e in events:
e.device = -1 # all devices, matching events created in the editor
ProjectSettings.set_setting("input/" + action_name, {"deadzone": 0.5, "events": events})
func _key(code: Key) -> InputEventKey:
var e := InputEventKey.new()
e.physical_keycode = code
return e
func _mouse(button: MouseButton) -> InputEventMouseButton:
var e := InputEventMouseButton.new()
e.button_index = button
return e
func _joy(button: JoyButton) -> InputEventJoypadButton:
var e := InputEventJoypadButton.new()
e.button_index = button
return e