class_name SceneManager extends Node2D
@onready var game = $".."
@onready var crates = $"../Crates"

func _ready() -> void:
	print("Hello")
	game.destroySignal.connect(destroy)
	buildLevel()
	
func destroy(body)->void:
	if body is Crate:
		body.queue_free()
		
func buildLevel()->void:
	updateCrates()

func updateCrates()->void:
	#is there a crate holder?
	var _crateTotal:int = 0
	if crates:
		for obj in crates.get_children():
			if obj is Crate:
				if not obj.tree_exited.is_connected(updateCrates):
					obj.tree_exited.connect(updateCrates)
				_crateTotal +=1
	print("Number of crates"+str(_crateTotal))
	game.totalCrates(_crateTotal)
