From 09625d8285dd7c63e582185237a5e91f851d973c Mon Sep 17 00:00:00 2001 From: Tabby <41929769+tabby-cat-nya@users.noreply.github.com> Date: Tue, 13 Jan 2026 13:05:20 +1100 Subject: [PATCH] fixed recipe checking, hoping it doesnt cost too much performace --- inv_system/crafting_panel.gd | 39 ++++++++++++++++++++++++---------- inv_system/crafting_panel.tscn | 9 +------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/inv_system/crafting_panel.gd b/inv_system/crafting_panel.gd index 531cc96..2076da4 100644 --- a/inv_system/crafting_panel.gd +++ b/inv_system/crafting_panel.gd @@ -54,20 +54,37 @@ func check_recipes(): elif filled_slots() > 1: # check crafting recipes - var possible_recipes : Array[CraftRecipe] = RecipeManager.craft_recipes.duplicate() - for x in range(9): - for recipe in possible_recipes: + #var possible_recipes : Array[CraftRecipe] = RecipeManager.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) + ##print("Possible recipes: " + str(possible_recipes.size())) + #if possible_recipes.size() == 1: + ##print("found our recipe!") + #matched_recipe = possible_recipes[0] + #style_assemble() + #return + for recipe in RecipeManager.craft_recipes: + var matches : int = 0 + for x in range(9): if recipe.ingredients[x] and slots[x].item: if recipe.ingredients[x].item_name != slots[x].item.item_name: - possible_recipes.erase(recipe) + matches = 0 + else: + matches += 1 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!") - matched_recipe = possible_recipes[0] - style_assemble() - return + matches = 0 + else: + matches += 1 + + if matches == 9: + matched_recipe = recipe + style_assemble() + return func style_assemble(): action_button.add_theme_stylebox_override("normal",assemble_style) diff --git a/inv_system/crafting_panel.tscn b/inv_system/crafting_panel.tscn index 6c94a31..72af48e 100644 --- a/inv_system/crafting_panel.tscn +++ b/inv_system/crafting_panel.tscn @@ -1,12 +1,7 @@ -[gd_scene load_steps=12 format=3 uid="uid://f06ym5ujhdsc"] +[gd_scene load_steps=7 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/large_psu_scav.tres" id="5_8c40c"] -[ext_resource type="Resource" uid="uid://dpnp3xlwhla4h" path="res://crafting/scavenges/small_psu_scav.tres" id="6_8c40c"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_h0v0h"] content_margin_left = 0.0 @@ -87,8 +82,6 @@ offset_right = 962.0 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"), ExtResource("6_8c40c")]) assemble_style = SubResource("StyleBoxFlat_h0v0h") assemble_style_hover = SubResource("StyleBoxFlat_441s3") assemble_style_pressed = SubResource("StyleBoxFlat_h0v0h")