Inventory context

This commit is contained in:
Rendo 2025-10-16 22:05:24 +05:00
commit fed57e38df
17 changed files with 128 additions and 108 deletions

View file

@ -24,14 +24,17 @@ func _process(_delta: float) -> void:
var output : Structure = get_output_structure()
if output == null:
return
var ang_diff = output.direction_difference(structure_parent)
if output.inventory.can_add_from_side(ang_diff):
inventory.output_slot.merge_stack(output.inventory.add_from_side(inventory.output_slot.extract(),ang_diff))
var transfer_context : InventoryContext = InventoryContext.new(structure_parent,output,get_output_position())
if output.inventory.can_add(inventory.output_slot.held_item,transfer_context):
inventory.output_slot.merge_stack(output.inventory.add(inventory.output_slot.extract(),transfer_context))
func get_output_structure() -> Structure:
var rotated = Vector2(1.5,-0.5).rotated(structure_parent.direction)
return structure_parent.get_relative(rotated+Vector2(0.5,0.5))
func get_output_position() -> Vector2:
return to_global(Vector2(1.5,-0.5).rotated(structure_parent.direction)+Vector2(0.5,0.5))
func check_for_recipe(_stack : Stack, _position : int) -> void:
if inventory.output_slot.held_item != null and inventory.output_slot.amount == inventory.output_slot.held_item.stack_size:
return