extends Node

const REACTIONS_DIRECTORY = "res://assets/reactions/"

var reactions: Array[Reaction]

func _ready() -> void:
	for file in ResourceLoader.list_directory(REACTIONS_DIRECTORY):
		reactions.append(load(REACTIONS_DIRECTORY + file))

func react(input_substances: Array[Substance], temperature: float) -> Array[Substance]:
	var filter_func: Callable = func(reaction: Reaction) -> bool:
		if reaction.reaction_temperature != -1:
			return (reaction.input_substances == input_substances) and temperature >= reaction.reaction_temperature
		else:
			return reaction.input_substances == input_substances
	
	var filtered: Array[Reaction] = reactions.filter(filter_func)
	
	if len(filtered) > 0:
		return filtered[0].output_substances.duplicate()
	else:
		return []
