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

View file

@ -26,10 +26,10 @@ func try_transfer(structure : Structure) -> void:
if structure == null or inventory.internal_array[inventory.capacity-1].amount == 0 or inventory.progress_array[inventory.capacity-1] < inventory.pop_treshold:
return
var last_slot = inventory.internal_array[inventory.capacity-1]
var ang_diff = structure_parent.direction_difference(structure)
if structure.inventory.can_add_from_side(ang_diff,last_slot.held_item) == false:
var transfer_context : InventoryContext = InventoryContext.new(structure_parent,structure,to_global(structure_parent.direction_vector()))
if structure.inventory.can_add(last_slot.held_item,transfer_context) == false:
return
last_slot.merge_stack(structure.inventory.add_from_side(last_slot.extract(),ang_diff))
last_slot.merge_stack(structure.inventory.add(last_slot.extract(),transfer_context))
if last_slot.amount == 0:
inventory.sort()