class_name InputMethod
## Tools for disambiguating game input methods.

enum Type {
	UNKNOWN,
	MOUSE_KEYBOARD,
	GAMEPAD,
	SONY,
	XBOX,
	NINTENDO,
}


static func _get_gamepad_type(device_id: int) -> Type:
	var name := Input.get_joy_name(device_id)
	if name.contains("Nintendo Switch"):
		return Type.NINTENDO
	if name.contains("Xbox"):
		return Type.XBOX
	# rpk: If you see this and think "HA! I could replace that with one simple regex!"...
	# ... buy me a beer sometime and ask me about the User Agent Regex.
	if (
		name.contains("PlayStation")
		or name.contains("PS1")
		or name.contains("PS2")
		or name.contains("PS3")
		or name.contains("PS4")
		or name.contains("PS5")
	):
		return Type.SONY

	return Type.GAMEPAD


static func get_method(event: InputEvent) -> Type:
	if event is InputEventKey or event is InputEventMouse:
		return Type.MOUSE_KEYBOARD

	if event is InputEventJoypadButton:
		return _get_gamepad_type((event as InputEventJoypadButton).device)

	if event is InputEventJoypadMotion:
		return _get_gamepad_type((event as InputEventJoypadMotion).device)

	return Type.UNKNOWN
