Files
Cozypaw-Hospital/scripts/objects/home_button.gd

36 lines
1.0 KiB
GDScript

## HomeButton — tappable button that navigates between the hospital and the garden area.
## go_to_garden = true calls RoomNavigator.go_to_home(); false calls RoomNavigator.go_to_hospital().
class_name HomeButton extends Node2D
const BUTTON_HALF_SIZE: float = 32.0
@export var go_to_garden: bool = true
var _busy: bool = false
func _input(event: InputEvent) -> void:
if _busy:
return
if not event is InputEventScreenTouch:
return
var touch: InputEventScreenTouch = event as InputEventScreenTouch
if not touch.pressed:
return
var local: Vector2 = to_local(touch.position)
if abs(local.x) > BUTTON_HALF_SIZE or abs(local.y) > BUTTON_HALF_SIZE:
return
if not is_instance_valid(RoomNavigator):
return
_busy = true
if go_to_garden:
RoomNavigator.home_entered.connect(_on_transition_done, CONNECT_ONE_SHOT)
RoomNavigator.go_to_home()
else:
RoomNavigator.hospital_entered.connect(_on_transition_done, CONNECT_ONE_SHOT)
RoomNavigator.go_to_hospital()
func _on_transition_done() -> void:
_busy = false