extends Node

const SOUND_EFFECT = preload("res://Audio/SoundEffect.tscn")

onready var resource_preloader = $ResourcePreloader

func play_sound(sound_name, pitch_scale = 1):
	if resource_preloader.has_resource(sound_name) and Global.main_node != null:
		var inst = SOUND_EFFECT.instance()
		inst.stream = resource_preloader.get_resource(sound_name)
		inst.pitch_scale = pitch_scale
		inst.play()
		#get_tree().root.add_child(inst)
		Global.main_node.add_child(inst)

func play_sound_random(array: Array, pitch_scale = 1):
	var a: Array = array.duplicate()
	a.shuffle()
	play_sound(a.front(), pitch_scale)
