Broken pos

This commit is contained in:
Rendo 2025-10-15 11:55:18 +05:00
commit 3af13d0a8b
24 changed files with 304 additions and 146 deletions

View file

@ -0,0 +1,19 @@
extends StructureBehaviour
@export var selected_recipe : Recipe
@onready var inventory : InOutInventory = get_parent().inventory
func _ready() -> void:
await get_tree().process_frame
switch_recipe(selected_recipe)
await get_tree().process_frame
for i in len(selected_recipe.ingridients):
inventory.input_array[i].filter = selected_recipe.ingridients[i].item
print(inventory.input_array[i].filter)
func switch_recipe(recipe: Recipe) -> void:
selected_recipe = recipe
inventory.input_capacity = len(selected_recipe.ingridients)
inventory.resize()
for i in len(selected_recipe.ingridients):
inventory.input_array[i].filter = selected_recipe.ingridients[i].item

View file

@ -0,0 +1 @@
uid://c7mx3uatj6ulm

View file

@ -1,7 +1,6 @@
extends Node2D
extends StructureBehaviour
@onready var parent_structure : Structure = get_parent()
@onready var inventory : BeltInventory = parent_structure.inventory
@onready var inventory : BeltInventory = structure_parent.inventory
@onready var animator : AnimationPlayer = $"../AnimationPlayer"
func _ready() -> void:
@ -14,23 +13,22 @@ func _draw() -> void:
for i in range(inventory.capacity):
if inventory.internal_array[i].amount > 0:
var calculated_position = calculate_position(i) - inventory.internal_array[i].held_item.preview.get_size()/2.0
for j in range(inventory.internal_array[i].amount/10):
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position + Vector2(0,-j))
draw_texture(inventory.internal_array[i].held_item.preview,calculated_position)
func _process(delta: float) -> void:
inventory.advance(delta)
queue_redraw()
var next : Structure = get_next()
if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,parent_structure.facing)) == false:
if next == null or next.inventory == null or next.inventory.can_add_from_side(Globals.facing_difference(next.facing,structure_parent.facing),inventory.internal_array[inventory.capacity-1].held_item) == false:
return
var popped = inventory.pop()
if popped == null:
return
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,parent_structure.facing))
next.inventory.add_from_side(popped,Globals.facing_difference(next.facing,structure_parent.facing))
func calculate_position(index: int) -> Vector2:
var indexed_part = 16.0 / inventory.capacity
match parent_structure.facing:
match structure_parent.facing:
Structure.Facing.RIGHT:
return Vector2.LEFT*8 + Vector2.RIGHT * indexed_part * (index + inventory.progress_array[index])
Structure.Facing.DOWN:
@ -42,16 +40,8 @@ func calculate_position(index: int) -> Vector2:
return Vector2.ZERO
func get_next() -> Structure:
match parent_structure.facing:
Structure.Facing.RIGHT:
return parent_structure.get_relative(Vector2(1,0))
Structure.Facing.DOWN:
return parent_structure.get_relative(Vector2(0,1))
Structure.Facing.LEFT:
return parent_structure.get_relative(Vector2(-1,0))
Structure.Facing.UP:
return parent_structure.get_relative(Vector2(0,-1))
return null
var faced_vector = Structure.facing_to_vector(structure_parent.facing)
return structure_parent.get_relative(faced_vector)
func _on_conveyor_switched_facing(to: Structure.Facing) -> void:
match to:

View file

@ -1,9 +1,15 @@
extends Node
extends StructureBehaviour
const test_item :=preload("res://generic/items/dbg_item.tres")
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:
for point in [Vector2(-1,0),Vector2(1,0),Vector2(0,1),Vector2(0,-1)]:
var found_structure :Structure = get_parent().get_relative(point)
if found_structure and found_structure.inventory:
found_structure.inventory.add_from_side(Stack.new(test_item,randi_range(1,test_item.stack_size)),Structure.facing_to_vector(found_structure.facing).angle_to(point))
try_add(Vector2.UP,Stack.new(inp1,1))
try_add(Vector2.DOWN,Stack.new(inp2,1))
try_add(Vector2.RIGHT,Stack.new(out,1))
func try_add(dir: Vector2,stack : Stack):
var found = structure_parent.get_relative(dir)
if found != null:
found.inventory.add(stack)