class_name MergeRecipes

# Add new crafting recipes here.
# speed_threshold = minimum collision_speed to trigger the merge.
static var _list: Array[Dictionary] = [
	{
		"ingredients":      ["leather", "stick"],
		"result_scene":     "res://scenes/LeatherBoots.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["rock", "rock"],
		"result_scene":     "res://scenes/Boulder.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["stick", "stick"],
		"result_scene":     "res://scenes/StickArmor.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["leather", "rock"],
		"result_scene":     "res://scenes/LeatherArmor.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["leather", "iron"],
		"result_scene":     "res://scenes/PlateArmor.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["rock", "stick"],
		"result_scene":     "res://scenes/WoodenShield.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["iron", "rock"],
		"result_scene":     "res://scenes/IronShield.tscn",
		"speed_threshold":  18.0,
	},
	{
		"ingredients":      ["iron", "Smith"],
		"result_scene":     "res://scenes/MetalPlate.tscn",
		"speed_threshold":  0.1,
	},
	{
		"ingredients":      ["essence", "Enchanted_Table"],
		"result_scene":     "res://scenes/EnchantedSphere.tscn",
		"speed_threshold":  0.1,
	}
]

static func find(type_a: String, type_b: String, speed: float) -> Dictionary:
	for r in _list:
		var a: String = r["ingredients"][0]
		var b: String = r["ingredients"][1]
		var match_ab := (a == type_a and b == type_b) or (a == type_b and b == type_a)
		if match_ab and speed >= float(r.get("speed_threshold", 3.0)):
			return r
	return {}
