fix(home-button): add busy guard against double-tap during navigation transition
This commit is contained in:
@@ -1,21 +1,35 @@
|
|||||||
## HomeButton — tappable button that navigates between the hospital and the garden area.
|
## 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
|
class_name HomeButton extends Node2D
|
||||||
|
|
||||||
const BUTTON_HALF_SIZE: float = 32.0
|
const BUTTON_HALF_SIZE: float = 32.0
|
||||||
|
|
||||||
@export var go_to_garden: bool = true
|
@export var go_to_garden: bool = true
|
||||||
|
|
||||||
|
var _busy: bool = false
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
|
if _busy:
|
||||||
|
return
|
||||||
if not event is InputEventScreenTouch:
|
if not event is InputEventScreenTouch:
|
||||||
return
|
return
|
||||||
if not (event as InputEventScreenTouch).pressed:
|
var touch: InputEventScreenTouch = event as InputEventScreenTouch
|
||||||
|
if not touch.pressed:
|
||||||
return
|
return
|
||||||
var touch_pos: Vector2 = (event as InputEventScreenTouch).position
|
var local: Vector2 = to_local(touch.position)
|
||||||
var local: Vector2 = to_local(touch_pos)
|
|
||||||
if abs(local.x) > BUTTON_HALF_SIZE or abs(local.y) > BUTTON_HALF_SIZE:
|
if abs(local.x) > BUTTON_HALF_SIZE or abs(local.y) > BUTTON_HALF_SIZE:
|
||||||
return
|
return
|
||||||
|
if not is_instance_valid(RoomNavigator):
|
||||||
|
return
|
||||||
|
_busy = true
|
||||||
if go_to_garden:
|
if go_to_garden:
|
||||||
|
RoomNavigator.home_entered.connect(_on_transition_done, CONNECT_ONE_SHOT)
|
||||||
RoomNavigator.go_to_home()
|
RoomNavigator.go_to_home()
|
||||||
else:
|
else:
|
||||||
|
RoomNavigator.hospital_entered.connect(_on_transition_done, CONNECT_ONE_SHOT)
|
||||||
RoomNavigator.go_to_hospital()
|
RoomNavigator.go_to_hospital()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_transition_done() -> void:
|
||||||
|
_busy = false
|
||||||
|
|||||||
Reference in New Issue
Block a user