class_name LerpableCamera extends Camera2D

signal move_completed

@export var focus_starting_position: Vector2 = Vector2(0.0, -12.0)
var lerp_speed = 1.0
var focus_start = focus_starting_position
var focus_target = focus_starting_position
var t = 0.0

func _ready():
	offset = focus_starting_position

func _process(delta):
	if focus_start != focus_target and t < 1.0:
		t += lerp_speed * delta
		var smooth_t = smoothstep(0.0, 1.0, t)
		offset = lerp(focus_start, focus_target, smooth_t)
		if focus_start == focus_target or t >= 1.0:
			offset = focus_target
			focus_start = focus_target
			move_completed.emit()

func lerp_to(point: Vector2, relative = false, speed = 1.0):
	focus_start = offset
	focus_target = point if relative else point - (global_position - focus_starting_position)
	t = 0.0
	lerp_speed = speed
	
func teleport_to(point: Vector2, relative = false):
	t = 1.0
	offset = point if relative else point - (global_position - focus_starting_position)
	focus_target = offset
	focus_start = focus_target
