Updated crafting machine code to check for valid recipe when deciding to enable/disable the coin machine

This commit is contained in:
akshay committed 2022-08-14 19:29:17 -04:00
1 parent 46817025a6
commit 01e57c169c
2 files changed
+11 -6

No files matched your search

+9 -3
View File
@@ -6,9 +6,15 @@ export var recipes: Resource
func _ready():
assert(recipes != null)
func craft_item():
func get_craft_recipe_item():
var items_in_slots = [$slot_1.item_in_hold.item_type, $slot_2.item_in_hold.item_type]
var crafted_item = recipes.find_recipe(items_in_slots)
return recipes.find_recipe(items_in_slots)
func can_craft_recipe():
return get_craft_recipe_item() != null
func craft_item():
var crafted_item = get_craft_recipe_item()
if crafted_item == null:
return
$slot_1.destroy_item()
@@ -29,7 +35,7 @@ func should_enable_coin_machine():
return false
if not $slot_1.has_item() or not $slot_2.has_item():
return false
return true
return can_craft_recipe()
func _on_craft_item_holder_item_changed(item):
$coin_machine.enabled = should_enable_coin_machine()