Basic recipe
This commit is contained in:
parent
4bae29f29f
commit
11d928c4f3
9 changed files with 59 additions and 1 deletions
|
@ -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
|
||||
|
|
7
scripts/recipe/comparable.gd
Normal file
7
scripts/recipe/comparable.gd
Normal file
|
@ -0,0 +1,7 @@
|
|||
@abstract
|
||||
extends Resource
|
||||
|
||||
class_name Comparable
|
||||
|
||||
@abstract
|
||||
func is_equal(to: Comparable) -> bool
|
1
scripts/recipe/comparable.gd.uid
Normal file
1
scripts/recipe/comparable.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://bqcyt8qnxvonj
|
12
scripts/recipe/item_tag.gd
Normal file
12
scripts/recipe/item_tag.gd
Normal 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
|
1
scripts/recipe/item_tag.gd.uid
Normal file
1
scripts/recipe/item_tag.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://iasxpubh7f3i
|
6
scripts/recipe/recipe.gd
Normal file
6
scripts/recipe/recipe.gd
Normal file
|
@ -0,0 +1,6 @@
|
|||
extends Resource
|
||||
|
||||
class_name Recipe
|
||||
|
||||
@export var ingridients : Array[RecipePart]
|
||||
@export var result : RecipePart
|
1
scripts/recipe/recipe.gd.uid
Normal file
1
scripts/recipe/recipe.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://dl0i68ut0lw70
|
22
scripts/recipe/recipe_part.gd
Normal file
22
scripts/recipe/recipe_part.gd
Normal 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
|
1
scripts/recipe/recipe_part.gd.uid
Normal file
1
scripts/recipe/recipe_part.gd.uid
Normal file
|
@ -0,0 +1 @@
|
|||
uid://w4v6jqv1ygqb
|
Loading…
Add table
Add a link
Reference in a new issue