## ElevatorButton — tappable button that navigates the camera to a target floor.
class_name ElevatorButton extends Node2D

const BUTTON_HALF_SIZE: float = 40.0

@export var target_floor: int = 0


func _input(event: InputEvent) -> void:
	var screen_pos: Vector2
	if event is InputEventScreenTouch and event.pressed:
		screen_pos = event.position
	elif event is InputEventMouseButton and event.pressed and event.button_index == MOUSE_BUTTON_LEFT:
		screen_pos = event.position
	else:
		return
	var canvas_transform: Transform2D = get_viewport().get_canvas_transform()
	var world_pos: Vector2 = canvas_transform.affine_inverse() * screen_pos
	var local_pos: Vector2 = to_local(world_pos)
	if abs(local_pos.x) <= BUTTON_HALF_SIZE and abs(local_pos.y) <= BUTTON_HALF_SIZE:
		_on_pressed()


func _on_pressed() -> void:
	if target_floor < 0:
		return
	RoomNavigator.go_to_floor(target_floor)
	_play_bounce()


func _play_bounce() -> void:
	var tween: Tween = create_tween()
	tween.tween_property(self, "scale", Vector2(1.15, 1.15), 0.08)
	tween.tween_property(self, "scale", Vector2(1.0, 1.0), 0.08)
