extends InputStrategy
class_name InputStrategy_Dragging

var mouse_anchor : Vector2 = Vector2(0, 0)
var drag_column = 0

func enter() -> void:
	mouse_anchor = get_viewport().get_mouse_position()
	var pos = parentManager.get_letter_manager().logical_position_from_screen_position(mouse_anchor)
	drag_column = pos.col
	if (drag_column < 0):
		drag_column = 0

	if (drag_column >= parentManager.get_letter_manager().Columns):
		drag_column = parentManager.get_letter_manager().Columns - 1

func exit() -> void:
	parentManager.get_letter_manager().clearVisualShift(drag_column)

func update() -> void:
	if (not Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)):
		transition_to(State.DRAG_OUTRO)
		return

	var deltaY = get_viewport().get_mouse_position().y - mouse_anchor.y

	var heightjump = parentManager.get_letter_manager().LetterScreenHeight * 0.6

	if (deltaY > heightjump):
		parentManager.get_letter_manager().spin_puzzle_column(drag_column, 1)
		mouse_anchor.y += parentManager.get_letter_manager().LetterScreenHeight 
		deltaY -= parentManager.get_letter_manager().LetterScreenHeight

	if (deltaY < -heightjump):
		parentManager.get_letter_manager().spin_puzzle_column(drag_column, -1)
		mouse_anchor.y -= parentManager.get_letter_manager().LetterScreenHeight 
		deltaY += parentManager.get_letter_manager().LetterScreenHeight


	parentManager.get_letter_manager().set_visual_shift(drag_column, deltaY)


