2025-04-21 20:49:29 +01:00
|
|
|
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
|
2025-04-23 11:56:29 +01:00
|
|
|
@onready var consumer: Consumer = $Consumer
|
|
|
|
@onready var producer: Producer = $Producer
|
2025-04-21 20:49:29 +01:00
|
|
|
|
|
|
|
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()
|
2025-04-23 11:56:29 +01:00
|
|
|
processing = false
|
2025-04-21 20:49:29 +01:00
|
|
|
|
|
|
|
func consume_ingredients() -> bool:
|
2025-04-23 11:56:29 +01:00
|
|
|
return consumer.take_items_from_storage(ingredients)
|
2025-04-21 20:49:29 +01:00
|
|
|
|
|
|
|
func produce_item() -> void:
|
2025-04-23 11:56:29 +01:00
|
|
|
producer.send_item(created_item)
|