scavenge recipes first stage
This commit is contained in:
parent
ccb15800a3
commit
bc657be1ab
7 changed files with 59 additions and 17 deletions
|
|
@ -2,6 +2,8 @@ extends Inventory
|
|||
|
||||
@export var action_button : Button
|
||||
@export var craft_recipes : Array[CraftRecipe]
|
||||
@export var scavenge_recipes : Array[ScavengeRecipe]
|
||||
var matched_recipe : Recipe
|
||||
#@export var no_style : StyleBox
|
||||
@export var assemble_style : StyleBox
|
||||
@export var assemble_style_hover : StyleBox
|
||||
|
|
@ -15,6 +17,7 @@ extends Inventory
|
|||
func _ready() -> void:
|
||||
super()
|
||||
#style_scavenge()
|
||||
check_recipes()
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
|
|
@ -32,22 +35,39 @@ func _notification(what: int) -> void:
|
|||
|
||||
func check_recipes():
|
||||
print("checking now")
|
||||
style_none()
|
||||
# write checking logic
|
||||
var possible_recipes : Array[CraftRecipe] = craft_recipes.duplicate()
|
||||
for x in range(9):
|
||||
for recipe in possible_recipes:
|
||||
if recipe.ingredients[x] and slots[x].item:
|
||||
if recipe.ingredients[x].item_name != slots[x].item.item_name:
|
||||
|
||||
if filled_slots() == 1:
|
||||
# check scavenging recipes
|
||||
var item_to_scavenge : ItemData
|
||||
for slot in slots:
|
||||
if slot.item:
|
||||
item_to_scavenge = slot.item
|
||||
break
|
||||
|
||||
for recipe in scavenge_recipes:
|
||||
if recipe.input.item_name == item_to_scavenge.item_name:
|
||||
matched_recipe = recipe
|
||||
style_scavenge()
|
||||
return
|
||||
|
||||
elif filled_slots() > 1:
|
||||
# check crafting recipes
|
||||
var possible_recipes : Array[CraftRecipe] = craft_recipes.duplicate()
|
||||
for x in range(9):
|
||||
for recipe in possible_recipes:
|
||||
if recipe.ingredients[x] and slots[x].item:
|
||||
if recipe.ingredients[x].item_name != slots[x].item.item_name:
|
||||
possible_recipes.erase(recipe)
|
||||
elif recipe.ingredients[x] or slots[x].item:
|
||||
possible_recipes.erase(recipe)
|
||||
elif recipe.ingredients[x] or slots[x].item:
|
||||
possible_recipes.erase(recipe)
|
||||
print("Possible recipes: " + str(possible_recipes.size()))
|
||||
if possible_recipes.size() == 1:
|
||||
print("found our recipe!")
|
||||
style_assemble()
|
||||
else:
|
||||
style_none()
|
||||
pass
|
||||
print("Possible recipes: " + str(possible_recipes.size()))
|
||||
if possible_recipes.size() == 1:
|
||||
print("found our recipe!")
|
||||
matched_recipe = possible_recipes[0]
|
||||
style_assemble()
|
||||
return
|
||||
|
||||
func style_assemble():
|
||||
action_button.add_theme_stylebox_override("normal",assemble_style)
|
||||
|
|
@ -69,3 +89,7 @@ func style_none():
|
|||
action_button.remove_theme_stylebox_override("pressed")
|
||||
action_button.text = "no matching recipe"
|
||||
action_button.disabled = true
|
||||
|
||||
|
||||
func _on_action_button_pressed() -> void:
|
||||
pass # Replace with function body.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue