extends Node2D

## Await Demo: Proving await doesn't freeze the game

var is_waiting = false

func _ready():
	$Label.text = "Click the button to test await"
	$Button.pressed.connect(_on_button_pressed)

func _process(delta):
	# This sprite rotates EVERY frame, no matter what
	$Sprite2D.rotation += 2.0 * delta

func _on_button_pressed():
	if is_waiting:
		return
		
	is_waiting = true
	$Button.disabled = true
	$ColorRect.color = Color(1.0, 0.2, 0.2, 0.5) # Turn red
	
	print("Started waiting...")
	$Label.text = "Function paused for 2 seconds...\nNotice the apple keeps spinning!"
	
	# THE MAGIC KEYWORD
	await get_tree().create_timer(2.0).timeout
	
	print("Finished waiting!")
	$Label.text = "Done! Function resumed."
	$ColorRect.color = Color(0.2, 0.8, 0.2, 0.5) # Turn green
	
	is_waiting = false
	$Button.disabled = false
