diff --git a/crafting/craft_recipe.gd b/crafting/craft_recipe.gd index 0a2787c..4087a82 100644 --- a/crafting/craft_recipe.gd +++ b/crafting/craft_recipe.gd @@ -1,4 +1,4 @@ -extends Resource +extends Recipe class_name CraftRecipe @export var ingredients : Array[ItemData] = [null,null,null,null,null,null,null,null,null] diff --git a/crafting/recipe.gd b/crafting/recipe.gd new file mode 100644 index 0000000..8c995da --- /dev/null +++ b/crafting/recipe.gd @@ -0,0 +1,2 @@ +extends Resource +class_name Recipe diff --git a/crafting/recipe.gd.uid b/crafting/recipe.gd.uid new file mode 100644 index 0000000..65e6aa3 --- /dev/null +++ b/crafting/recipe.gd.uid @@ -0,0 +1 @@ +uid://cp4ujmfinylse diff --git a/crafting/scavenge_recipe.gd b/crafting/scavenge_recipe.gd index 3b8538a..91d98aa 100644 --- a/crafting/scavenge_recipe.gd +++ b/crafting/scavenge_recipe.gd @@ -1,4 +1,4 @@ -extends Resource +extends Recipe class_name ScavengeRecipe @export var input : ItemData diff --git a/crafting/scavenges/testScavenge.tres b/crafting/scavenges/testScavenge.tres new file mode 100644 index 0000000..a21857f --- /dev/null +++ b/crafting/scavenges/testScavenge.tres @@ -0,0 +1,10 @@ +[gd_resource type="Resource" script_class="ScavengeRecipe" load_steps=4 format=3 uid="uid://deohei5avmspt"] + +[ext_resource type="Resource" uid="uid://88v5bcyrgpob" path="res://items/large_psu_item.tres" id="1_20hhf"] +[ext_resource type="Script" uid="uid://dccraom7a7e8d" path="res://inv_system/item_data.gd" id="1_o2l1m"] +[ext_resource type="Script" uid="uid://boqr1fowaqmt0" path="res://crafting/scavenge_recipe.gd" id="2_20hhf"] + +[resource] +script = ExtResource("2_20hhf") +input = ExtResource("1_20hhf") +metadata/_custom_type_script = "uid://boqr1fowaqmt0" diff --git a/inv_system/crafting_panel.gd b/inv_system/crafting_panel.gd index 3c6e446..dfa920d 100644 --- a/inv_system/crafting_panel.gd +++ b/inv_system/crafting_panel.gd @@ -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. diff --git a/inv_system/crafting_panel.tscn b/inv_system/crafting_panel.tscn index 7dff2ca..cbd56bb 100644 --- a/inv_system/crafting_panel.tscn +++ b/inv_system/crafting_panel.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=9 format=3 uid="uid://f06ym5ujhdsc"] +[gd_scene load_steps=11 format=3 uid="uid://f06ym5ujhdsc"] [ext_resource type="Script" uid="uid://br4fgimf7nygr" path="res://inv_system/crafting_panel.gd" id="1_441s3"] [ext_resource type="PackedScene" uid="uid://dgqs20xf7l8c" path="res://inv_system/item_slot.tscn" id="2_h0v0h"] [ext_resource type="Script" uid="uid://b4iu5xrdf0evs" path="res://crafting/craft_recipe.gd" id="2_ytbts"] [ext_resource type="Resource" uid="uid://dp4hnei3ur6oe" path="res://crafting/crafts/computer_craft.tres" id="3_4h4i0"] +[ext_resource type="Script" uid="uid://boqr1fowaqmt0" path="res://crafting/scavenge_recipe.gd" id="4_qjage"] +[ext_resource type="Resource" uid="uid://deohei5avmspt" path="res://crafting/scavenges/testScavenge.tres" id="5_8c40c"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h0v0h"] content_margin_left = 0.0 @@ -85,6 +87,7 @@ offset_bottom = 382.0 script = ExtResource("1_441s3") action_button = NodePath("MarginContainer/VBoxContainer/ActionButton") craft_recipes = Array[ExtResource("2_ytbts")]([ExtResource("3_4h4i0")]) +scavenge_recipes = Array[ExtResource("4_qjage")]([ExtResource("5_8c40c")]) assemble_style = SubResource("StyleBoxFlat_h0v0h") assemble_style_hover = SubResource("StyleBoxFlat_441s3") assemble_style_pressed = SubResource("StyleBoxFlat_h0v0h") @@ -151,3 +154,5 @@ layout_mode = 2 custom_minimum_size = Vector2(0, 52.585) layout_mode = 2 text = "No matching recipie" + +[connection signal="pressed" from="MarginContainer/VBoxContainer/ActionButton" to="." method="_on_action_button_pressed"]