2 class_name InputHandler
5 var camera_input_method := CameraInput.MOUSE
6 var camera_input_direction := Vector2.ZERO
9 func _unhandled_input(event: InputEvent) -> void:
10 # If user clicks on the window, capture the mouse and direct the camera with it
11 if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED:
14 if event is InputEventMouseMotion:
15 camera_input_method = CameraInput.MOUSE
16 camera_input_direction = event.screen_relative
17 elif event is InputEventJoypadMotion:
18 # TODO: add these settings!
19 camera_input_method = CameraInput.JOYSTICK
20 camera_input_direction = Input.get_vector(
21 "camera-left", "camera-right", "camera-up", "camera-down"
25 func get_player_input() -> InputPacket:
26 var p: InputPacket = InputPacket.new()
28 p.camera_input_method = camera_input_method
29 if camera_input_method == CameraInput.MOUSE:
30 # TODO: clumsy handling of last relative mouse event!
31 if Input.get_last_mouse_velocity().length() > 0.05:
32 p.camera_input_direction = camera_input_direction
34 p.player_movement_direction = Input.get_vector(
35 "player-left", "player-right", "player-forward", "player-backward"
37 if p.player_movement_direction != Vector2.ZERO:
38 p.player_actions.append("walk")
40 if Input.is_action_just_pressed("player-dash"):
41 p.player_actions.append("dash")
43 if Input.is_action_just_pressed("player-slash"):
44 p.player_actions.append("slash")
46 if Input.is_action_just_pressed("player-shoot"):
47 p.player_actions.append("shoot")
49 if p.player_actions.is_empty():
50 p.player_actions.append("idle")