## InputManager — abstracts touch and mouse input into unified drag signals.
extends Node

signal drag_started(position: Vector2)
signal drag_moved(position: Vector2)
signal drag_ended(position: Vector2)

var _is_dragging: bool = false


func _input(event: InputEvent) -> void:
	if event is InputEventScreenTouch:
		if event.pressed:
			_emit_drag_started(event.position)
		else:
			_emit_drag_ended(event.position)
	elif event is InputEventScreenDrag:
		if _is_dragging:
			_emit_drag_moved(event.position)
	elif event is InputEventMouseButton and event.button_index == MOUSE_BUTTON_LEFT:
		if event.pressed:
			_emit_drag_started(event.position)
		else:
			_emit_drag_ended(event.position)
	elif event is InputEventMouseMotion and _is_dragging:
		_emit_drag_moved(event.position)


func _emit_drag_started(pos: Vector2) -> void:
	_is_dragging = true
	drag_started.emit(pos)


func _emit_drag_moved(pos: Vector2) -> void:
	drag_moved.emit(pos)


func _emit_drag_ended(pos: Vector2) -> void:
	_is_dragging = false
	drag_ended.emit(pos)
