extends Node class_name InputHandler var camera_input_method := CameraInput.MOUSE var camera_input_direction := Vector2.ZERO func _unhandled_input(event: InputEvent) -> void: # If user clicks on the window, capture the mouse and direct the camera with it if Input.get_mouse_mode() != Input.MOUSE_MODE_CAPTURED: return if event is InputEventMouseMotion: camera_input_method = CameraInput.MOUSE camera_input_direction = event.screen_relative elif event is InputEventJoypadMotion: # TODO: add these settings! camera_input_method = CameraInput.JOYSTICK camera_input_direction = Input.get_vector( "camera-left", "camera-right", "camera-up", "camera-down" ) func get_player_input() -> InputPacket: var p: InputPacket = InputPacket.new() p.camera_input_method = camera_input_method if camera_input_method == CameraInput.MOUSE: # TODO: clumsy handling of last relative mouse event! if Input.get_last_mouse_velocity().length() > 0.05: p.camera_input_direction = camera_input_direction p.player_movement_direction = Input.get_vector( "player-left", "player-right", "player-forward", "player-backward" ) if p.player_movement_direction != Vector2.ZERO: p.player_actions.append("walk") if Input.is_action_just_pressed("player-dash"): p.player_actions.append("dash") if Input.is_action_just_pressed("player-slash"): p.player_actions.append("slash") if Input.is_action_just_pressed("player-shoot"): p.player_actions.append("shoot") if p.player_actions.is_empty(): p.player_actions.append("idle") return p