extends Node
class_name MarbleBag

var bag_contents : Array
var current_bag_index : int

# Note, anytime new items are added to the bag, the full contents of the bag are shuffled and reset so this is
# not an appropriate function to use for dynamic bag changes
func add(items : Array):
	bag_contents.append_array(items)
	_reshuffle_contents()

func _reshuffle_contents():
	bag_contents.shuffle()
	current_bag_index = 0
	
func next() -> Variant:
	if current_bag_index >= bag_contents.size():
		_reshuffle_contents()
		
	current_bag_index = current_bag_index + 1
	
	return bag_contents[current_bag_index - 1]

func clear() -> void:
	bag_contents.clear()
	current_bag_index = 0