class_name InputSetup extends RefCounted ## Registers the game's input actions in code, so that project.godot holds no ## serialized input events. Keys are physical positions, so WASD stays in ## place on German keyboards too. static func install() -> void: _add_keys("move_up", [KEY_W, KEY_UP]) _add_keys("move_down", [KEY_S, KEY_DOWN]) _add_keys("move_left", [KEY_A, KEY_LEFT]) _add_keys("move_right", [KEY_D, KEY_RIGHT]) _add_keys("save_game", [KEY_F5]) _add_keys("load_game", [KEY_F9]) _add_keys("toggle_pause", [KEY_ESCAPE]) _add_keys("next_style", [KEY_F2]) _add_keys("back", [KEY_ESCAPE]) _add_keys("style_1", [KEY_1]) _add_keys("style_2", [KEY_2]) _add_keys("style_3", [KEY_3]) _add_mouse_button("dig", MOUSE_BUTTON_LEFT) static func _add_keys(action: StringName, keys: Array[Key]) -> void: if InputMap.has_action(action): return InputMap.add_action(action) for key in keys: var event := InputEventKey.new() event.physical_keycode = key InputMap.action_add_event(action, event) static func _add_mouse_button(action: StringName, button: MouseButton) -> void: if InputMap.has_action(action): return InputMap.add_action(action) var event := InputEventMouseButton.new() event.button_index = button InputMap.action_add_event(action, event)