25 lines
614 B
GDScript3
25 lines
614 B
GDScript3
|
extends Building
|
||
|
|
||
|
@export var ingredients: Dictionary[Item, int] = {}
|
||
|
@export var process_time: float = 1.0
|
||
|
@export var created_item: Item
|
||
|
|
||
|
var process_timer: float = 0.0
|
||
|
var processing: bool = false
|
||
|
|
||
|
func _process(delta: float) -> void:
|
||
|
if is_functional():
|
||
|
if !processing:
|
||
|
processing = consume_ingredients()
|
||
|
if processing:
|
||
|
process_timer += delta
|
||
|
if process_timer >= process_time:
|
||
|
process_timer -= process_time
|
||
|
produce_item()
|
||
|
|
||
|
func consume_ingredients() -> bool:
|
||
|
return $Consumer.take_items_from_storage(ingredients)
|
||
|
|
||
|
func produce_item() -> void:
|
||
|
$Producer.set_output_item(created_item)
|