This commit is contained in:
Rendo 2025-10-17 18:22:49 +05:00
commit 074bb21ffd
18 changed files with 99 additions and 51 deletions

View file

@ -15,9 +15,10 @@ func switch_recipe(recipe: Recipe) -> void:
for i in range(len(selected_recipe.ingridients)):
inventory.input_array[i].filter = selected_recipe.ingridients[i].item
func _process(_delta: float) -> void:
func _tick(_current_tick : int) -> void:
if inventory.output_slot.amount <= 0:
return
inventory.refresh()
var output : Structure = get_output_structure()
if output == null:
return

View file

@ -8,28 +8,28 @@ func _draw() -> void:
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position)
func _process(delta: float) -> void:
inventory.advance(delta)
func _tick(current_tick: int) -> void:
queue_redraw()
if current_tick % 8 != 0:
return
inventory.refresh()
inventory.advance()
var next : Structure = get_next()
try_transfer(next)
func calculate_position(index: int) -> Vector2:
var indexed_part = 16.0 / inventory.capacity
return -structure_parent.direction_vector()*8 + structure_parent.direction_vector() * indexed_part * (index + inventory.progress_array[index])
return -structure_parent.direction_vector()*8 + structure_parent.direction_vector() * indexed_part * index
func get_next() -> Structure:
return structure_parent.get_relative(structure_parent.direction_vector())
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:
if structure == null or inventory.internal_array[inventory.capacity-1].amount == 0:
return
var last_slot = inventory.internal_array[inventory.capacity-1]
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(last_slot.extract(),transfer_context))
if last_slot.amount == 0:
inventory.sort()

View file

@ -4,7 +4,7 @@ const inp1 := preload("res://generic/items/dbg_input1.tres")
const inp2 := preload("res://generic/items/dbg_input2.tres")
const out := preload("res://generic/items/dbg_output.tres")
func _process(_delta: float) -> void:
func _tick(_current_tick: int) -> void:
try_add(Vector2.UP,Stack.new(inp1,1))
try_add(Vector2.DOWN,Stack.new(inp2,1))
try_add(Vector2.RIGHT,Stack.new(out,1))

View file

@ -10,16 +10,20 @@ func get_down_next() -> Vector2:
var base = get_upper_next()
return base + base.rotated(PI/2).abs()
func _process(_delta: float) -> void:
func _tick(current_tick: int) -> void:
if current_tick % 8 != 0:
return
inventory.refresh()
if has_non_empty(inventory.upper_array) == false and has_non_empty(inventory.down_array) == false:
return
var transfer_upper = try_transfer(get_upper_next(),false)
var transfer_down = try_transfer(get_down_next(),true)
if transfer_upper or transfer_down or (not transfer_down and not transfer_upper):
split = not split
if transfer_upper or transfer_down or not (transfer_down or transfer_upper):
inverse_split()
func try_transfer(point:Vector2,down:bool) -> bool:
var next :Structure = structure_parent.get_relative(point)
var array : Array[InventorySlot] = inventory.down_array if split != down else inventory.upper_array
if next == null:
return false
@ -33,6 +37,9 @@ func try_transfer(point:Vector2,down:bool) -> bool:
return true
return false
func inverse_split() -> void:
split = not split
func has_non_empty(array:Array[InventorySlot]) -> bool:
for i in range(inventory.capacity):
if array[i].amount > 0: