extends Area2D

onready var sounds = $sounds.get_children() 
var bozuk = false

var bozulmaSayaci = 0

func _ready():
	$Control/repair.disabled = true
	pass

func _process(delta):
	
	pass

func _on_kabin_body_entered(body):
	var soundCount = sounds.size()
	var secili = rand_range(0, soundCount)
	sounds[secili].play()
	$light.modulate = Color(1, 0, 0)
	$tuvaletSuresi.wait_time = body.tuvaletSuresi
	$tuvaletSuresi.start()
	body.tuvaleteGitti = true
	body.hide()

func _on_tuvaletSuresi_timeout():
	if name == "kabin1":
		global.sureBittiler["kabin1Path"] = true
		pass
	if name == "kabin2":
		global.sureBittiler["kabin2Path"] = true
		pass
	if name == "kabin3":
		global.sureBittiler["kabin3Path"] = true
		pass
	if name == "kabin4":
		global.sureBittiler["kabin4Path"] = true
		pass
	pass


func _on_kabin_body_exited(body):
	$toiletFlush.play()
	if bozuk:
		body.begendi = false
		global.begeniler -= 1
	else:
		body.begendi = true
		global.begeniler += 1
	bozulmaSayaci += 1
	if bozulmaSayaci >= 1:
		$Control/repair.disabled = false
		bozuk = true
		$Control/repair.modulate = Color(1, 0, 0)
		pass
	$light.modulate = Color(0, 1, 0)
	body.show()
	pass


func _on_repair_pressed():
	$clean.play()
	bozuk = false
	bozulmaSayaci = 0
	global.para -= 5
	$Control/repair.modulate = Color(1,1,1)
#	$moneyEarn.play()
	pass


func _on_moneyEarn_finished():
#	$moneyEarn.stop()
	pass # Replace with function body.
