diff --git a/scripts/item.gd b/scripts/item.gd index 8ce25ff..f7c5a06 100644 --- a/scripts/item.gd +++ b/scripts/item.gd @@ -1,4 +1,4 @@ -extends Resource +extends Comparable ## Base unit of manipulated objects @@ -14,3 +14,10 @@ class_name Item @export var stack_size : int @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 diff --git a/scripts/recipe/comparable.gd b/scripts/recipe/comparable.gd new file mode 100644 index 0000000..14c9cdf --- /dev/null +++ b/scripts/recipe/comparable.gd @@ -0,0 +1,7 @@ +@abstract +extends Resource + +class_name Comparable + +@abstract +func is_equal(to: Comparable) -> bool diff --git a/scripts/recipe/comparable.gd.uid b/scripts/recipe/comparable.gd.uid new file mode 100644 index 0000000..4fa1576 --- /dev/null +++ b/scripts/recipe/comparable.gd.uid @@ -0,0 +1 @@ +uid://bqcyt8qnxvonj diff --git a/scripts/recipe/item_tag.gd b/scripts/recipe/item_tag.gd new file mode 100644 index 0000000..2202497 --- /dev/null +++ b/scripts/recipe/item_tag.gd @@ -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 diff --git a/scripts/recipe/item_tag.gd.uid b/scripts/recipe/item_tag.gd.uid new file mode 100644 index 0000000..e7448d8 --- /dev/null +++ b/scripts/recipe/item_tag.gd.uid @@ -0,0 +1 @@ +uid://iasxpubh7f3i diff --git a/scripts/recipe/recipe.gd b/scripts/recipe/recipe.gd new file mode 100644 index 0000000..610c1fb --- /dev/null +++ b/scripts/recipe/recipe.gd @@ -0,0 +1,6 @@ +extends Resource + +class_name Recipe + +@export var ingridients : Array[RecipePart] +@export var result : RecipePart diff --git a/scripts/recipe/recipe.gd.uid b/scripts/recipe/recipe.gd.uid new file mode 100644 index 0000000..ea1d160 --- /dev/null +++ b/scripts/recipe/recipe.gd.uid @@ -0,0 +1 @@ +uid://dl0i68ut0lw70 diff --git a/scripts/recipe/recipe_part.gd b/scripts/recipe/recipe_part.gd new file mode 100644 index 0000000..94b17a2 --- /dev/null +++ b/scripts/recipe/recipe_part.gd @@ -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 diff --git a/scripts/recipe/recipe_part.gd.uid b/scripts/recipe/recipe_part.gd.uid new file mode 100644 index 0000000..fcc318d --- /dev/null +++ b/scripts/recipe/recipe_part.gd.uid @@ -0,0 +1 @@ +uid://w4v6jqv1ygqb