extends Node

var mini_inventory: Array[RuntimeSubstanceData] = []
signal inventory_updated(substances: Array[RuntimeSubstanceData])

func _on_interactible_interacted(with: DraggableObject) -> void:
	if with.is_in_group("solid_source") and mini_inventory == []:
		mini_inventory = [RuntimeSubstanceData.new()]
		mini_inventory[0].substance = with.get_node("SubstanceData").substance
		mini_inventory[0].amount = 5
		mini_inventory[0].temperature = 20
		GuiSignalBus.push("Ложкой взято 5 мг. %s" % [mini_inventory[0].substance.get_formula()])
		
	elif with.is_in_group("solid_source") and mini_inventory != []:
		mini_inventory = []
		GuiSignalBus.push("Ложка опустошена")
	elif with.is_in_group("flask") and mini_inventory != []:
		var log_message = "В пробирку засыпано "
		for sub in mini_inventory:
			log_message += "%s мг. %s, " % [str(sub.amount),sub.substance.get_formula()]
		GuiSignalBus.push(log_message)
		with.get_node("%Inventory").add_inventory(mini_inventory)
		mini_inventory = []
		
	elif with.is_in_group("flask") and mini_inventory == []:
		mini_inventory = with.get_node("%Inventory").extract_solid(5)
		var log_message = "Из пробирки изъято "
		for sub in mini_inventory:
			log_message += "%s мг. %s, " % [str(sub.amount),sub.substance.get_formula()]
		GuiSignalBus.push(log_message)
	inventory_updated.emit(mini_inventory)
