class_name GamepadControl
extends Node
# Command from keyboard input


signal dir_changed(dir: Vector2)

var _last_dir = Vector2.ZERO


func _unhandled_input(event: InputEvent) -> void:
	if event is InputEventJoypadMotion:
		var joyEvent := event as InputEventJoypadMotion
		if joyEvent.get_axis() == JOY_AXIS_LEFT_X:
			_last_dir.x = joyEvent.get_axis_value()
			dir_changed.emit(_last_dir)
		elif joyEvent.get_axis() == JOY_AXIS_TRIGGER_RIGHT:
			_last_dir.y = joyEvent.get_axis_value()
		else:
			return

		dir_changed.emit(_last_dir)
