extends Node

var fountain_delay = 5
var fountain_time = 0

func _ready():
	global.particles_node = $Particles
	
	if global.player_nickname:
		$Controls/EditNickname.text = global.player_nickname
		
	if global.bot_amount:
		$Controls/SliderBotAmount.value = global.bot_amount
	
	if global.frags_limit:
		$Controls/SpinFragsLimit.value = global.frags_limit
	
	if global.time_limit:
		$Controls/SpinTimeLimit.value = global.time_limit
	
	if global.easy_bots:
		$Controls/CheckEasyBots.pressed = global.easy_bots
	
	if global.level:
		$Controls/SpinLevel.value = global.level

func _process(delta):
	if Input.is_action_just_released("ui_cancel"):
		get_tree().quit()
	
	fountain_time += delta
	
	if fountain_time >= fountain_delay:
		fountain_time = 0
		
		for fountain in $Fountains.get_children():
			global.add_gibs(fountain.position, Vector2(0, 5.0))

func _on_ButtonPlay_pressed():
	global.player_nickname = $Controls/EditNickname.text
	global.bot_amount = $Controls/SliderBotAmount.value
	global.frags_limit = $Controls/SpinFragsLimit.value 
	global.time_limit = $Controls/SpinTimeLimit.value
	global.easy_bots = $Controls/CheckEasyBots.pressed
	global.level = $Controls/SpinLevel.value
	
	get_tree().change_scene("res://scenes/game.tscn")

func _on_ButtonQuit_pressed():
	get_tree().quit()

func _on_ToggleFullscreen_pressed():
	OS.window_fullscreen = $Controls/ToggleFullscreen.pressed
