-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e20013a
commit c17d6b7
Showing
6 changed files
with
103 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://d3jmireffqxgp"] | ||
[gd_scene load_steps=2 format=3 uid="uid://d3jmireffqxgp"] | ||
|
||
[ext_resource type="PackedScene" uid="uid://cccy3p17tx25c" path="res://Scenes/ui_item_stack.tscn" id="1_kr5gx"] | ||
[ext_resource type="PackedScene" uid="uid://du08juske0mo1" path="res://Scenes/ui_ingredient_stack.tscn" id="2_kyq4o"] | ||
|
||
[node name="UiRecipe" type="VBoxContainer"] | ||
|
||
[node name="hallo" parent="." instance=ExtResource("1_kr5gx")] | ||
[node name="UiResult" parent="." instance=ExtResource("1_kr5gx")] | ||
custom_minimum_size = Vector2(100, 100) | ||
layout_mode = 2 | ||
size_flags_vertical = 1 | ||
|
||
[node name="HFlowContainer" type="HFlowContainer" parent="."] | ||
[node name="IngredientContainer" type="HFlowContainer" parent="."] | ||
layout_mode = 2 | ||
size_flags_vertical = 3 | ||
alignment = 1 | ||
|
||
[node name="hallo" parent="HFlowContainer" instance=ExtResource("2_kyq4o")] | ||
layout_mode = 2 | ||
|
||
[node name="hallo3" parent="HFlowContainer" instance=ExtResource("2_kyq4o")] | ||
layout_mode = 2 | ||
|
||
[node name="hallo2" parent="HFlowContainer" instance=ExtResource("2_kyq4o")] | ||
layout_mode = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
extends Control | ||
|
||
@onready var inventory: Inventory = $"../.." | ||
@onready var recipe_container: Control = %RecipeContainer | ||
|
||
var ui_recipe_res = preload("res://Scenes/ui_recipe.tscn") | ||
var ui_ingredient_res = preload("res://Scenes/ui_ingredient_stack.tscn") | ||
|
||
func _ready() -> void: | ||
inventory.inv_updated.connect(_inv_updated) | ||
|
||
func _inv_updated() -> void: | ||
for child in recipe_container.get_children(): | ||
child.queue_free() | ||
|
||
for recipe: Dictionary in Recipes.recipes: | ||
if _has_items(recipe): | ||
var ui_recipe: Control = ui_recipe_res.instantiate() | ||
var ui_result = ui_recipe.get_node("UiResult") | ||
inventory._update_ui_item(ui_result, recipe.result) | ||
ui_result.get_node("Button").pressed.connect(_recipe_pressed.bind(recipe)) | ||
|
||
var ingredient_container = ui_recipe.get_node("IngredientContainer") | ||
|
||
for ingredient: ItemStack in recipe.ingredients: | ||
var ui_ingredient: Control = ui_ingredient_res.instantiate() | ||
inventory._update_ui_item(ui_ingredient, ingredient) | ||
ingredient_container.add_child(ui_ingredient) | ||
|
||
add_child(ui_recipe) | ||
|
||
func _recipe_pressed(recipe: Dictionary) -> void: | ||
if inventory.cursor_item != null: | ||
return | ||
|
||
inventory.cursor_item = ItemStack.new(recipe.result.type, recipe.result.amount) | ||
inventory._update_ui_item(inventory.ui_cursor_item, inventory.cursor_item) | ||
for ingredient: ItemStack in recipe.ingredients: | ||
inventory.remove_items(ingredient.type, ingredient.amount) | ||
|
||
func _has_items(recipe: Dictionary) -> bool: | ||
for ingredient: ItemStack in recipe.ingredients: | ||
if inventory.count_items(ingredient.type, ingredient.amount) < ingredient.amount: | ||
return false | ||
|
||
return true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class_name Recipes | ||
extends RefCounted | ||
|
||
static var recipes: Array = [ | ||
{"result": ItemStack.new(ItemStack.ItemType.Pickaxe), "ingredients": [ | ||
ItemStack.new(ItemStack.ItemType.Wood, 5), | ||
ItemStack.new(ItemStack.ItemType.Rock, 3) | ||
]}, | ||
{"result": ItemStack.new(ItemStack.ItemType.Rock), "ingredients": [ | ||
ItemStack.new(ItemStack.ItemType.Wood, 1), | ||
]}, | ||
] |