TowerGameProto/scripts/Processor.gd

40 lines
1.0 KiB
GDScript3
Raw Normal View History

2025-04-16 22:56:14 +01:00
extends "res://scripts/Machine.gd"
@export var ingredient_items: Dictionary[Item, int]
@export var production_time: float = 1.0
var production_timer: float = 0.0
func _process(delta: float) -> void:
if ready_to_produce():
production_timer += delta
if production_timer >= production_time:
if !can_send_item(produced_item):
return
consume_ingredients()
if produce():
production_timer -= production_time
func ready_to_produce() -> bool:
if produced_item == null:
return false # that's not gonna work
var checklist: Dictionary[Item, int] = ingredient_items.duplicate()
for item in stored_items:
if checklist.has(item):
var count: int = checklist.get(item)
count -= 1
if count > 0:
checklist.set(item, count)
else:
checklist.erase(item)
if checklist.is_empty():
return true
return false
func consume_ingredients() -> void:
for item in ingredient_items:
fetch_item_from_storage(item, ingredient_items[item])
func _on_conveyor_2_item_available(node: ItemNode) -> void:
pass # Replace with function body.