extends Control

@export var amount = 3
@export var starting_consistency: int = 20
@onready var consistency: int = starting_consistency

@onready var label: Label = $Label
@onready var consistency_timer: Timer = $ConsistencyTimer

@onready var game_on: bool = true

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	GameVariables.bubble_pickup.connect(_on_bubble_pickup)
	label_update(consistency)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	if consistency == 0:
		game_on = false
		GameVariables.game_over.emit()


func _on_bubble_pickup():
	consistency += amount
	label_update(consistency)
	

func _on_consistency_timer_timeout() -> void:
	consistency -= 1
	label_update(consistency)


func label_update(number):
	if game_on:
		label.text = "BUBBLE CONSISTENCY: " + str(number)
	else:
		label.text = "GAME OVER!"
