scavenge recipes first stage

This commit is contained in:
Tabby 2026-01-11 18:49:11 +11:00
parent ccb15800a3
commit bc657be1ab
7 changed files with 59 additions and 17 deletions

View file

@ -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]

2
crafting/recipe.gd Normal file
View file

@ -0,0 +1,2 @@
extends Resource
class_name Recipe

1
crafting/recipe.gd.uid Normal file
View file

@ -0,0 +1 @@
uid://cp4ujmfinylse

View file

@ -1,4 +1,4 @@
extends Resource
extends Recipe
class_name ScavengeRecipe
@export var input : ItemData

View file

@ -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"

View file

@ -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.

View file

@ -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"]