Basic recipe

This commit is contained in:
Rendo 2025-10-15 09:58:24 +05:00
commit 11d928c4f3
9 changed files with 59 additions and 1 deletions

View file

@ -1,4 +1,4 @@
extends Resource extends Comparable
## Base unit of manipulated objects ## Base unit of manipulated objects
@ -14,3 +14,10 @@ class_name Item
@export var stack_size : int @export var stack_size : int
@export var scene : PackedScene @export var scene : PackedScene
func is_equal(to: Comparable) -> bool:
if to is Item:
return to == self
elif to is ItemTag:
return self in to.items
return false

View file

@ -0,0 +1,7 @@
@abstract
extends Resource
class_name Comparable
@abstract
func is_equal(to: Comparable) -> bool

View file

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

View file

@ -0,0 +1,12 @@
extends Comparable
class_name ItemTag
@export var items : Array[Item]
func is_equal(to: Comparable) -> bool:
if to is Item:
return to in self.items
elif to is ItemTag:
return to == self
return false

View file

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

6
scripts/recipe/recipe.gd Normal file
View file

@ -0,0 +1,6 @@
extends Resource
class_name Recipe
@export var ingridients : Array[RecipePart]
@export var result : RecipePart

View file

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

View file

@ -0,0 +1,22 @@
extends Resource
class_name RecipePart
@export var item : Comparable
@export var amount : int
func is_stack_sufficient(stack: Stack) -> bool:
return item.is_equal(stack.held_item) and stack.amount >= amount
func consume_stack(stack: Stack) -> bool:
if is_stack_sufficient(stack) == false:
return false
stack.amount -= amount
return true
func create_stack() -> Stack:
if item is Item:
return Stack.new(item,amount)
elif item is ItemTag:
return Stack.new(item.items[randi_range(0,len(item.items))],amount)
return null

View file

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