recipie book autoloading working
This commit is contained in:
parent
e8c1f85a5b
commit
4f899c13f9
8 changed files with 134 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ class_name RecipeCard
|
|||
@export var grid_container : GridContainer
|
||||
var ingredient_slots : Array[ItemSlot]
|
||||
@export var output_slot : ItemSlot
|
||||
@export var output_label : Label
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
|
@ -26,3 +27,4 @@ func show_recipe(recipe : CraftRecipe):
|
|||
output_slot.item = recipe.output
|
||||
output_slot.update_ui()
|
||||
output_slot.block_taking = true
|
||||
output_label.text = recipe.output.item_name
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_8t2l7"]
|
||||
size = Vector2(32, 32)
|
||||
|
||||
[node name="Recipe Card" type="PanelContainer" node_paths=PackedStringArray("grid_container", "output_slot")]
|
||||
[node name="Recipe Card" type="PanelContainer" node_paths=PackedStringArray("grid_container", "output_slot", "output_label")]
|
||||
script = ExtResource("1_8t2l7")
|
||||
grid_container = NodePath("HBoxContainer/GridContainer")
|
||||
output_slot = NodePath("HBoxContainer/VBoxContainer/ItemSlot10")
|
||||
output_label = NodePath("HBoxContainer/VBoxContainer/Label")
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
layout_mode = 2
|
||||
|
|
|
|||
|
|
@ -4,14 +4,17 @@ extends PanelContainer
|
|||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
RecipeManager.recipes_loaded.connect(recipes_loaded)
|
||||
pass # Replace with function body.
|
||||
var test_card = load("res://crafting/recipe book/recipe_card.tscn").instantiate() as RecipeCard
|
||||
var recipe : CraftRecipe = load("res://crafting/crafts/computer_craft.tres")
|
||||
print(recipe)
|
||||
test_card.show_recipe(recipe)
|
||||
vbox.add_child(test_card)
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func recipes_loaded():
|
||||
for recipe in RecipeManager.craft_recipes:
|
||||
var new_card = load("res://crafting/recipe book/recipe_card.tscn").instantiate() as RecipeCard
|
||||
new_card.show_recipe(recipe)
|
||||
vbox.add_child(new_card)
|
||||
|
|
|
|||
49
crafting/recipeManager.gd
Normal file
49
crafting/recipeManager.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
extends Node
|
||||
|
||||
signal recipes_loaded
|
||||
var craft_recipes : Array[CraftRecipe]
|
||||
var crafts_dir : String = "res://crafting/crafts/"
|
||||
var scavenge_recipes : Array[ScavengeRecipe]
|
||||
var scavenges_dir : String = "res://crafting/scavenges/"
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
load_recipes()
|
||||
|
||||
pass # Replace with function body.
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
pass
|
||||
|
||||
func load_recipes():
|
||||
## CRAFTS
|
||||
var dir = DirAccess.open(crafts_dir)
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
|
||||
# do something with the file
|
||||
if (file_name.get_extension() == "remap"):
|
||||
file_name = file_name.replace('.remap', '')
|
||||
print(crafts_dir + file_name)
|
||||
craft_recipes.append(load(crafts_dir + file_name) as CraftRecipe)
|
||||
file_name = dir.get_next()
|
||||
|
||||
## SCAVENGES
|
||||
dir = DirAccess.open(scavenges_dir)
|
||||
if dir:
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
while file_name != "":
|
||||
|
||||
# do something with the file
|
||||
if (file_name.get_extension() == "remap"):
|
||||
file_name = file_name.replace('.remap', '')
|
||||
print(crafts_dir + file_name)
|
||||
craft_recipes.append(load(scavenges_dir + file_name) as ScavengeRecipe)
|
||||
file_name = dir.get_next()
|
||||
|
||||
recipes_loaded.emit()
|
||||
1
crafting/recipeManager.gd.uid
Normal file
1
crafting/recipeManager.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://b76dwpvf6ot3o
|
||||
Loading…
Add table
Add a link
Reference in a new issue